Return to Diffusion

Be sure to source FreeSurfer before trying to run any of the following scripts.

subjects.csh

Use this script to set the 'SUBJECTS_DIR' and 'TUTORIAL_DIR' parameters, as well as assigning various subject data sub-sets (normal subjects, lesioned subjects, both groups). The 'TUTORIAL_DATA' represents the file path of where the tutorial data is being stored.

 #!/bin/tcsh -ef
 #

setenv  SUBJECTS_DIR $TUTORIAL_DATA/diffusion_recons
setenv TUTORIAL_DIR  $TUTORIAL_DATA/diffusion_tutorial


set SUBJECTS = (Diff001 Diff002 Diff003 Diff004 Diff005 Diff006 Diff007 Diff008 Diff009 Diff010)
set LESION_SUBJECTS = (LDiff006 LDiff007 LDiff008 LDiff009 LDiff010)
set SUBJECTS_AND_LESION_SUBJECTS = (Diff001 Diff002 Diff003 Diff004 Diff005 LDiff006 LDiff007 LDiff008 LDiff009 LDiff010)

DiffPreproc.csh

 #!/bin/tcsh –ef
 #

source subjects.csh

# Run dt_recon on all subjects
foreach subj ($SUBJECTS)
  echo $subj
  set outdir = $TUTORIAL_DIR/$subj/dtrecon
  mkdir -p $outdir
  set dicomfile = $TUTORIAL_DIR/$subj/orig/*-1.dcm
  set cmd = (dt_recon --i $dicomfile --s $subj --o $outdir)
  echo $cmd
  eval $cmd
end

Output: dwi.nii, dwi.mghdti.bvecs, dwi.mghdti.bvals, dwi-ec.nii, lowb.nii, bvecs.dat, bvals.dat, eigvec[123].nii, eigvals.nii, tensor.nii, dwirvar.nii, ivc.nii, adc.nii, radialdiff.nii, vr.nii, ra.nii, fa.nii, fa-tal.nii, register.dat.

Return to Diffusion

AlignAnat2Diff.csh

 #!/bin/tcsh -ef
 #

source subjects.csh

# Loop through each subject
foreach subj ($SUBJECTS)
  echo $subj
  set outdir = $TUTORIAL_DIR/$subj/dtrecon

  # For each subject's wmparc and aparc+aseg volumes resample them to diffusion space
  foreach vol (wmparc aparc+aseg)
    set vol = $SUBJECTS_DIR/$subj/mri/$vol.mgz
    set vol2diff = ${vol:r}2diff.mgz
    set cmd = (mri_vol2vol --mov $outdir/lowb.nii --targ $vol --inv --interp nearest \
               --o $vol2diff --reg $outdir/register.dat --no-save-reg)
    echo $cmd
    eval $cmd
  end

end

Output: wmparc2diff.mgz, aparc+aseg2diff.mgz.

Return to Diffusion

DiffMasking.csh

 #!/bin/tcsh -ef
 #

source subjects.csh

# Loop through each subject
foreach subj ($SUBJECTS)
  echo $subj
  set outdir = $TUTORIAL_DIR/$subj/dtrecon

  # Use wmparc2diff.mgz to mask out noise in the fa.nii, adc.nii, and ivc.nii volumes
  foreach vol (fa adc ivc)
    set cmd = (mri_mask $outdir/$vol.nii $SUBJECTS_DIR/$subj/mri/wmparc2diff.mgz \
               $outdir/${vol}-masked.mgz)
    echo $cmd
    eval $cmd
  end

end

Output: fa-masked.mgz, adc-masked.mgz, ivc-masked.mgz.

Return to Diffusion

AlignAnatCVSToAvg.csh

 #!/bin/tcsh -ef
 #

source subjects.csh

set interp = trilin  
set template = $SUBJECTS_DIR/cvs_avg35/mri/norm.mgz

# Loop through each subject
foreach subj ($SUBJECTS)
  echo $subj
  set outdir = $TUTORIAL_DIR/$subj/dtrecon
  set morph = $SUBJECTS_DIR/$subj/cvs/fullCVSmorph-to-avg35template.m3z

# Resample the fa-masked.mgz, adc-masked.mgz, and ivc-masked.mgz to common CVS space
  foreach vol (fa adc ivc)
    set vol = $outdir/${vol}-masked.mgz
    echo $vol
    set outvol = ${vol:r}.ANAT+CVS-to-avg35.mgz
    echo $outvol
    set cmd = (mri_vol2vol --targ $template --m3z $morph --noDefM3zPath \
               --reg $outdir/register.dat --mov $vol \
               --o $outvol --interp $interp --no-save-reg)
    echo $cmd
    eval $cmd
  end

end

Output: fa-masked.ANAT+CVS-to-avg35.v2v.mgz, adc-masked.ANAT+CVS-to-avg35.v2v.mgz, ivc-masked.ANAT+CVS-to-avg35.v2v.mgz.

Return to Diffusion

GroupAnalysis.csh

 #!/bin/tcsh -ef

source subjects.csh

set outdir = $TUTORIAL_DIR/GLM
mkdir -p $outdir

# Assemble input for group analysis
set type = CVS-to-avg35    # alternatively could be 'TAL' or 'MNI'
set prefix = fa-masked     # alternatively could be adc-masked or ivc-masked
set inputfiles = ()

foreach subj ($SUBJECTS)
  set inputfiles=($inputfiles $TUTORIAL_DIR/$subj/dtrecon/${prefix}.ANAT+${type}.mgz)
end

set cmd = (mri_concat --i $inputfiles --o $outdir/GroupAnalysis.${prefix}.${type}.Input.mgz)
echo $cmd
eval $cmd

# Create average of the input images for visualization
set cmd = (mri_average $inputfiles $outdir/Average.{$prefix}.${type}.Input.mgz)
echo $cmd
eval $cmd

set cmd = (mri_glmfit --y $outdir/GroupAnalysis.{$prefix}.${type}.Input.mgz \
          --fsgd group_analysis.fsgd dods --C contrast.mtx \
          --glmdir $outdir/gender_age.{$prefix}.${type}.glmdir --mgz)
echo $cmd
eval $cmd

Output: gender_age.fa-masked.CVS-to-avg35.glmdir, dof.dat, mri_glmfit.log, y.fsgd, X.mat, contrast/Xg.dat, contrast/rstd.mgz, contrast/rvar.mgz, contrast/beta.mgz, contrast/fwhm.dat, contrast/sar1.mgz, contrast/mask.mgz.

Return to Diffusion

FsTutorial/Diffusion/DTIscripts (last edited 2017-03-21 10:59:57 by AllisonMoreau)