This script will read in data frame of sample structure IDs and MNI coordinates, and see if there is any overlap between coordinates. The point of this is because if we write a brain image (.nii file), we can only have one value per voxel
df = read.csv("data/AllenBrainAtlasSampleMNI.csv", head = TRUE, sep = ",")
Let's visualize where the probes are
library(scatterplot3d)
scatterplot3d(df$mni_x, df$mni_y, df$mni_z, main = "Allen Brain Atlas 3702 Samples",
color = as.numeric(df$id), xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
We can't see everyone… let's break apart
par(mfrow = c(2, 3))
scatterplot3d(df$mni_x[df$id == "H0351.2001"], df$mni_y[df$id == "H0351.2001"],
df$mni_z[df$id == "H0351.2001"], main = "Allen Brain Atlas 3702 Samples ID-2001",
color = 1, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
scatterplot3d(df$mni_x[df$id == "H0351.2002"], df$mni_y[df$id == "H0351.2002"],
df$mni_z[df$id == "H0351.2002"], main = "Allen Brain Atlas 3702 Samples ID-2002",
color = 2, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
scatterplot3d(df$mni_x[df$id == "H0351.1009"], df$mni_y[df$id == "H0351.1009"],
df$mni_z[df$id == "H0351.1009"], main = "Allen Brain Atlas 3702 Samples ID-1009",
color = 3, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
scatterplot3d(df$mni_x[df$id == "H0351.1012"], df$mni_y[df$id == "H0351.1012"],
df$mni_z[df$id == "H0351.1012"], main = "Allen Brain Atlas 3702 Samples ID-1012",
color = 4, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
scatterplot3d(df$mni_x[df$id == "H0351.1015"], df$mni_y[df$id == "H0351.1015"],
df$mni_z[df$id == "H0351.1015"], main = "Allen Brain Atlas 3702 Samples ID-1015",
color = 5, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
scatterplot3d(df$mni_x[df$id == "H0351.1016"], df$mni_y[df$id == "H0351.1016"],
df$mni_z[df$id == "H0351.1016"], main = "Allen Brain Atlas 3702 Samples ID-1016",
color = 6, xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
Looking at the plots, we can visually verify that the older datasets (2001 and 2002) have something strange going on with theirmapping to MNI standard space, but the remaining datasets are ok. You can check by doing the following for different sets: df$mni_x[df$id == “H0351.1012”] == df$mni_x[df$id == “H0351.1016”]
Let's create a subset of the data that separates 2001 and 2002, the older datasets. We will want to compare each to a standard MNI brain
df.old = df[df$id %in% c("H0351.2001", "H0351.2002"), ]
df.new = df[!df$id %in% c("H0351.2001", "H0351.2002"), ]
We should now only see one color when we plot all datasets
par(mfrow = c(1, 1))
scatterplot3d(df.new$mni_x, df.new$mni_y, df.new$mni_z, main = "Allen Brain Atlas 3702 Samples",
color = as.numeric(df.new$id), xlab = "X", ylab = "Y", zlab = "Z", pch = 20)
Yep! Now let's read in the actual MNI brain and take a look…