Chapter 7 ANTS Cortical Thickness

Log onto the remote computer. Remember you will be using the preprocessed T1 image found under ‘/work/${username}/data/ACAP/prepAnat/’.

7.1 Download Template

On the remote computer, download the OASIS template.

mkdir ~/templates
cd ~/templates
wget https://s3-eu-west-1.amazonaws.com/pfigshare-u-files/3133832/Oasis.zip
unzip Oasis.zip && rm -rf Oasis.zip

If the template directory isn’t labeled OASIS, rename the directory.

cd ~/templates
mv MICCAI2012-Multi-Atlas-Challenge-Data/ OASIS/

7.2 Job Script

Still on the remote computer, create job script. The output files will have to be placed under a mindboggle directory, ‘/work/ashley.ware/data/ACAP/mindboggle/ants_subjects/’.

vi ~/scripts/ACAP/antsCT-job.sh

Copy and paste.

#!/bin/bash

#SBATCH --time=15:00:00  # walltime
#SBATCH --ntasks=1  # number of processor cores (i.e. tasks)
#SBATCH --nodes=1  # number of nodes
#SBATCH --mem-per-cpu=16G  # memory per CPU core

# LOAD ENVIRONMENTAL VARIABLES
username=`id -un`
export ANTSPATH=/home/${username}/apps/ants/bin/
PATH=${ANTSPATH}:${PATH}

# INSERT CODE, AND RUN YOUR PROGRAMS HERE
DATA=/work/${username}/data/ACAP/prepAnat/${1}
TPL=~/templates/OASIS
mkdir -p /work/${username}/data/ACAP/mindboggle/ants_subjects/${1}/

antsCorticalThickness.sh \
-d 3 \
-a ${DATA}/${1}_T1w.nii.gz \
-e ${TPL}/T_template0.nii.gz \
-t ${TPL}/T_template0_BrainCerebellum.nii.gz \
-m ${TPL}/T_template0_BrainCerebellumProbabilityMask.nii.gz \
-f ${TPL}/T_template0_BrainCerebellumExtractionMask.nii.gz \
-p ${TPL}/Priors2/priors%01d.nii.gz \
-q 1 \
-n 6 \
-x 6 \
-o /work/${username}/data/ACAP/mindboggle/ants_subjects/${1}/ants

7.3 Batch Script

First check that your subjid are correct.

for i in $(find /work/ashley.ware/data/ACAP/prepAnat/ -name "*T1w.nii.gz"); do
  subjid=`echo $i | cut -d "/" -f7`
  echo $subjid
done

If everything is correct then you can create your batch file.

Create batch script.

vi ~/scripts/ACAP/antsCT-batch.sh

Copy and paste.

#!/bin/bash
curTime=`date +"%Y%m%d-%H%M%S"`
username=`id -un`
mkdir -p ~/logfiles/ACAP/${curTime}
for i in $(find /work/${username}/data/ACAP/prepAnat/ -name "*T1w.nii.gz"); do
  subjid=`echo $i | cut -d "/" -f7`
  sbatch \
  -o ~/logfiles/ACAP/${curTime}/output_${subjid}.txt \
  -e ~/logfiles/ACAP/${curTime}/error_${subjid}.txt \
  ~/scripts/ACAP/antsCT-job.sh \
  ${subjid}
  sleep 1
done

7.4 Submit Jobs with Batch Script

Submit jobs.

sh ~/scripts/ACAP/antsCT-batch.sh

You can check the status of your jobs by checking if it is running or pending.

squeue

You can check the outputs.

tail -n 5 ~/logfiles/ACAP/<date>/output*

7.5 Directory Structure

The final data structure will look like this.

/work/ashley.ware/data/ACAP/mindboggle/
  |–– ants_subjects/
    |–– sub-ACAP1001_ses-BL/
      |–– antsACTStage1Complete.txt
      |–– antsACTStage2Complete.txt
      |–– antsACTStage3Complete.txt
      |–– antsACTStage4Complete.txt
      |–– antsACTStage5Complete.txt
      |–– antsACTStage6Complete.txt
      |–– antsBrainExtractionMask.nii.gz
      |–– antsBrainNormalizedToTemplate.nii.gz
      |–– antsBrainSegmentation0N4.nii.gz
      |–– antsBrainSegmentationConvergence.txt
      |–– antsBrainSegmentation.nii.gz
      |–– antsBrainSegmentationPosteriors1.nii.gz
      |–– antsBrainSegmentationPosteriors2.nii.gz
      |–– antsBrainSegmentationPosteriors3.nii.gz
      |–– antsBrainSegmentationPosteriors4.nii.gz
      |–– antsBrainSegmentationPosteriors5.nii.gz
      |–– antsBrainSegmentationPosteriors6.nii.gz
      |–– antsBrainSegmentationTiledMosaic.png
      |–– antsbrainvols.csv
      |–– antsCorticalThickness.nii.gz
      |–– antsCorticalThicknessNormalizedToTemplate.nii.gz
      |–– antsCorticalThicknessTiledMosaic.png
      |–– antsExtractedBrain0N4.nii.gz
      |–– antsRegistrationTemplateBrainMask.nii.gz
      |–– antsSubjectToTemplate0GenericAffine.mat
      |–– antsSubjectToTemplate1Warp.nii.gz
      |–– antsSubjectToTemplateLogJacobian.nii.gz
      |–– antsTemplateToSubject0Warp.nii.gz
      |–– antsTemplateToSubject1GenericAffine.mat

7.6 Download Directory / Sync Directory with Arc

Back on your local computer make sure you have the directory already.

mkdir -p /Volumes/bobo/data/ACAP/mindboggle/ants_subjects

Then sync the data from the remote computer to your local computer.

rsync -rauv \
ashley.ware@arc.ucalgary.ca:/work/ashley.ware/data/ACAP/mindboggle/ants_subjects/ \
/Volumes/bobo/data/ACAP/mindboggle/ants_subjects/