Skip to content

FreeSurfer v5.3 Processing on CFN

megq edited this page May 18, 2017 · 5 revisions

Reprocessing FS on CFN with v5.3

Motivation:

In moving CONTE data to CFN, the subjects were reprocessed on CFN using FreeSurfer v5.3. This is the same process and version that was run on monstrum.

Scripts Overview:

  • wrapper script: /data/joy/BBL/projects/conteReproc2017/freesurfer/surf2grid.sh
    • calls: /data/joy/BBL/projects/conteReproc2017/freesurfer/freesurfer_grid_submission.sh

Runs FreeSurfer version 5.3. The code is broken down into two main sections:

  • Set necessary FreeSurfer variables and check for existing FreeSurfer data
  • Run FreeSurfer 5.3 on individuals without FreeSurfer data

Output:

  • FreeSurfer data for each subject (mri, stats, surf, label)
    • /data/joy/BBL/studies/conte/processedData/structural/freesurfer/[bblid]/[datexscanid]/
  • Log files (.o and .e) for each subject
    • /data/joy/BBL/projects/conteReproc2017/freesurfer/logs/

FreeSurfer Processing:

Set necessary variables and check for existing FreeSurfer data

Script: /data/joy/BBL/projects/conteReproc2017/freesurfer/surf2grid.sh

Requires:

  • FreeSurfer output directory (SUBJECTS_DIR)
    export SUBJECTS_DIR="/data/joy/BBL/studies/conte/processedData/freesurfer"
  • List of subjects (slist) (in the form of a wildcard ls statement in the subjects directory)
    slist=$(ls -d /data/joy/BBL/studies/conte/rawData/*/*x*)
  • MPRAGE nifti (infile)
    infile=ls -d $i/MPRAGE*ipat2*moco3*/nifti/*MPRAGE*ipat2*moco3*.nii.gz
  • Full path to log files
    logs="/data/joy/BBL/projects/conteReproc2017/freesurfer/logs"

Steps:

  1. loops through each subject, and creates variables for the bblid (bblid), subject id (subjid) (unique to timepoint, in the form of datexscanid), MPRAGE nifti (infile), the subject/timepoint specific directory (surfpath), and the subject specific directory (SUBJECTS_DIR)

  2. locates the T1 structural MPRAGE nifti needed for FreeSurfer processing and creates a variable called infile for this

  3. creates FreeSurfer specific directory variables for the subject/timepoint unique output directory (surfpath) where processed FreeSurfer data for that subject/timepoint will be output, and the overall subject directory which FreeSurfer also requires (SUBJECTS_DIR).

    (Steps 1-3)    
             
    export SUBJECTS_DIR="/data/joy/BBL/studies/conte/processedData/freesurfer"  
    slist=$(ls -d /data/joy/BBL/studies/conte/rawData/*/*x*)   
    logs="/data/joy/BBL/projects/conteReproc2017/freesurfer/logs"  
               
    #for every subject in the subjects folder  
    for i in $slist; do  
    	#get bblid, datexscanid, and MPRAGE nifti   
    	bblid=`echo $i | cut -d "/" -f 8`  
    	subjid=`echo $i | cut -d "/" -f 9`  
    	echo $subjid  
    	infile=`ls -d $i/MPRAGE*ipat2*moco3*/nifti/*MPRAGE*ipat2*moco3*.nii.gz`  
    	#get the working subjects folder for that subject  
    	surfpath=`ls -d /data/joy/BBL/studies/conte/processedData/freesurfer/$bblid/$subjid`  
    	SUBJECTS_DIR="/data/joy/BBL/studies/conte/processedData/freesurfer/$bblid"  
    
  4. checks that the subject/timepoint specific output directory (surfpath) is empty, and if not, prints the statement
    *-*-*-*-Freesurfer has already been run for this subject-*-*-*-*
    and moves on to the next subject.

  5. If the surfpath is empty, then the raw MPRAGE nifti (infile), subject specific but not timepoint specific output directory (SUBJECTS_DIR), and subject/timepoint specific subject id (subjid) are passed to the next script in the pipeline (/data/joy/BBL/projects/conteReproc2017/freesurfer/freesurfer_grid_submission.sh) which is set up to run on the grid.

qsub -V -e $logs -o $logs -q all.q -S /bin/bash /data/joy/BBL/projects/conteReproc2017/freesurfer/freesurfer_grid_submission.sh $infile $SUBJECTS_DIR $subjid

  1. The script then moves on to the next subject in the loop and performs the same steps

Notes:

  • For CONTE FreeSurfer processing on CFN the SUBJECTS_DIR is unique to each subject but not to each timepoint. This SUBJECTS_DIR changes for each subject bblid, as per the directory structure set up on CFN (bblid/datexscanid). Previous projects and runs of Freesurfer elsewhere have maintained the same SUBJECTS_DIR for each subject.

Run FreeSurfer version 5.3

Script: /data/joy/BBL/projects/conteReproc2017/freesurfer/freesurfer_grid_submission.sh

Requires:

  • arguments passed by /data/joy/BBL/projects/conteReproc2017/freesurfer/surf2grid.sh
    • MPRAGE raw nifti (infile)
    • subject (bblid) specific output directory (SUBJECTS_DIR)
    • subject/timepoint unique id (subjid))
  • FreeSurfer version specific environments (FREESURFER_HOME and PERL5LIB)

Steps:

  1. creates variables from the arguments passed to the script.

     export FREESURFER_HOME="/share/apps/freesurfer/5.3.0"       
     export SUBJECTS_DIR=$2    
     export PERL5LIB="/share/apps/freesurfer/5.3.0/mni/lib/perl5/5.8.5"    
     mprage=$1    
     subjid=$3  
    
  2. runs recon-all -i (initial set up) to create each subject's unique subject/timepoint FS directory structure (surfpath from previous script: /data/joy/BBL/studies/conte/processedData/freesurfer/$bblid/$subjid)

recon-all -i $mprage -subjid $subjid

  1. runs recon-all -all -qcache (all standard FreeSurfer processing) on each subject/timepoint.

recon-all -subjid $subjid -all -qcache

Notes:

  • runs on sge and each subject takes approximately 16-24 hours to run this FreeSurfer process
  • -qcache argument usage from recon-all --help:
    • Produce the pre-cached files required by the Qdec utility, allowing rapid analysis of group data. These files are created by running mris_preproc, which creates smoothed surface data files sampled to the 'fsaverage' common-space surface. By default, the surface data for thickness, curv, sulc, area and jacobian_white are smoothed at 0, 5, 10, 15, 20, and 25 mm FWHM. If just one set of surface data needs to be processed, then the option -measure can follow -qcache, where is one of: thickness, curv, sulc, area, jacobian_white or any surface measure. Multiple instances of -measure is supported. The -measuredir option allows specifying a directory other than the default of surf. Another option is -fwhm where is a value in mm. Also, -target allows specifying a common-space target other than fsaverage (the default). qcache is also a target for make, eg. recon-all -make qcache
  • See also: http://surfer.nmr.mgh.harvard.edu/fswiki/Qdec