Attention: Confluence is not suitable for the storage of highly confidential data. Please ensure that any data classified as Highly Protected is stored using a more secure platform.
If you have any questions, please refer to the University's data classification guide or contact ict.askcyber@sydney.edu.au
FBA - Longitudinal template
As MRtrix3 has not had built-in functions for creating a longitudinal template, this document describes a method for creating a longitudinal template based on the approach proposed by Genc et al. (2018). This method involves first creating individual subject templates by averaging across timepoints, and then creating the longitudinal template by averaging the individual subject templates.
This script should follow the PreAnalysis Longitudinal script which prepares all the fod and brain mask images for template generation.
#!/bin/bash -v
#PBS -P Project name
#PBS -N Job name
#PBS -l select=1:ncpus=12:mem=128GB
#PBS -q=main
#PBS -l walltime=48:00:00
#PBS -q defaultQ
cd $PBS_O_WORKDIR
module load mrtrix3/3.0.3
root_path=/scratch/Folder/
preanalysis_path=${root_path}PreAnalysisLongitudinal/
#####################
# Creating Template #
#####################
analysis_path=${root_path}LongitudinalAnalysis/
template_path=${analysis_path}Template/
intra_template_path=${analysis_path}Template/Individual_Templates/
fod_input_path=${preanalysis_path}fod/
mask_input_path=${preanalysis_path}mask_upsampled/
fod_path=${template_path}/fod_input/
mkdir ${analysis_path}
mkdir ${template_path}
mkdir ${intra_template_path}
mkdir ${fod_input_path}
mkdir ${mask_input_path}
mkdir ${template_path}/fod_input
mkdir ${template_path}/mask_input
template_list="01_MRI1 01_MRI2 05_MRI1" #your template list - this should include about 30 subjects representing your cohort#
#name your image XX_MRIY with XX = subject number, Y = timepoint#
for sub in $template_list; do
cp ${fod_input_path}${sub}_wmfod.mif ${template_path}fod_input/${sub}_wmfod.mif;
cp ${mask_input_path}${sub}_mask_upsampled.mif ${template_path}mask_input/${sub}_mask_upsampled.mif;
done
##########################
# Intra-subject Templates #
##########################
unique_names=$(for file in $fod_input_path*_MRI*; do
path=$(basename $file)
name=${path%%_*}
echo $name
done | sort -u)
for each in $unique_names; do
mkdir ${intra_template_path}fod_input_${each}
mkdir ${intra_template_path}mask_input_${each}
tmp_path=${intra_template_path}tmp_${each}/
mkdir ${tmp_path}
scans=$(find ${fod_path} -iname "$each*")
for a_scan in $scans; do
filename=$(basename "$a_scan")
each_scan=$(echo "$filename" | cut -d'_' -f1-2)
cp ${template_path}/fod_input/${each_scan}_wmfod.mif ${intra_template_path}fod_input_${each};
cp ${template_path}/mask_input/${each_scan}_mask_upsampled.mif ${intra_template_path}mask_input_${each};
done
population_template ${intra_template_path}fod_input_${each} -mask_dir ${intra_template_path}mask_input_${each} ${intra_template_path}${each}_wmfod.mif -voxel_size 1.25
for a_scan in $scans; do
filename=$(basename "$a_scan")
each_scan=$(echo "$filename" | cut -d'_' -f1-2)
mrregister ${intra_template_path}fod_input_${each}/${each_scan}_wmfod.mif \
-mask1 ${intra_template_path}mask_input_${each}/${each_scan}_mask_upsampled.mif \
${intra_template_path}${each_scan}_wmfod.mif -nl_warp ${tmp_path}${each_scan}_subject2template_warp.mif \
${tmp_path}${each_scan}template2subject_warp.mif;
mrtransform ${intra_template_path}mask_input_${each}/${each_scan}_mask_upsampled.mif \
-warp ${tmp_path}${each_scan}_subject2template_warp.mif \
-interp nearest -datatype bit \
${tmp_path}${each_scan}_dwi_mask_in_template_space.mif;
done
mrmath ${tmp_path}*_dwi_mask_in_template_space.mif min ${intra_template_path}${each}_brainmask_.mif -datatype bit
done
##########################
# Inter-subject Template #
##########################
mkdir ${inter_template_path}
mkdir ${inter_template_path}fod_input
mkdir ${inter_template_path}mask_input
for temp in $(ls ${intra_template_path} |grep wmfod_template); do
cp ${intra_template_path}*wmfod* ${inter_template_path}fod_input;
cp ${intra_template_path}*mask* ${inter_template_path}mask_input;
done
inter_template_path=${root_path}Template/Inter_Template/
# Generate a study-specific unbiased FOD template
population_template ${inter_template_path}fod_input -mask_dir ${inter_template_path}mask_input ${inter_template_path}wmfod_template.mif -voxel_size 1.25