ANTs tutorial with Slurm Workload Manager
This tutorial illustrates Advanced Normalization Tools (ANTs) to do image registration in 3D using data from Brain/MINDS data portal and how to apply the transforms/inverse transforms from image registration using the Slurm Workload Manager.
ANTs is described on their repository as follows:
"Advanced Normalization Tools (ANTs) is a C++ library available through the command line that computes high-dimensional mappings to capture the statistics of brain structure and function. It allows one to organize, visualize and statistically explore large biomedical image sets. Additionally, it integrates imaging modalities in space + time and works across species or organ systems with minimal customization."
This tutorial is derived from the tutorial at the Brain/MINDS data portal.
As with all Slurm jobs, start with the resource requests. Note that ANTs is memory intensive, so the request on our system is double what what would normally be allocated per CPU. Also, note that the application is multi-threaded.
#SBATCH --ntasks=1 #SBATCH --cpus-per-task=2 #SBATCH --mem=40GB #SBATCH --time=0:30:00
Let's download some brains! And what marvellous brains they are!
"The dataset includes NIfTI files of MRI T2 ex-vivo data; reconstructed Nissl stained images of the same brain, registered to the shape of the MRI; brain region segmentation (with separate color lookup table); and gray, mid-cortical and white matter boundary segmentation" (BMA 2017 Ex Vivo (Brain Space 1)
From: https://dataportal.brainminds.jp/atlas-package-download-main-page/refere...
"This atlas is composed of a population average ex-vivo MRI T2WI contrast mapped with the BMA 2017 Ex Vivo (published by Woodward et al. The Brain/MINDS 3D digital marmoset brain atlas). The population average MRI was constructed based on scans of 25 individual brains. The 25 brains were aligned with one another by iteratively applying linear and non-linear registration and averaging the transformation files until convergence. Data of individual brains were then resampled with an isotropic spatial resolution of 100×100×100µm3 and averaged across brain." BMA 2019 Ex Vivo (Brain Space 2)
From: https://dataportal.brainminds.jp/atlas-package-download-main-page/bma-20...
This can be added to the job submission script as follows:
wget https://cau-gin.brainminds.riken.jp/brainminds/BMA-2017/raw/master/bma-1-mri.nii.gz wget https://cau-gin.brainminds.riken.jp/brainminds/BMA-2017/raw/master/bma-1-region_seg.nii.gz wget https://cau-gin.brainminds.riken.jp/brainminds/BMA-2019/raw/master/bma_2019_exvivo/base_data/sp2_avg_mri_exvivo_t2wi_v1.0.0.nii.gz wget https://cau-gin.brainminds.riken.jp/brainminds/BMA-2019/raw/master/bma_2019_exvivo/labelmap/sp2_label_512_v1.0.0.nii.gz
Then clear the environment and load software PATHs. This assumes LMod and modify according to the software stack available.
module purge module load foss/2022a module load ANTs/2.4.4
Now register brain1 to brain2. The options are -d 3 (the dimensions of the brain, 3 in this case), -f the fixed image or the image we want to register to, in our case, this will be brain2., -m the moving image or the image we want to register, in our case, this will be brain1., -o the output prefix, in this example, the output files will all have the prefix "brain1_tobrain2"., -n the number of threads; add this to the end of the command. Thus we get the following command:
antsRegistrationSyNQuick.sh d 3 \ -f sp2_avg_mri_exvivo_t2wi_v1.0.0.nii.gz \ -m bma-1-mri.nii.gz \ -o brain1_to_brain2_ \ -n 2
Now conduct an inverse transform (map label2 to brain1). The option -d is the same as above., -i represents the the volume we want to register, -r is the refences image (brain1)., -o is the output file., -t are the transforms, applied right to left in this case the inverse of the affine transforms, then the inverse displacement field., -n the interpolation method to be used, nothing to do with the number of threads (see previous command).
antsApplyTransforms -d 3 \ -i sp2_label_512_v1.0.0.nii.gz \ -r bma-1-mri.nii.gz \ -o label2_to_brain1.nii.gz \ -t [brain1_to_brain2_0GenericAffine.mat, 1] \ -t brain1_to_brain2_1InverseWarp.nii.gz \ -n NearestNeighbor
The full Slurm script is attached.
If you want to compare the result with the label map before registration, you can do it by loading sp2_label_512_v1.0.0.nii.gz and bma-1-mri.nii.gz with an application like 3DSlicer.