3D visualization of stat files for mice - CoBrALab/documentation GitHub Wiki

This tutorial is based on this paper (Madan C. R., 2015): https://pubmed.ncbi.nlm.nih.gov/26594340/

Here you will learn how to create a 3D plot showing your statistics results, like the example below:

tgeffect

Step 1

You will need your statistics file(s) and a brain mask (if you don't have a brain mask see this). Your mask is key because is the one that will provide the mouse brain shape. You can use this tutorial for human 3D plots too. In that case, you will need a human brain mask that will provide the human brain shape.

Your files should be in niftii format. If they are in minc format you can do the following for conversion.

First, in a terminal load the minc toolkit:

module load minc-toolkit-v2

Then use mnc2nii for conversion:

mnc2nii <mincfilename.mnc> <niftiifilename.nii>

Example:

mnc2nii Ctrl_LFD_Tgpoly1.mnc Ctrl_LFD_Tgpoly1.nii

The line above will convert the minc file "Ctrl_LFD_Tgpoly1" to a niftii file with the same name.

Your statistic maps should be thresholded to significant values. In this example, the statistic file comes from a linear mixed effects model run in R, after false discovery rate correction, it turns out that the regression term of interest was significant at 1%. The t-value thresholding the statistic file at 1% is 3.29. This means that when the statistic file is threshold at 3.29, we get to see the significant areas with t-values above 3.29. However we also got negative values that are significant at 1%, and we get to see them when we threshold the statistic file below -3.29.

This is how the statistic map looks when is thresholded from 1% to Maximum value, and plotted on top of the population average:

Ctrl_LFD_Tgpoly1_1percent

Because we like to plot in red the positive values of the slope, and in blue the negative values of the slope, from this statistic file we will create two files, one with only the positive values above 3.29, and the other one with negative values below -3.29.

To do it, you can use minccalc (see this).

First, in a terminal load the minc toolkit:

module load minc-toolkit-v2

Then use minccalc to threshold the statistic files (minc files only, then you can convert them to niftii as explained above):

minccalc -expression '(A[0] > 3.29)?A[0]:0' Ctrl_LFD_Tgpoly1.mnc Ctrl_LFD_Tgpoly1pos1percent.mnc

The line above is asking to output a minc file with the name "Ctrl_LFD_Tgpoly1pos1percent.mnc" only if the values of the input file (Ctrl_LFD_Tgpoly1.mnc) are above 3.29, otherwise set the value of the voxel to zero.

To create a minc file with values below -3.29, see the example below:

minccalc -expression '(A[0] < -3.29)?A[0]:0' Ctrl_LFD_Tgpoly1.mnc Ctrl_LFD_Tgpoly1neg1percent.mnc

To do it in matlab first open a terminal and load MATLAB and SPM modules:

module load MATLAB

module load SPM12

And then open Matlab by typing "matlab" in the terminal. In there, set the working directory where your files are, and use the following lines as example:

spm %to open SPM

spm_imcalc_ui('Ctrl_LFD_Tgpoly1.nii', 'Ctrl_LFD_Tgpoly1pos1percent.nii', 'i1>=3.29'); %create a niftii file with values equal and above 3.29

spm_imcalc_ui('Ctrl_LFD_Tgpoly1.nii', 'Ctrl_LFD_Tgpoly1neg1percent.nii', 'i1<=-3.29'); %create a niftii file with values equal and below -3.29

In the lines above the input stat file (Ctrl_LFD_Tgpoly1.nii) is thresholded and saved with a new name.

So now we have:

  1. a niftii file thresholded to 1% with positive values

  2. a niftii file thresholded to 1% with negative values

  3. a niftii file of the brain mask (a.k.a. statistic mask)

You can threshold your statistics as you need, or if you don't care about visualizing positive and negative slopes with different colors, you can use only one statistic file.

Step 2

You will need to create a mesh file for each niftii file you have. Here we will show you how to do it for the statistic mask and you can repeat it for each niftii file you want to visualize in your 3D model. To do so, you will use ITK-SNAP software.

  1. load the ITK-SNAP software in a terminal

module load itksnap

  1. open the software by typing itksnap

itksnap

3)Load the stat mask by going to File -> Open Main Image -> browse for your mask -> Next -> Finish

1

2

3

4

  1. load exactly the same file but as a segmentation. Do it by going to Segmentation -> Open Segmentation -> browse for the same file -> Next -> Finish

5

Now it will look something like this:

6

  1. To save the mesh go: Segmentation -> Export as Surface Mesh -> Export meshes for all labels as a single scene -> Next -> type the name (make sure it includes extention .vtk) -> Finish

7

8

9

The steps above will create a file with the extension .vtk, this is the mesh file. You should create one mesh file per Niftii file of interest.

Step 3

Visualize your mesh files.

  1. load the ParaView software in a terminal

module load paraview

  1. open the software by typing paraview

paraview

  1. load your mesh files by going to File -> Open -> Browse for your mesh file and open one by one

10

  1. when all your mesh files are loaded you can see the following video to learn how to change color, export them as images or animations.

youtube video: https://youtu.be/LsGntCnPwxw