Sep 23, 2022

Public workspaceDTI preprocessing, statistical and cluster analysis

  • 1Barrow Neuroimaging Innovation Center, Barrow Neurological Institute, Phoenix, AZ;
  • 2School of Biological Health Systems and Engineering, Arizona State University
Icon indicating open access to content
QR code linking to this content
Protocol CitationMaurizio Bergamino, Jennapher Lingo Vangilder 2022. DTI preprocessing, statistical and cluster analysis. protocols.io https://dx.doi.org/10.17504/protocols.io.6qpvrdjozgmk/v1
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: Working
We use this protocol and it's working
Created: September 28, 2021
Last Modified: September 23, 2022
Protocol Integer ID: 53634
Keywords: diffusion tensor imaging,
Abstract
This protocol outlines preprocessing, statistical and cluster analyses that were applied in 'Using whole-brain diffusion tensor analysis to evaluate white matter structural correlates of delayed visuospatial memory and one-week motor skill retention in nondemented older adults: A preliminary study' (https://doi.org/10.1371/journal.pone.0274955).


The following software packages are required to follow this protocol: FSL, MRtrix, Advanced Normalization Tools (Github: https://github.com/ANTsX/ANTs). Figures were created via AFNI.
Guidelines
Double-check your images after each step!
Preprocessing data
Preprocessing data
Double-check if your native and original images are in FLOAT32 and oriented with the MNI.
-Convert to float-
fslmaths dwidata.nii.gz dwi.nii.gz -odt float
DWI Denoising:
dwidenoise -datatype float32 -noise level_noise.nii.gz [IN] [OUT_denoised]
dwidenoise -datatype float32 -noise level_noise.nii.gz dwi.nii.gz dwi_denoised.nii.gz
mrdegibbs [OUT_denoised] [OUT_Gibbs]
mrdegibbs dwi_denoised.nii.gz dwi_Gibbs.nii.gz
need brain – bet doesn’t work as well as dwi2mask
dwi2mask -fslgrad bvecs.txt bvals.txt dwi_Gibbs.nii.gz temp_brain_mask.nii.gz
Run ‘nodif_brain_mask.sh’ script [e.g.,bash nodif_brain_mask.sh dwi_Gibbs.nii.gz 4214_52 temp_brain_mask.nii.gz] to get temporary nodif brain masks for eddy.
Rename both of these nodif files with the prefix ‘dwi_Gibbs_’ e.g., ‘dwi_Gibbs_brain_mask’ for eddy. Delete the ‘temp_brain’ file.
Run eddy correction and get rotated vector file
eddy --imain=dwi_Gibbs.nii.gz --mask=dwi_Gibbs_brain_mask.nii.gz --index=index.txt --acqp=acqparams.txt --bvecs=bvecs.txt --bvals=bvals.txt --fwhm=0 --flm=quadratic --slm=linear --out=eddy_unwarped_images --data_is_shelled
Nodif and Brain extraction on the data.nii.gz
fslroi data.nii.gznodif_data0 1
dwi2mask -fslgrad eddy_unwarped_images.eddy_rotated_bvecs.txt bvals.txt data.nii.gz temp_brain_mask.nii.gz
Run ‘nodif_brain_mask.sh’ script [e.g.,bash nodif_brain_mask.sh data.nii.gz 4214_52 temp_brain_mask.nii.gz] output is ‘nodif_brain_mask.nii.gz’ and ‘nodif_brain.nii.gz’ rename and add ‘data’ in front, so ‘data_nodif_brain’. Delete ‘temp_brain’ file.
Bias Field correction (via ANTs):
dwibiascorrect ants data.nii.gz data_bias.nii.gz -fslgrad eddy_unwarped_images.eddy_rotated_bvecs.txt bvals.txt -mask data_nodif_brain_mask.nii.gz -bias bias_image.nii.gz -ants.b [100,3]
Upsample DWI images for better coregistration with MNI template
mrgrid -vox 1.25 data_bias.nii.gz regrid data_bias_HR.nii.gz

Fit tensor model
dtifit -k data_bias_HR.nii.gz -o DTI_map_w-linear_ -m nodif_brain_mask.nii.gz -r eddy_unwarped_images.eddy_rotated_bvecs.txt -b bvals.txt -w
Optional: create bash script to generate group template
Copy all the nodif_brain.nii.gz images into one folder and change directory to it. Then run:
bash buildtemplateparallel.sh -d 3 -o template -c 0 -r 1 -n 0 -i 3 *.nii.gz

WarpImageMultiTransform 3 [in: FA map in native space] [out: FA map in template space] -R templatetemplate.nii.gz [warp file] [affine file] 
At this point all participant FA maps should be in template space. Create a 4D (x,y,z + time) file with all your maps: Insert all your FA in template space in one folder and run: fslmerge -t [output] *.nii.gz
Create then apply mask from all subjects
fslmaths all_FA.nii.gz -max 0 -Tmin -bin mean_mask -odt char
fslmaths all_FA.nii.gz -mas mean_mask all_FA.nii.gz


Create a mean of the FA over-time and create white matter mask (thresholded at FA>0.20):
fslmaths all_FA -Tmean mean_FA
fslmaths mean_FA -thr 0.20 -bin WM_mask
Apply your mask to your smoothed maps:
fslmaths all_FA_smooth -mas mean_mask all_FA_smooth
At this point you should have a FA map 'all_FA.nii.gz' for all subjects.
Linear regression
Linear regression
Create linear regression script (that applies model voxel-by-voxel) using the LM.m function in MATLAB by using:
LM (file_ID1, raw_image_subject, mask)

e.g., LM (covariates.txt, all_FA_smooth.nii, WM_mask.nii)
Resulting files will be the FDR-corrected p-value and tstat maps for each variable.
Clusterize and apply white matter atlas to identify clusters
Clusterize and apply white matter atlas to identify clusters
Example is for first behavioral variable 'score_1'
3dcalc -ascore_1_FDR.nii-expr 'a*1' -prefixscore_1_FDR_corrected.nii.gz
3dcalc -a score_1_tStat.nii -expr 'a*1' -prefix score_1_tStat_corrected.nii.gz
Split scores tStat into positive and negative (this provides you with positive and negative correlations):

Fslmathsscore_1_tStat_corrected.nii.gz -thr 0 positive_score1.nii.gz
Fslmathsscore_1_tStat_corrected.nii.gz -uthr 0 negative_score1.nii.gz
*For negative images, need to multiply by -1
Fslmaths negative_score1.nii.gz -mul -1 negative_score1.nii.gz
Get FDR-corrected p-value clusters that are less than 0.01 and that are at least 100 voxels in size
3dClusterize -nosum -1Dformat -inset score_1_FDR_corrected.nii.gz -idat 0 -ithr 0 -NN 2 -clust_nvox 100 -1sided RIGHT_TAIL 0.99 -pref_map Clust_mask_motor.nii.gz

fslmaths Clust_mask_motor.nii.gz -bin Clust_mask_motor.nii.gz
Coregister the template to MNI:

antsRegistrationSyN.sh -d 3 -m /Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/group_template/templatetemplate.nii.gz -f /usr/local/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz -o /Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI -t s
Check that ROIs are Binarized (use nearest neighbor command when the images are binarized). Behavioral variables are 'score_1' and 'motor'

Transform clusters to MNI:

antsApplyTransforms -d 3 -i Clust_mask_motor.nii.gz -o Clust_mask_motor_MNI.nii.gz -r/usr/local/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI1Warp.nii.gz,0]  -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI0GenericAffine.mat,0] -n NearestNeighbor

