Skip to content

Instantly share code, notes, and snippets.

@FidgetteSpinneur
Created April 1, 2020 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FidgetteSpinneur/4f45af8862074fe0076dcd41faa4f80e to your computer and use it in GitHub Desktop.
Save FidgetteSpinneur/4f45af8862074fe0076dcd41faa4f80e to your computer and use it in GitHub Desktop.
#!/bin/bash
#
#SBATCH -J fmriprep
#SBATCH --time=48:00:00
#SBATCH -n 1
#SBATCH --cpus-per-task=16
#SBATCH --mem-per-cpu=8G
#SBATCH -p HPC # Queue names you can submit to
# Outputs ----------------------------------
#SBATCH -o log/%A-%a.out
#SBATCH -e log/%A-%a.err
#SBATCH --mail-user=%u@domain.tld
#SBATCH --mail-type=ALL
# ------------------------------------------
# Specify directories and names, change these according to the version of fmriprep
BIDS_DIR="$STUDY/rawdata"
DERIVS_DIR="$STUDY/derivatives/fmriprep-1.5.2"
IMAGE_NAME="poldracklab_fmriprep_1.5.2-2019-12-02-6afc1e0e96cd.simg"
IMAGE_DIR="$STUDY/code/singularity"
# Prepare some writeable bind-mount points, these are local to prevent network traffic issues
TEMPLATEFLOW_HOST_HOME=/tmp/templateflow-$(whoami)
FMRIPREP_HOST_CACHE=/tmp/fmriprep-$(whoami)
mkdir -p ${TEMPLATEFLOW_HOST_HOME}
mkdir -p ${FMRIPREP_HOST_CACHE}
# Make derivatives folder
mkdir -p ${DERIVS_DIR}
# Make variable to represent freesurfer license (download from the freesurfer website)
export SINGULARITYENV_FS_LICENSE=$STUDY/code/singularity/license.txt
# Make variable for the templateflow bind-mount point inside the container
export SINGULARITYENV_TEMPLATEFLOW_HOME="/templateflow"
#Specify the singularity command which sets up the environment, binds the $STUDY path to the bind mount point inside the container, and specifies the singularity image
SINGULARITY_CMD="singularity run --cleanenv -B $STUDY:/projectFolder -B ${TEMPLATEFLOW_HOST_HOME}:${SINGULARITYENV_TEMPLATEFLOW_HOME} -B $L_SCRATCH:/work $IMAGE_DIR/$IMAGE_NAME"
# Parse the participants.tsv file and extract one subject ID from the line corresponding to this SLURM task.
subject=$( sed -n -E "$((${SLURM_ARRAY_TASK_ID} + 1))s/sub-(\S*)\>.*/\1/gp" ${BIDS_DIR}/participants.tsv )
# Compose the command line
cmd="${SINGULARITY_CMD} /projectFolder/rawdata /projectFolder/derivatives/fmriprep-1.5.2_tempflow-davidm participant --participant-label $subject -w /work --output-spaces MNI152NLin2009cAsym:res-2 anat fsnative fsaverage5 -vv --no-submm-recon --fs-license-file $SINGULARITYENV_FS_LICENSE --skip_bids_validation"
# Setup done, run the command
echo Running task ${SLURM_ARRAY_TASK_ID}
echo Commandline: $cmd
eval $cmd
exitcode=$?
# Output results to a table
echo "sub-$subject ${SLURM_ARRAY_TASK_ID} $exitcode" \
>> ${SLURM_JOB_NAME}.${SLURM_ARRAY_JOB_ID}.tsv
echo Finished tasks ${SLURM_ARRAY_TASK_ID} with exit code $exitcode
exit $exitcode
@FidgetteSpinneur
Copy link
Author

First, install the developmental version of templateflow:
[...]
Let me know if that helps.

Yes! We're good! We'll keep an eye on the releases, I'm guessing once fMRIPrep includes TF >= 0.6.0rc2 we can skip this step?

Thanks a lot for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment