Skip to content

Visualizing MAGeT Brain results on Mouse Average

tulste edited this page Aug 20, 2019 · 13 revisions

There are two ways to get MAGeT-Brain results for mouse data

  1. Runnning hierarchical MAGeT using an hanatLM

  2. Running a non-hierarchical MAGeT using an anatLM

Below are two examples for visualizing MAGeT results from hanatLM and anatLM using the DSURQE atlas

1. Running hierarchical MAGeT

Setting up the data:

data <- read.csv("/data/chamal/projects/stephanie/cross-sect-asyn-PFF-project/analysis/maget-subjects-analyses.csv")
data$label_file=paste("/data/chamal/projects/stephanie/cross-sect-asyn-PFF-project/derivatives/MICe_build_model_take2/ASY20190409_processed/", data$file, "/", data$file,"_I_lsq6_voted.mnc", sep="")

data$vols = anatGetAll(data$label_file,
                            defs = "/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/mappings/DSURQE_40micron_R_mapping.csv", 
                            method = "labels")

Running the hanatLM model:

abijson <- "/opt/quarantine/resources/Allen_Brain/Allen_hierarchy_definitions.json"
defs <- "/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/mappings/DSURQE_40micron_R_mapping.csv"
hdefs <- makeMICeDefsHierachical(defs, abijson)
vols <- addVolumesToHierarchy(hdefs, data$vols)

model <- hanatLm(~group*sex, data, vols)
FDR <- hanatFDR(model)
thresholds(FDR)

Visualizing the data:

anatVol <- mincArray(mincGetVolume("/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/ex-vivo/DSURQE_40micron.mnc"))
labelVol <- mincArray(mincGetVolume("/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/ex-vivo/DSURQE_40micron_labels.mnc"))
stats <- hanatToVolume(model, labelVol, "tvalue.groupPFF")

tFDR20 = 7.024384
sliceSeries(nrow = 6, ncol=6, begin=100, end=350) %>% 
  anatomy(anatVol, low=700, high=1400) %>% 
  overlay(stats, low=tFDR20, high=8, symmetric = T) %>%
  legend("t-statistics") %>%
  draw()

For other ways to visualize the data, please see: https://htmlpreview.github.io/?https://github.com/Mouse-Imaging-Centre/MRIcrotome/blob/master/vignettes/figures.html

2. Running a non-hierarchical MAGeT

Setting up the data:

data <- read.csv("/data/chamal/projects/stephanie/cross-sect-asyn-PFF-project/analysis/maget-subjects-analyses.csv")
data$label_file=paste("/data/chamal/projects/stephanie/cross-sect-asyn-PFF-project/derivatives/MICe_build_model_take2/ASY20190409_processed/", data$file, "/", data$file,"_I_lsq6_voted.mnc", sep="")

data$vols = anatGetAll(data$label_file,
                            defs = "/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/mappings/DSURQE_40micron_R_mapping.csv", 
                            method = "labels")

Running the anatLM model:

LMmodel<-anatLm(~ group * sex, data = data, anat = data$vols)`
FDR <- anatFDR(LMmodel)

Visualizing the data:

In order to visualize the results, need to create a 3D volume incorporating the tscores from the anatLM:

Normally the command to do so is, anatCreateVolume, however there are several bugs in the code that prevent this and so while it is being fixed, create and use the function anatCreateVolume2 in the meantime (see code).

#create new function that assigns a tscore  of a region from the anatLM to its corresponding label
anatCreateVolume2 <- function (anat, column = 1) 
{
  labels <- read.csv(attr(anat, "definitions"))
  volume <- mincGetVolume(attr(anat, "atlas"))
  newvolume <- volume
  for (i in 1:nrow(labels)) {
    if (labels$right.label[i] == labels$left.label[i] ) {
      newvolume[volume < labels$right.label[i] + 0.5 & volume > 
                  labels$right.label[i] - 0.5] <- anat[labels$Structure[i], 
                                                       column]
    } else {
    newvolume[volume < labels$right.label[i] + 0.5 & volume > 
                labels$right.label[i] - 0.5] <- anat[paste0("right ",labels$Structure[i]), 
                                                     column]
    newvolume[volume < labels$left.label[i] + 0.5 & volume > 
                labels$left.label[i] - 0.5] <- anat[paste0("left ",labels$Structure[i]), 
                                                    column]
    }
  }
  return(invisible(mincArray(newvolume)))
}

Then you need to modify the attributes of the anatLM model (LMmodel) using the following commands in which incorporate the region names and their corresponding label number.

attr(LMmodel,"definitions") <- "/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/mappings/DSURQE_40micron_R_mapping.csv"
attr(LMmodel,"atlas") <- "/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/ex-vivo/DSURQE_40micron_labels.mnc"

Finally, create the 3D stats volume using this command:

stats2 <- anatCreateVolume2(LMmodel, '/data/chamal/projects/stephanie/cross-sect-asyn-PFF-project/analysis/DSURQE_labels_tscores_interaction.mnc', column='tvalue-groupPFF:sexM') 

The next step is to visualize the tscores onto an average mouse brain (here we use the DSURQE ex-vivo MRI)

anatVol <- mincArray(mincGetVolume("/opt/quarantine/resources/Dorr_2008_Steadman_2013_Ullmann_2013_Richards_2011_Qiu_2016_Egan_2015_40micron/ex-vivo/DSURQE_40micron.mnc"))

tFDR20 = 2.2
tmax = 6
sliceSeries(nrow = 5, ncol=5, begin=50, end=350) %>% 
  anatomy(anatVol, low=700, high=1400) %>% 
  overlay(stats2, low=tFDR20, high=tmax, symmetric = T) %>%
  legend("t-statistics") %>%
  draw()`

For other ways to visualize the data, please see: https://htmlpreview.github.io/?https://github.com/Mouse-Imaging-Centre/MRIcrotome/blob/master/vignettes/figures.html

Clone this wiki locally