Transform scores tstat (positive and negative) to MNI space:

antsApplyTransforms -d 3 -ipositive_score1.nii.gz-opositive_score1_MNI.nii.gz -r/usr/local/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI1Warp.nii.gz,0]  -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI0GenericAffine.mat,0]

antsApplyTransforms -d 3 -inegative_score1.nii.gz-onegative_score1_MNI.nii.gz -r/usr/local/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI1Warp.nii.gz,0]  -t [/Users/syschaef/Desktop/4214_DTI/MRtrix_preproc/template_to_MNI/templatetemplate_to_MNI0GenericAffine.mat,0]
Mask the tstat scores with significant cluster files:

Positive:
fslmathspositive_score1_MNI.nii.gz -mas Clust_mask_motor_MNI.nii.gzpositive_score1masked_MNI.nii.gz fslmathspositive_score1masked_MNI.nii.gz -bin Clust_mask_motor_positive_MNI.nii.gz

Negative:
fslmathsnegative_score1_MNI.nii.gz -mas Clust_mask_motor_MNI.nii.gznegative_score1masked_MNI.nii.gz fslmathsnegative_score1masked_MNI.nii.gz -bin Clust_mask_motor_negative_MNI.nii.gz
Custom code extracted significant cluster locations from the JHU white matter atlas, but use the atlas of your choice and identify clusters by using 'fslmaths' (see fslwiki for tutorial)