Skip to content

Commit ad7705d

Browse files
authored
Merge pull request #1379 from mckenziephagen/sbatch
DOC: Update sbatch script to be more detailed for newer users
2 parents 35d2055 + 489c31b commit ad7705d

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mriqc: image quality metrics for quality assessment of MRI
44
|DOI| |Zenodo| |Package| |Pythons| |DevStatus| |License| |Documentation| |CircleCI| |EOSS|
55

66
MRIQC extracts no-reference IQMs (image quality metrics) from
7-
structural (T1w and T2w) and functional MRI (magnetic resonance imaging)
7+
structural (T1w and T2w), functional and diffusion MRI (magnetic resonance imaging)
88
data.
99

1010
MRIQC is an open-source project, developed under the following

docs/source/resources/mriqc.sbatch

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
# NOTE: To use this script, edit lines 17, 26, 40, 55, 56, 58
4+
# labeled TODO with NOTES explaining how.
5+
6+
# Set SBATCH Parameters:
7+
# ------------------------------------------
8+
# NOTE: These should work with Slurm HPC systems,
9+
# but these specific parameters have only been tested on
10+
# Stanford's Sherlock. Some parameters may need to be
11+
# adjusted for other HPCs, specifically --partition.
12+
#SBATCH --job-name mriqc
13+
14+
# NOTE: Each HCP has different partitions for job submissions.
15+
# Check your HCPs documentation for what partitions are available
16+
# to you.
17+
#SBATCH --partition normal #TODO: update for your HPC
18+
19+
# NOTE: The --array parameter allows multiple jobs to be launched at once,
20+
# and is generally recommended to efficiently run several hundred jobs
21+
# simultaneously This should be adjusted to the range for your dataset;
22+
# 1-n%j where n is the number of
23+
# participants and j is the maximum number of concurrent jobs.
24+
# In this example, there are 216 participants, and only 50 run
25+
# at a given time.
26+
#SBATCH --array=1-216%50 #TODO: adjust for your dataset
27+
28+
# NOTE: These parameters request time and resources from the job
29+
# scheduler. These specific parameters should be sufficient for
30+
# most datasets.
31+
#SBATCH --time=1:00:00 #NOTE: likely longer than generally needed
32+
#SBATCH --ntasks 1
33+
#SBATCH --cpus-per-task=16
34+
#SBATCH --mem-per-cpu=4G
35+
36+
# NOTE: These parameters set where log files will be written, and
37+
# where status emails will be sent.
38+
#SBATCH --output log/%x-%A-%a.out
39+
#SBATCH --error log/%x-%A-%a.err
40+
#SBATCH --mail-user=%[email protected] #TODO: update to your email domain
41+
#SBATCH --mail-type=ALL
42+
43+
## More information about these Slurm commands can be found at:
44+
# https://slurm.schedmd.com/sbatch.html
45+
# ------------------------------------------
46+
# Setup variables
47+
# ------------------------------------------
48+
# NOTE: These variables are paths to your data, and where you'd
49+
# like your output to be written. You should replace STUDY
50+
# with the directory one level below the directory where your data
51+
# is stored.
52+
# You should replace `ds0002785` with the name of your BIDS directory
53+
STUDY="/scratch/users/mphagen/mriqc-protocol" #TODO: replace with your path
54+
BIDS_DIR="${STUDY}/ds002785" # TODO: replace with path to your dataset
55+
56+
# NOTE: These variables set the "Apptainer" execution for your
57+
# MRIQC container
58+
MRIQC_VERSION="24.0.2" #TODO: update if using a different version
59+
APPTAINER_CMD="apptainer run -e mriqc_${MRIQC_VERSION}.sif"
60+
61+
OUTPUT_DIR="${BIDS_DIR}/derivatives/mriqc-${MRIQC_VERSION}"
62+
63+
# NOTE: The next two variables are used to extract participant IDs from
64+
# the mandatory participants.tsv. SLURM_ARRAY_TASK_ID is generated by the
65+
#--array parameter, and is determined by each job's order - i.e. the
66+
# first job has the SLURM_ARRAY_TASK_ID=1, the second SLURM_ARRAY_TASK_ID=2.
67+
# It is necessary to add 1 to the SLURM_ARRAY_TASK_ID because of the header
68+
# in participants.tsv.
69+
subject_idx=$(( ${SLURM_ARRAY_TASK_ID} + 1 ))
70+
71+
## NOTE: The first clause in this line selects a row in participants.tsv
72+
# using subject_idx. This is piped to grep to isolate the subject id.
73+
# This regex should work for most subject naming conventions, but
74+
# may need to be modified in some cases.
75+
subject=$( sed -n ${subject_idx}p ${BIDS_DIR}/participants.tsv \
76+
| grep -oP "sub-[A-Za-z0-9_]*" )
77+
78+
echo Subject $subject
79+
80+
# Define the Apptainer command that will be ran, with MRIQC CLI flags
81+
cmd="${APPTAINER_CMD} ${BIDS_DIR} ${OUTPUT_DIR} participant \
82+
--participant-label $subject \
83+
-w $PWD/work/ \
84+
--omp-nthreads 10 --nprocs 12" # For nodes with at least 32GB RAM
85+
86+
# Print useful information to log files
87+
echo Running task ${SLURM_ARRAY_TASK_ID}
88+
echo Commandline: $cmd
89+
90+
# Run the full command defined in cmd
91+
eval $cmd
92+
exitcode=$?
93+
94+
# Print useful information to log files
95+
echo "sub-$subject ${SLURM_ARRAY_TASK_ID} $exitcode" \
96+
>> ${SLURM_ARRAY_JOB_ID}.tsv
97+
echo Finished tasks ${SLURM_ARRAY_TASK_ID} with exit code $exitcode
98+
exit $exitcode

0 commit comments

Comments
 (0)