Skip to content

Module 8 Brain Age

Jared Tanner edited this page Jun 13, 2024 · 11 revisions

A more complete background to brain age models will be added later (possibly only available for future years).

In short, there are multiple machine learning models of brain age. These were typically trained on thousands to tens of thousands of images. They can be applied by taking a T1-weighted image (at least for the method we are using), preprocessing it (the methods vary from method to method), and then applying the prediction models.

The method we are using for this module is called Pyment. It was published in 2022: https://www.sciencedirect.com/science/article/pii/S1053811922003342?via%3Dihub

Code available here: https://github.com/estenhl/pyment-public?tab=readme-ov-file

I've taken the code and made a Singularity container from it. I also made another container that will be used in the preprocessing steps.

All code and containers used are available in the Module8 directory on the class share drive on HiPerGator. Please do not move or delete anything in there!

Here is the walk-through video: https://youtu.be/wlRk8krLdCI?si=04TRrug6dT16_gjM

You can download the commands from the Module8 directory.

#Run the following to create a directory and subdirectories for the pyment
analysis
#Before running the following commands, make sure to replace the path with
the paths for your data
mkdir -p
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/{tmp,in,images,p
redictions}
cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/
#Run the following to load the freesurfer and fsl modules
module load freesurfer fsl
#Run the following to convert the brain.mgz files to nifti format
mri_convert
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/sub-
011S6303/mri/brain.mgz
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/tmp/sub-
011S6303_brain.nii.gz
mri_convert
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/sub-
011S6367/mri/brain.mgz
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/tmp/sub-
011S6367_brain.nii.gz
#Run the following to reorient the images to standard orientation
cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/tmp
fslreorient2std sub-011S6303_brain.nii.gz sub-011S6303_brain2std
fslreorient2std sub-011S6367_brain.nii.gz sub-011S6367_brain2std
#Run the following to align the images with the MNI template using a 6
degrees of freedom transformation
flirt -in sub-011S6303_brain2std.nii.gz -ref
$FSLDIR/data/standard/MNI152_T1_1mm_brain.nii.gz -out
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/in/sub-
011S6303_brain2mni -dof 6
flirt -in sub-011S6367_brain2std.nii.gz -ref
$FSLDIR/data/standard/MNI152_T1_1mm_brain.nii.gz -out
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/in/sub-
011S6367_brain2mni -dof 6
cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment
#Run the following to crop the images
apptainer run --cleanenv \
--bind
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/in:/in,/blue/clp
7934/share/jjtanner/ADNI_bids/derivatives/pyment/images:/out \
/blue/clp7934/share/Module8/crop_pyment_prep.sif /in /out
cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment/
#Run the following command to create a csv file with the labels for the
images
cat <<EOF > labels.csv
id,age,
sub-011S6303_brain2mni_crop,75
sub-011S6367_brain2mni_crop,70
EOF
#Run the following to predict the brain age of the images
apptainer run --cleanenv \
--bind
/blue/clp7934/share/jjtanner/ADNI_bids/derivatives/pyment:/images,/blue/cl
p7934/share/jjtanner/ADNI_bids/derivatives/pyment/predictions:/predictions
\
/blue/clp7934/share/Module8/pyment.sif

Please make sure you update all paths and names as needed. Those commands work for my directories on HiPerGator but will not work for you without you editing them first. Most of the changes should be minor (my Gatorlink to yours). If you have your FreeSurfer-processed files named differently than what I have mine named and/or in a different relative location, update paths to match. I don't recommend changing output file names or locations (other than making sure to change my gatorlink to yours), for simplicity. You might have to make more changes to paths and file names on in the mri_convert commands (see the commands.txt file).

If you make sure you have all the files (they should have been processed with FreeSurfer earlier in the semester), following along with the video should be fairly straightforward.

The whole process shouldn't take more than about 30 - 40 minutes, but leave time for troubleshooting when you request a HiPerGator Desktop session.

What you submit

Predict the brain age of two brains (using our ADNI ones you processed with FreeSurfer is easiest). Upload the logs.txt and predictions.csv files created by the pyment.sif container.

Clone this wiki locally