Last active
March 16, 2022 20:18
-
-
Save htwangtw/a985605553015c5efd88134a0777e560 to your computer and use it in GitHub Desktop.
run fmriprep in multiple tmux sessions in parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# NOTE: make sure freesurfer licence is under ${HOME}/.freesurfer.txt before running the script | |
SING_IMG="/data/cisl/containers/fmriprep-20.2.1lts.sif" | |
DATASET="ds000228" | |
DATASET_DIR="/data/cisl/datasets/${DATASET}" | |
# run BIDS validator | |
singularity exec -B ${DATASET_DIR}/${DATASET}_openfmri:/DATA \ | |
${SING_IMG} bids-validator \ | |
/DATA | |
SUBJECTS_LIST=($(ls ${DATASET_DIR}/${DATASET}_openfmri/sub-* -d)) | |
N_SUBJECTS=10 | |
for i in $(seq ${N_SUBJECTS}); do | |
i=$((i-1)) | |
subject=${SUBJECTS_LIST[$i]} | |
participant_id=${subject#*-} | |
# create fmriprep command | |
FMRIPREP_CMD=$(cat << CMD | |
export SINGULARITYENV_FS_LICENSE=${HOME}/.freesurfer.txt | |
singularity run --cleanenv -B ${DATASET_DIR}:/WORK -B ${HOME}/.cache/templateflow:/templateflow -B /etc/pki:/etc/pki/ \ | |
${SING_IMG} \ | |
-w /WORK/fmriprep_work \ | |
--output-spaces MNI152NLin2009cAsym MNI152NLin6Asym \ | |
--notrack --write-graph --resource-monitor \ | |
--omp-nthreads 1 --nprocs 1 --mem_mb 65536 \ | |
--fs-license-file /WORK/freesurfer.txt \ | |
--participant-label ${participant_id} --random-seed 0 --skull-strip-fixed-seed \ | |
/WORK/${DATASET}_openfmri /WORK/derivatives participant & # create detached session | |
CMD | |
) | |
# send to a tmux session | |
tmux new -d -s sub-${participant_id} | |
tmux send-keys -t sub-${participant_id}.0 "$FMRIPREP_CMD" ENTER | |
done | |
# quick check of console output | |
# tmux capture-pane -S -100 -pt sub-001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment