Running MRIQC

MRIQC is a BIDS-App [BIDSApps], and therefore it inherently understands the BIDS standard [BIDS]. Before moving forward, please make sure to have read and understood NiPreps’s introductory documentation).

Containerized execution with Docker and Singularity/Apptainer

For containerized execution with Docker or Singularity/Apptainer, please follow the documentation on the NiPreps site, which contains tip and troubleshooting guidelines for both Docker, and Singularity or Apptainer. In addition to container-specific guidelines, the documentation also includes specific help for processing DataLad-managed datasets.

TemplateFlow templates inside the container

MRIQC gets its templates from TemplateFlow, which keeps them in $TEMPLATEFLOW_HOME or, when that variable is not set, in $HOME/.cache/templateflow. The container image ships the MNI152NLin2009cAsym files MRIQC uses in /home/mriqc/.cache/templateflow, and leaves TEMPLATEFLOW_HOME unset:

  • Docker runs with HOME=/home/mriqc, so the shipped templates are used.

  • Singularity/Apptainer sets $HOME to your home directory on the host, so TemplateFlow looks in the host’s ~/.cache/templateflow and downloads the templates there on the first run. Because that cache is writable, templates the image does not ship (e.g., Fischer344 for --species rat) can be downloaded as well.

If your compute nodes cannot reach the Internet, either pre-fetch the templates from a node that can (see the NiPreps guidelines on TemplateFlow and Singularity), or point TemplateFlow to the templates in the image:

$ apptainer run --env TEMPLATEFLOW_HOME=/home/mriqc/.cache/templateflow \
      mriqc.sif <mriqc arguments>

The image is read-only under Apptainer, so the second option only covers the templates the image ships, that is, human data. --species rat needs a writable TEMPLATEFLOW_HOME.

The rest of this documentation page applies to both bare-metal and containerized execution modes.

MRIQC can fetch data in DataLad datasets

