Skip to content

Commit

Permalink
Add script.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 3, 2024
1 parent 9ff6be3 commit 73a735f
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN python -m build /src
#

# Utilities for downloading packages
FROM ${BASE_IMAGE} as downloader
FROM ${BASE_IMAGE} AS downloader
# Bump the date to current to refresh curl/certificates/etc
RUN echo "2023.07.20"
RUN apt-get update && \
Expand All @@ -53,7 +53,7 @@ RUN apt-get update && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# AFNI
FROM downloader as afni
FROM downloader AS afni
# Bump the date to current to update AFNI
RUN echo "2023.07.20"
RUN mkdir -p /opt/afni-latest \
Expand All @@ -70,7 +70,7 @@ RUN mkdir -p /opt/afni-latest \
&& find /opt/afni-latest -type f -not -name "3dTshift" -delete

# Connectome Workbench 1.5.0
FROM downloader as workbench
FROM downloader AS workbench
RUN mkdir /opt/workbench && \
curl -sSLO https://www.humanconnectome.org/storage/app/media/workbench/workbench-linux64-v1.5.0.zip && \
unzip workbench-linux64-v1.5.0.zip -d /opt && \
Expand All @@ -79,7 +79,7 @@ RUN mkdir /opt/workbench && \
strip --remove-section=.note.ABI-tag /opt/workbench/libs_linux64/libQt5Core.so.5

# Micromamba
FROM downloader as micromamba
FROM downloader AS micromamba

# Install a C compiler to build extensions when needed.
# traits<6.4 wheels are not available for Python 3.11+, but build easily.
Expand Down Expand Up @@ -108,7 +108,7 @@ RUN npm install -g svgo@^3.2.0 bids-validator@^1.14.0 && \
#
# Main stage
#
FROM ${BASE_IMAGE} as fmripost_rapidtide
FROM ${BASE_IMAGE} AS fmripost_rapidtide

# Configure apt
ENV DEBIAN_FRONTEND="noninteractive" \
Expand Down
140 changes: 140 additions & 0 deletions scripts/fetch_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env python
"""
Standalone script to facilitate caching of required TemplateFlow templates.
To download and view how to use this script, run the following commands inside a terminal:
1. wget https://raw.githubusercontent.com/nipreps/fmriprep-aroma/main/scripts/fetch_templates.py
2. python fetch_templates.py -h
"""

import argparse
import os


def fetch_MNI2009():
"""
Expected templates:
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_T1w.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_mask.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-brain_mask.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-carpet_dseg.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-02_desc-fMRIPrep_boldref.nii.gz
tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_label-brain_probseg.nii.gz
"""
template = 'MNI152NLin2009cAsym'

# tf.get(template, resolution=(1, 2), desc=None, suffix='T1w')
# tf.get(template, resolution=(1, 2), desc='brain', suffix='mask')
tf.get(template, resolution=1, atlas=None, desc='carpet', suffix='dseg')
# tf.get(template, resolution=2, desc='fMRIPrep', suffix='boldref')
# tf.get(template, resolution=1, label='brain', suffix='probseg')


def fetch_MNI6():
"""
Expected templates:
tpl-MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-01_T1w.nii.gz
tpl-MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-02_T1w.nii.gz
tpl-MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-01_desc-brain_mask.nii.gz
tpl-MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-02_desc-brain_mask.nii.gz
tpl-MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-02_atlas-HCP_dseg.nii.gz
"""
template = 'MNI152NLin6Asym'

tf.get(template, resolution=(1, 2), desc=None, suffix='T1w')
tf.get(template, resolution=(1, 2), desc='brain', suffix='mask')
# CIFTI
tf.get(template, resolution=2, atlas='HCP', suffix='dseg')
# Transform from MNI152NLin2009cAsym to MNI152NLin6Asym
tf.get(
template, mode='image', suffix='xfm', extension='.h5', **{'from': 'MNI152NLin2009cAsym'}
)


def fetch_OASIS():
"""
Expected templates:
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-WM_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-BS_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_label-brain_probseg.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-brain_mask.nii.gz
tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_desc-BrainCerebellumExtraction_mask.nii.gz
"""
template = 'OASIS30ANTs'

tf.get(template, resolution=1, desc=None, label=None, suffix='T1w')
tf.get(template, resolution=1, label='WM', suffix='probseg')
tf.get(template, resolution=1, label='BS', suffix='probseg')
tf.get(template, resolution=1, label='brain', suffix='probseg')
tf.get(template, resolution=1, label='brain', suffix='mask')
tf.get(template, resolution=1, desc='BrainCerebellumExtraction', suffix='mask')


def fetch_fsaverage():
"""
Expected templates:
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_desc-std_sphere.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_desc-std_sphere.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_desc-vaavg_midthickness.shape.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_desc-vaavg_midthickness.shape.gii
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_midthickness.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_midthickness.surf.gii
tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_sulc.shape.gii
tpl-fsaverage/tpl-sfaverage_hemi-R_den-164k_sulc.shape.gii
"""
template = 'fsaverage'

tf.get(template, density='164k', desc='std', suffix='sphere')
tf.get(template, density='164k', suffix='midthickness')
tf.get(template, density='164k', suffix='sulc')


def fetch_fsLR():
"""
Expected templates:
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_desc-nomedialwall_dparc.label.gii
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_desc-vaavg_midthickness.shape.gii
tpl-fsLR/tpl-fsLR_hemi-L_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_desc-nomedialwall_dparc.label.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_desc-vaavg_midthickness.shape.gii
tpl-fsLR/tpl-fsLR_hemi-R_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-L_den-32k_sphere.surf.gii
tpl-fsLR/tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii
"""
tf.get('fsLR', density='32k')


def fetch_all():
fetch_MNI2009()
fetch_MNI6()
# fetch_OASIS()
# fetch_fsaverage()
# fetch_fsLR()


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Helper script for pre-caching required templates to run fMRIPost-AROMA',
)
parser.add_argument(
'--tf-dir',
type=os.path.abspath,
help='Directory to save templates in. If not provided, templates will be saved to'
' `${HOME}/.cache/templateflow`.',
)
opts = parser.parse_args()

# set envvar (if necessary) prior to templateflow import
if opts.tf_dir is not None:
os.environ['TEMPLATEFLOW_HOME'] = opts.tf_dir

import templateflow.api as tf

fetch_all()

0 comments on commit 73a735f

Please sign in to comment.