Chapter 6 Register T2 to T1
After you finish running the preprocessing steps on your T2 images, these are the image you will ALWAYS use for analyses. The T2 image will be in the same native space and registered to your processed T1 image. Log onto the remote computer.
6.1 Job Script
On the remote computer create script.
vi ~/scripts/ACAP/t2warp-job.sh
Copy and paste code.
#!/bin/bash
#SBATCH --time=01: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_DIR=/work/${username}/BIDS/ACAP/${1}/${2}/anat/
OUTPUT_DIR=/work/${username}/data/ACAP/prepAnat/${1}_${2}
mkdir -p ${OUTPUT_DIR}
## REGISTRATION
antsRegistrationSyNQuick.sh \
-d 3 \
-f ${OUTPUT_DIR}/${1}_${2}_T1w.nii.gz \
-m ${DATA_DIR}/${1}_${2}_T2w.nii.gz \
-o ${OUTPUT_DIR}/${1}_${2}_inplaneT2 \
-t a
6.2 Batch Script
First check that your subjid
and ses
are correct.
for i in $(find /work/ashley.ware/data/ACAP/prepAnat/ -name "*T1w.nii.gz"); do
id=`echo $i | cut -d "/" -f7`
subjid=${id:0:12}
ses=${id:13}
echo $subjid
echo $ses
done
If everything is correct then you can create your batch file.
Create script.
vi ~/scripts/ACAP/t2warp-batch.sh
Copy and paste code.
#!/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
id=`echo $i | cut -d "/" -f7`
subjid=${id:0:12}
ses=${id:13}
t2image=/work/${username}/BIDS/ACAP/${subjid}/${ses}/anat/${subjid}_${ses}_T2w.nii.gz
if [ -f $t2image ]; then
sbatch \
-o ~/logfiles/ACAP/${curTime}/output-${subjid}_${ses}.txt \
-e ~/logfiles/ACAP/${curTime}/error-${subjid}_${ses}.txt \
~/scripts/ACAP/t2warp-job.sh \
${subjid} \
${ses}
sleep 1
fi
done
6.3 Submit Jobs with Batch Script
sh ~/scripts/ACAP/t2warp-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*
6.4 Clean Up Directory
Once you have confirmed your resampled.nii.gz came out correctly:
find /work/ashley.ware/data/ACAP/prepAnat \
-type f \
-name "*T2InverseWarped.nii.gz" \
-exec rm {} \;
find /work/ashley.ware/data/ACAP/prepAnat \
-type f \
-name "*T20GenericAffine.mat" \
-exec rm {} \;
for i in $(find /work/ashley.ware/data/ACAP/prepAnat/ \
-type f \
-name "*inplaneT2Warped.nii.gz"); do
cd $(dirname $i)
subjid=`echo $i | cut -d "/" -f7`
mv $(basename $i) ${subjid}_inplaneT2.nii.gz
done
6.5 Directory Structure
The final data structure will look like this.
/work/ashley.ware/data/ACAP/prepAnat/
|–– sub-ACAP1001_ses-BL/
|–– sub-ACAP1001_ses-BL_T1w.nii.gz
|–– sub-ACAP1001_ses-BL_inplaneT2.nii.gz
|–– sub-ACAP1001_ses-FU3/
|–– sub-ACAP1001_ses-FU3_T1w.nii.gz
|–– sub-ACAP1001_ses-FU3_inplaneT2.nii.gz
6.6 Download Directory / Sync Directory with Arc
Back on your local computer, sync from your remote to your local computer.
rsync -rauv \
ashley.ware@arc.ucalgary.ca:/work/ashley.ware/data/ACAP/prepAnat/ \
/Volumes/bobo/data/ACAP/prepAnat/