As of version 22.0.3, MRIQC bundles DataLad, enabling automatic data fetching in DataLad datasets. Employing this feature in containerized environments may lead to somewhat obscure errors (see, for example, nipreps/mriqc#1307). If you intend to use DataLad datasets, please read carefully NiPreps’ help for processing DataLad-managed datasets.

Alternatively, this feature can be disabled by adding --no-datalad-get to the command line. This will separate DataLad management from MRIQC’s operation, which can be an effective way of debugging issues and averting erroneous conditions.

Troubleshooting

If you encounter problems, please check our NiPreps Guidelines for Singularity or Apptainer. Common tips and guidelines that used to be found within MRIQC’s or fMRIPrep’s documentation sites have been relocated in the general NiPreps website.

A BIDS Apps command line interface

MRIQC follows the BIDS Apps standard command line interface:

mriqc bids-root/ output-folder/ participant

That simple command runs MRIQC on all the T1w and BOLD images found under the BIDS-compliant folder bids-root/. The last participant keyword indicates that the first level analysis is run. (i.e. extracting the IQMs from the images retrieved within bids-root/).

To specify one particular subject, the --participant-label argument can be used:

mriqc bids-root/ output-folder/ participant --participant-label S01 S02 S03

That command will run MRIQC only on the subjects indicated: only bids-root/sub-S01, bids-root/sub-S02, and bids-root/sub-S03 will be processed.

The second level (group) is never run automatically. Once the participant level has finished, we generate the group level results (the group level report and the features TSV table) with:

mriqc bids-root/ output-folder/ group

The group level traditionally required the same bids-root/ provided to the participant level. This requirement was dropped starting with _MRIQC_ 26, which only needs the IQM files in output-folder/. Both levels can also be run in one call, with mriqc bids-root/ output-folder/ participant group.

Examples of the generated visual reports are found in The MRIQC Reports.

Warning

MRIQC by default attempts to upload anonymized quality metrics to a publicly accessible web server (mriqc.nimh.nih.gov). The uploaded data consists only of calculated quality metrics and scanning parameters. It removes all personal health information and participant identifiers. We try to collect this data to build normal distributions for improved outlier detection, but if you do not wish to participate you can disable the submission with the --no-sub flag.

Participant-level IQM parquet outputs

Participant-level runs generate a parquet file containing the IQMs for each input image. The file is written in the derivatives output directory (output-folder) using the following layout:

<derivs-folder>/sub-<label>/[ses-<label>/]<anat|func|dwi>/<bids-selectors>_<suffix>+iqms.parquet

Each parquet file contains a single row with IQM values (no metadata). A sidecar JSON is written alongside it to document the schema:

<derivs-folder>/sub-<label>/[ses-<label>/]<anat|func|dwi>/<bids-selectors>_<suffix>+iqms.json

The sidecar includes the column names and types, the MRIQC version used to generate the file, the modality, the BIDS entities and metadata of the input (bids_meta), and the provenance record (provenance).

Before MRIQC 26.0, IQMs, metadata and provenance were written together to <bids-selectors>_<suffix>.json, which is no longer generated.

Schema compatibility policy

The IQM parquet schema is intended to remain stable for all patch releases within a minor MRIQC version (e.g., 26.0.x). New minor versions may add columns, refine types, or introduce new metrics, but column removal or renaming is reserved for major version changes. Downstream consumers should treat the schema as additive across minor releases and use the sidecar metadata to validate expectations and handle unknown or missing columns.

Command line interface

MRIQC 26.2.0.dev2+g587123f34 Automated Quality Control and visual reports for Quality Assessment of structural (T1w, T2w, FLAIR) and functional MRI of the brain.

IMPORTANT: Anonymized quality metrics (IQMs) will be submitted to MRIQC’s metrics repository. Submission of IQMs can be disabled using the --no-sub argument. Please visit https://mriqc.readthedocs.io/en/latest/dsa.html to revise MRIQC’s Data Sharing Agreement.

usage: mriqc [-h] [--version] [-v] [--species {human,rat}]
             [--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
             [--bids-filter-file PATH] [--session-id [SESSION_ID ...]]
             [--run-id [RUN_ID ...]] [--task-id [TASK_ID ...]]
             [-m [{T1w,T2w,bold,dwi,FLAIR} ...]] [--dsname DSNAME]
             [--bids-database-dir PATH] [--bids-database-wipe]
             [--no-datalad-get] [--nprocs NPROCS]
             [--omp-nthreads OMP_NTHREADS] [--mem MEMORY_GB] [--testing] [-f]
             [--pdb] [-w WORK_DIR] [--verbose-reports]
             [--random-seed _RANDOM_SEED] [--reports-only] [--write-graph]
             [--dry-run] [--resource-monitor] [--use-plugin USE_PLUGIN]
             [--crashfile-format {txt,pklz}] [--no-sub] [--email EMAIL]
             [--webapi-url WEBAPI_URL] [--webapi-port WEBAPI_PORT]
             [--upload-strict] [--notrack] [--ants-float]
             [--ants-settings ANTS_SETTINGS] [--min-dwi-length MIN_LEN_DWI]
             [--min-bold-length MIN_LEN_BOLD] [--fft-spikes-detector]
             [--fd_thres FD_THRES] [--deoblique] [--despike]
             [--start-idx START_IDX] [--stop-idx STOP_IDX]
             bids_dir output_dir {participant,group} [{participant,group} ...]

Positional Arguments

bids_dir

The root folder of a BIDS valid dataset (sub-XXXXX folders should be found at the top level in this folder).

output_dir

The directory where the output files should be stored. If you are running group level analysis this folder should be prepopulated with the results of the participant level analysis.

analysis_level

Possible choices: participant, group

Level of the analysis that will be performed. Multiple participant level analyses can be run independently (in parallel) using the same output_dir.

Named Arguments

--version

show program’s version number and exit

-v, --verbose

Increases log verbosity for each occurrence, debug level is -vvv.

--species

Possible choices: human, rat

Use appropriate template for population

Options for filtering BIDS queries

--participant-label, --participant_label, --participant-labels, --participant_labels

A space delimited list of participant identifiers or a single identifier (the sub- prefix can be removed).

--bids-filter-file

a JSON file describing custom BIDS input filter using pybids {<suffix>:{<entity>:<filter>,…},…} (https://github.com/bids-standard/pybids/blob/master/src/bids/layout/config/bids.json)

--session-id

Filter input dataset by session ID.

--run-id

DEPRECATED - This argument will be disabled. Use --bids-filter-file instead.

--task-id

Filter input dataset by task ID.

-m, --modalities

Possible choices: T1w, T2w, bold, dwi, FLAIR

Filter input dataset by MRI type.

--dsname

A dataset name.

--bids-database-dir

Path to an existing PyBIDS database folder, for faster indexing (especially useful for large datasets).

--bids-database-wipe

Wipe out previously existing BIDS indexing caches, forcing re-indexing.

--no-datalad-get

Disable attempting to get remote files in DataLad datasets.

Options to handle performance

--nprocs, --n_procs, --n_cpus, -n-cpus

Maximum number of simultaneously running parallel processes executed by MRIQC (e.g., several instances of ANTs’ registration). However, when --nprocs is greater or equal to the --omp-nthreads option, it also sets the maximum number of threads that simultaneously running processes may aggregate (meaning, with --nprocs 16 --omp-nthreads 8 a maximum of two 8-CPU-threaded processes will be running at a given time). Under this mode of operation, --nprocs sets the maximum number of processors that can be assigned work within an MRIQC job, which includes all the processors used by currently running single- and multi-threaded processes. If None, the number of CPUs available will be automatically assigned (which may not be what you want in, e.g., shared systems like a HPC cluster.

--omp-nthreads, --ants-nthreads

Maximum number of threads that multi-threaded processes executed by MRIQC (e.g., ANTs’ registration) can use. If None, the number of CPUs available will be automatically assigned (which may not be what you want in, e.g., shared systems like a HPC cluster.

--mem, --mem_gb, --mem-gb

Upper bound memory limit for MRIQC processes.

--testing

Use testing settings for a minimal footprint.

-f, --float32

Cast the input data to float32 if it’s represented in higher precision (saves space and improves performance).

--pdb

Open Python debugger (pdb) on exceptions.

Instrumental options

-w, --work-dir

Path where intermediate results should be stored.

--verbose-reports
--random-seed

Seed the random numbers of ANTs registration and of MRIQC, and run Atropos with its constant seed (Atropos takes no seed value). With –omp-nthreads 1, two runs with the same seed give the same results.

--reports-only
--write-graph

Write workflow graph.

--dry-run

Do not run the workflow.

--resource-monitor, --profile

Hook up the resource profiler callback to nipype.

--use-plugin

Nipype plugin configuration file.

--crashfile-format

Possible choices: txt, pklz

Nipype crashfile format

--no-sub

Turn off submission of anonymized quality metrics to MRIQC’s metrics repository.

--email

Email address to include with quality metric submission.

--webapi-url

IP address where the MRIQC WebAPI is listening.

--webapi-port

Port where the MRIQC WebAPI is listening.

--upload-strict

Upload will fail if upload is strict.

--notrack

Opt-out of sending tracking information of this run to the NiPreps developers. This information helps to improve MRIQC and provides an indicator of real world usage crucial for obtaining funding.

Specific settings for ANTs

--ants-float

Use float number precision on ANTs computations.

--ants-settings

Path to JSON file with settings for ANTs.

Diffusion MRI workflow configuration

--min-dwi-length

Drop DWI runs with fewer orientations than this threshold.

Functional MRI workflow configuration

--min-bold-length

Drop BOLD runs with fewer time points than this threshold.

--fft-spikes-detector

Turn on FFT based spike detector (slow).

--fd_thres

Threshold on framewise displacement estimates to detect outliers.

--deoblique

Deoblique the functional scans during head motion correction preprocessing.

--despike

Despike the functional scans during head motion correction preprocessing.

--start-idx

DEPRECATED Initial volume in functional timeseries that should be considered for preprocessing.

--stop-idx

DEPRECATED Final volume in functional timeseries that should be considered for preprocessing.

Running MRIQC on HPC with Singularity/Apptainer

We have profiled cores and memory usages with the resource profiler tool of Nipype.

An MRIQC run of one subject (from the ABIDE) dataset, containing only one run, one BOLD task (resting-state) yielded the following report:

Using the MultiProc plugin of nipype with nprocs=10, the workflow nodes run across the available processors for 41.68 minutes. A memory peak of 8GB is reached by the end of the runtime, when the plotting nodes are fired up.

We also profiled MRIQC on a dataset with 8 tasks (one run per task), on ds030 of OpenfMRI:

Again, we used n_procs=10. The software run for roughly about the same time (47.11 min). Most of the run time, memory usage keeps around a maximum of 10GB. Since we saw a memory consumption of 1-2GB during the the 1-task example, a rule of thumb may be that each task takes around 1GB of memory.

The ABIDE images behind MRIQC’s classifier

MRIQC’s classifier (Esteban et al., 2017, doi:10.1371/journal.pone.0184661) was trained on the T1w images of ABIDE I. Up to version 26.0, MRIQC shipped an abide2bids script that downloaded them from NITRC with NITRC credentials. The same images are available in BIDS, without credentials, from the DataLad dataset ///abide, a mirror of FCP-INDI’s s3://fcp-indi/data/Projects/ABIDE/RawDataBIDS/.

abide-datalad.tsv maps each participant_id, as abide2bids named it (e.g., sub-50137), to its site and to the paths of its T1w image and of its first resting-state BOLD run in ///abide, with their MD5 checksums. To fetch an image:

datalad clone ///abide abide
cd abide
datalad get RawDataBIDS/Olin/sub-0050137/anat/sub-0050137_T1w.nii.gz

datalad get installs the subdatasets it needs along the way. Ten subjects have no T1w image (n/a), and 28 have more than one BOLD run (bold_runs), stored next to the first one.