Skip to content

Instantly share code, notes, and snippets.

@mgxd
Created February 11, 2018 17:50
Show Gist options
  • Save mgxd/f2d105d3694d42ca9d02239147476d4d to your computer and use it in GitHub Desktop.
Save mgxd/f2d105d3694d42ca9d02239147476d4d to your computer and use it in GitHub Desktop.
submitting mindboggle per subject
submit_mindboggle.sh
-------------------------------------------------------------------
#!/bin/bash
base={{FULL PATH TO DATA}}
# first go to data directory, grab all subjects,
# and assign to an array
pushd $base
subjs=($(ls sub-* -d -1)) # this is set up for BIDS, but you can alter the search pattern
popd
# take the length of the array
# this will be useful for indexing later
len=$(expr ${#subjs[@]} - 1) # len - 1
echo Spawning ${#subjs[@]} sub-jobs.
# this submits a SLURM job array with same size as # of subjects
sbatch --array=0-$len ss_mindboggle.sh $base ${subjs[@]}
-------------------------------------------------------------------------
ss_mindboggle.sh
-------------------------------------------------------------------------
#!/bin/bash
#SBATCH --time=2-00:00:00
#SBATCH --mem=30GB
#SBATCH --cpus-per-task=8
#SBATCH -J mindboggle
base=$1
args=($@)
subjs=(${args[@]:1})
# index slurm array to grab subject
subject=${subjs[${SLURM_ARRAY_TASK_ID}]}
echo Submitted job for: ${subject}
IMG={PATH TO CONTAINER}
# assign individual working directory per subject
scratch=/om/scratch/Wed/mathias/singwork/${subject}
if [ ! -d $scratch ]; then
mkdir -p ${scratch}/jovyan
fi
if [ ! -d ${base}/derivatives ]; then
mkdir -p ${base}/derivatives
fi
# preventive
unset DISPLAY
# an optional step that makes this flexible across BIDS datasets with and without sessions
fullt1path=$(ls {base}/${subject}/*/anat/${subject}*T1w.nii.gz)
t1path=${fullt1path##*${base}}
# save the command to as a string to output in job log
cmd='singularity run -B '${scratch}':/workdir -B '${base}':/data $IMG /data/'${t1path}' --id '$subject' --plugin MultiProc --out /data/derivatives/mindboggle --working /workdir'
echo $'Command :\n'${cmd}
# run the command
${cmd}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment