Skip to content

Commit 3ba8f41

Browse files
committed
enh: minor fixes and added fmriprep.slurm
1 parent 25d7b90 commit 3ba8f41

File tree

6 files changed

+116
-13
lines changed

6 files changed

+116
-13
lines changed

docs/apps/framework.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,46 @@ For instance, *MRIQC* generates group-level reports with the following command-l
8181
$ mriqc /data/bids_root /data/bids_root/derivatives/ group
8282
```
8383

84+
## What are *BIDS Derivatives*?
85+
86+
*NiPreps* generate *derivatives* of the original data, and they fulfill the BIDS specification for the results of Apps that are created for subsequent consumption by other BIDS-Apps.
87+
These derivatives must follow the BIDS Derivatives specification ([draft](https://bids-specification.readthedocs.io/en/derivatives/)).
88+
An example of BIDS Derivatives filesystem tree, generated with *fMRIPrep* 1.5:
89+
```
90+
derivatives/
91+
├── fmriprep/
92+
│ ├── dataset_description.json
93+
│ ├── logs
94+
│ ├── sub-01.html
95+
│ ├── sub-01/
96+
│ │ ├── anat/
97+
│ │ │ ├── sub-01_desc-brain_mask.nii.gz
98+
│ │ │ ├── sub-01_dseg.nii.gz
99+
│ │ │ ├── sub-01_label-GM_probseg.nii.gz
100+
│ │ │ ├── sub-01_label-WM_probseg.nii.gz
101+
│ │ │ ├── sub-01_label-CSF_probseg.nii.gz
102+
│ │ │ ├── sub-01_desc-preproc_T1w.nii.gz
103+
│ │ │ ├── sub-01_space-MNI152_desc-brain_mask.nii.gz
104+
│ │ │ ├── sub-01_space-MNI152_dseg.nii.gz
105+
│ │ │ ├── sub-01_space-MNI152_label-GM_probseg.nii.gz
106+
│ │ │ ├── sub-01_space-MNI152_label-WM_probseg.nii.gz
107+
│ │ │ ├── sub-01_space-MNI152_label-CSF_probseg.nii.gz
108+
│ │ │ ├── sub-01_space-MNI152_desc-preproc_T1w.nii.gz
109+
│ │ │ ├── sub-01_from-MNI152_to-T1w_mode-image_xfm.h5
110+
│ │ │ ├── sub-01_from-T1w_to-MNI152_mode-image_xfm.h5
111+
│ │ │ └── sub-01_from-orig_to-T1w_mode-image_xfm.txt
112+
│ │ ├── figures/
113+
│ │ └── func/
114+
│ │ ├── sub-01_task-rhymejudgment_space-MNI152_boldref.nii.gz
115+
│ │ ├── sub-01_task-rhymejudgment_space-MNI152_desc-preproc_bold.nii.gz
116+
│ │ ├── sub-01_task-rhymejudgment_space-MNI152_desc-confounds_regressors.nii.gz
117+
│ │ └── sub-01_task-rhymejudgment_space-MNI152_desc-brain_mask.nii.gz
118+
│ ├── sub-02.html
119+
│ ├── sub-02/
120+
│ ├── sub-03.html
121+
│ └── sub-03/
122+
```
123+
84124
[bids]: https://bids.neuroimaging.io/
85125
[bidsapps_paper]: https://doi.org/10.1371/journal.pcbi.1005209
86126
[Singularity]: https://sylabs.io/singularity/

docs/apps/singularity.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,17 @@ environment and access to *fMRIPrep* resources, using
342342
## Running Singularity on a SLURM system
343343
344344
An example of `sbatch` script to run *fMRIPrep* on a SLURM system[^1] is
345-
given [below](singularity.html#sbatch-slurm). The submission script will
346-
generate one task per subject using a *job array*. Submission is as easy
347-
as:
345+
given below. The submission script will
346+
generate one task per subject using a *job array*.
347+
```Shell
348+
{!assets/fmriprep.slurm!}
349+
```
350+
Submission is then as easy as:
348351
349352
```Shell
350353
$ export STUDY=/path/to/some/folder
351-
$ sbatch --array=1-$(( $( wc -l $STUDY/data/participants.tsv | cut -f1 -d' ' ) - 1 )) sbatch.slurm
354+
$ sbatch --array=1-$(( $( wc -l $STUDY/data/participants.tsv | cut -f1 -d' ' ) - 1 )) fmriprep.slurm
352355
```
353356
357+
354358
[^1]: assuming that *job arrays* and Singularity are available

docs/assets/fmriprep.slurm

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
#
3+
#SBATCH -J fmriprep
4+
#SBATCH --time=48:00:00
5+
#SBATCH -n 1
6+
#SBATCH --cpus-per-task=16
7+
#SBATCH --mem-per-cpu=4G
8+
#SBATCH -p normal,mygroup # Queue names you can submit to
9+
# Outputs ----------------------------------
10+
#SBATCH -o log/%x-%A-%a.out
11+
#SBATCH -e log/%x-%A-%a.err
12+
#SBATCH --mail-user=%[email protected]
13+
#SBATCH --mail-type=ALL
14+
# ------------------------------------------
15+
16+
BIDS_DIR="$STUDY/data"
17+
DERIVS_DIR="derivatives/fmriprep-1.5.0"
18+
LOCAL_FREESURFER_DIR="$STUDY/data/derivatives/freesurfer-6.0.1"
19+
20+
# Prepare some writeable bind-mount points.
21+
TEMPLATEFLOW_HOST_HOME=$HOME/.cache/templateflow
22+
FMRIPREP_HOST_CACHE=$HOME/.cache/fmriprep
23+
mkdir -p ${TEMPLATEFLOW_HOST_HOME}
24+
mkdir -p ${FMRIPREP_HOST_CACHE}
25+
26+
# Prepare derivatives folder
27+
mkdir -p ${BIDS_DIR}/${DERIVS_DIR}
28+
29+
# Make sure FS_LICENSE is defined in the container.
30+
export SINGULARITYENV_FS_LICENSE=$HOME/.freesurfer.txt
31+
32+
# Designate a templateflow bind-mount point
33+
export SINGULARITYENV_TEMPLATEFLOW_HOME="/templateflow"
34+
SINGULARITY_CMD="singularity run --cleanenv -B $BIDS_DIR:/data -B ${TEMPLATEFLOW_HOST_HOME}:${SINGULARITYENV_TEMPLATEFLOW_HOME} -B $L_SCRATCH:/work -B ${LOCAL_FREESURFER_DIR}:/fsdir $STUDY/images/poldracklab_fmriprep_1.5.0.simg"
35+
36+
# Parse the participants.tsv file and extract one subject ID from the line corresponding to this SLURM task.
37+
subject=$( sed -n -E "$((${SLURM_ARRAY_TASK_ID} + 1))s/sub-(\S*)\>.*/\1/gp" ${BIDS_DIR}/participants.tsv )
38+
39+
# Remove IsRunning files from FreeSurfer
40+
find ${LOCAL_FREESURFER_DIR}/sub-$subject/ -name "*IsRunning*" -type f -delete
41+
42+
# Compose the command line
43+
cmd="${SINGULARITY_CMD} /data /data/${DERIVS_DIR} participant --participant-label $subject -w /work/ -vv --omp-nthreads 8 --nthreads 12 --mem_mb 30000 --output-spaces MNI152NLin2009cAsym:res-2 anat fsnative fsaverage5 --use-aroma --fs-subjects-dir /fsdir"
44+
45+
# Setup done, run the command
46+
echo Running task ${SLURM_ARRAY_TASK_ID}
47+
echo Commandline: $cmd
48+
eval $cmd
49+
exitcode=$?
50+
51+
# Output results to a table
52+
echo "sub-$subject ${SLURM_ARRAY_TASK_ID} $exitcode" \
53+
>> ${SLURM_JOB_NAME}.${SLURM_ARRAY_JOB_ID}.tsv
54+
echo Finished tasks ${SLURM_ARRAY_TASK_ID} with exit code $exitcode
55+
exit $exitcode

docs/devs/releases.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
As of January 2020, *fMRIPrep* has adopted a Calendar Versioning scheme, and with it we are attempting to apply more coherent semantic rules to our releases.
2+
As of January 2020, *fMRIPrep* has adopted a [Calendar Versioning](https://calver.org) scheme, and with it we are attempting to apply more coherent semantic rules to our releases.
33

44
!!! warning "Note"
55
This document is a draft for internal and external comment. Any commitments expressed here are proposals, and should not be relied upon at this time.
@@ -16,19 +16,19 @@ Patch releases are considered bug-fix releases. Each minor release triggers the
1616

1717
These releases must satisfy four conditions:
1818

19-
1. Resolving one or more bugs. These mostly include failures of *fMRIPrep* to complete or producing invalid derivatives (e.g., a NIfTI file of all zeroes).
20-
1. Derivatives compatibility. If a subject may be successfully run on 20.0.n, then the imaging derivatives should be identical if rerun with 20.0.(n+1), modulo rounding errors and the effects of nondeterministic algorithms. The changes between successful runs of 20.0.n and 20.0.(n+1) should not be larger than the changes between two successful runs of 20.0.n. Cosmetic changes to reports are acceptable, while differing fields of view or data types in a NIfTI file would not be.
21-
1. API compatibility. Workflow-generating functions, workflow input- and outputnode fields must not change. As an end-user application, this may seem overly strict, but the odds of introducing a bug are much higher in these cases.
22-
1. User interface compatibility. Substantial changes to *fMRIPrep* command line must not happen (e.g., the addition of a new, relevant flag).
19+
1. **Resolving one or more bugs.** These mostly include failures of *fMRIPrep* to complete or producing invalid derivatives (e.g., a NIfTI file of all zeroes).
20+
1. **Derivatives compatibility.** If a subject may be successfully run on 20.0.n, then the imaging derivatives should be identical if rerun with 20.0.(n+1), modulo rounding errors and the effects of nondeterministic algorithms. The changes between successful runs of 20.0.n and 20.0.(n+1) should not be larger than the changes between two successful runs of 20.0.n. Cosmetic changes to reports are acceptable, while differing fields of view or data types in a NIfTI file would not be.
21+
1. **API compatibility.** Workflow-generating functions, workflow input- and outputnode fields must not change. As an end-user application, this may seem overly strict, but the odds of introducing a bug are much higher in these cases.
22+
1. **User interface compatibility.** Substantial changes to *fMRIPrep* command line must not happen (e.g., the addition of a new, relevant flag).
2323

2424
Note that not all bugs can be fixed in a way that satisfies all three of these criteria without significant effort. A developer may determine that the bug will be fixed in the next feature release.
2525

2626
Additional acceptable changes within a minor release series:
2727

28-
1. Improved tests. These often come along with bug fixes, but they can be free-standing improvements to the code base.
29-
1. Improved documentation. Unless the documentation is of a feature that will not be present in a bug-fix release, this is always welcome.
30-
1. Updates to the Dockerfile that improve operation for Docker and/or Singularity users, but do not risk behavior change. A good example is including more templates to reduce the need for network requests. An example of an update to the Dockerfile that forces a minor release increment is a change in the pinned version of any of the dependencies or the base container image.
31-
1. Improvements to the fmriprep-docker wrapper. As long as a command-line invocation that worked for the previous version continues to work and produce the same Docker command, there's little chance of harm.
28+
1. **Improved tests.** These often come along with bug fixes, but they can be free-standing improvements to the code base.
29+
1. **Improved documentation.** Unless the documentation is of a feature that will not be present in a bug-fix release, this is always welcome.
30+
1. **Updates to the Dockerfile** that improve operation for Docker and/or Singularity users, but do not risk behavior change. A good example is including more templates to reduce the need for network requests. An example of an update to the Dockerfile that forces a minor release increment is a change in the pinned version of any of the dependencies or the base container image.
31+
1. **Improvements to the *lightweight wrappers*.** As long as a command-line invocation that worked for the previous version continues to work and produce the same Docker command, there's little chance of harm.
3232

3333
## Mechanics
3434

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ markdown_extensions:
3535
emoji_index: !!python/name:materialx.emoji.twemoji
3636
emoji_generator: !!python/name:materialx.emoji.to_svg
3737
- pymdownx.superfences
38+
- pymdownx.snippets
39+
- markdown_include.include:
40+
base_path: docs
3841

3942
plugins:
4043
- toc-sidebar

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mkdocs
22
mkdocs-material
3+
markdown-include
34
git+https://github.com/Mandy91/mkdocs-toc-sidebar-plugin.git@drop_python_2.7_support

0 commit comments

Comments
 (0)