Metadata-Version: 2.4
Name: fmri_qctoolkit
Version: 2.0.2
Summary: MRI Quality Control Dashboard for AFNI and fMRIPrep pipelines
Author-email: Qiuyu Yu <qiuyuyu.psych@gmail.com>
Maintainer-email: Qiuyu Yu <qiuyuyu.psych@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/QiuyuYu3/fMRI-QCtoolkit
Project-URL: Documentation, https://qiuyuyu3.github.io/fMRI-QCtoolkit/
Project-URL: Repository, https://github.com/QiuyuYu3/fMRI-QCtoolkit
Project-URL: Issues, https://github.com/QiuyuYu3/fMRI-QCtoolkit/issues
Project-URL: Changelog, https://github.com/QiuyuYu3/fMRI-QCtoolkit/blob/main/CHANGELOG.md
Keywords: fMRI,quality control,MRIQC,fMRIPrep,AFNI,dashboard
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Dash
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typer>=0.16
Requires-Dist: dash<5,>=2.17
Requires-Dist: dash-ag-grid>=34.3
Requires-Dist: plotly>=5.20
Requires-Dist: pandas>=2.1
Requires-Dist: numpy>=1.26
Requires-Dist: flask>=3.0
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=7; extra == "docs"
Requires-Dist: myst-parser>=3; extra == "docs"
Requires-Dist: furo; extra == "docs"
Dynamic: license-file

# fMRI-QCtoolkit

fMRI-QCtoolkit is a Python package for the quality control (QC) of preprocessed fMRI data. It combines your visual ratings of each participant's QC report with the quantitative metrics from [AFNI](https://afni.nimh.nih.gov/) or [MRIQC](https://mriqc.readthedocs.io/en/latest/), and shows both in an interactive dashboard where you filter runs, look at them in a table and in plots, and download the ones you keep. It works with the outputs of [fMRIPrep](https://fmriprep.org/en/stable/) and AFNI's `afni_proc.py`.

**Handbook: <https://qiuyuyu3.github.io/fMRI-QCtoolkit/>**

![workflow](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/workflow.png)

## Install

Python 3.11 or newer is required. Create or activate a virtual environment, then install from PyPI:

```bash
pip install fmri-qctoolkit
```

## Quick start

### 1. Rate

Rate AFNI output in AFNI's APQC report:

```bash
fmriqc rating afni \
    --input-dir /PATH/AFNI_derivatives \
    --subjects "001,002" \
    --task rest \
    --prefix sub-
```

![AFNI rating](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/AFNI_rating.png)

Rate fMRIPrep output in the toolkit's rating page, on top of the fMRIPrep report:

```bash
fmriqc rating fmriprep \
    --input-dir /PATH/fmriprep \
    --subjects "001,002" \
    --output-dir /PATH/ratings
```

![fMRIPrep rating](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/fMRIPrep_rating.png)

### 2. Prepare

Collect the ratings and the metrics into one table, `df_final.csv`. For fMRIPrep, the metrics come from MRIQC's `group_bold.tsv`.

```bash
fmriqc prep afni \
    --input-dir /PATH/AFNI_derivatives \
    --task rest \
    --prefix sub- \
    --output-dir /PATH/QC
```

```bash
fmriqc prep fmriprep \
    --bold-file /PATH/mriqc/group_bold.tsv \
    --rating-dir /PATH/ratings \
    --task rest \
    --output-dir /PATH/QC
```

### 3. View

```bash
fmriqc dashboard fmriprep \
    --data-file /PATH/QC/df_final.csv \
    --task rest
```

For AFNI, use `fmriqc dashboard afni` with the same options. Open the link printed in the terminal. Runs rated bad on any metric are hidden at first; the filters on the left change which runs are shown.

The **Table** tab lists the runs. Select some and download them.

![Table tab](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/dashboard1.png)

The **Plots** tab shows the ratings as heatmaps and the metrics as a lollipop chart.

![Heatmaps](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/dashboard2.png)

![Lollipop chart](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/dashboard3.png)

The **Settings** tab chooses the metrics shown and the thresholds that rate them.

![Settings tab](https://raw.githubusercontent.com/QiuyuYu3/fMRI-QCtoolkit/main/images/dashboard_settings.png)

The screenshots show simulated data.

## On an HPC cluster

Start a remote desktop session on the cluster (such as XDesktop or an Open OnDemand desktop), open a terminal in it, and load Firefox before running the commands above:

```bash
ml Firefox
```

The rating pages open in Firefox. For the dashboard, copy the printed link into Firefox. Module names differ between clusters; `module avail firefox` lists yours. To rate AFNI output, load AFNI as well. More in [Opening the pages](https://qiuyuyu3.github.io/fMRI-QCtoolkit/opening-pages.html).

## Documentation

- [Handbook](https://qiuyuyu3.github.io/fMRI-QCtoolkit/)
- [Training materials](https://github.com/QiuyuYu3/fMRI-QCtoolkit/tree/main/training_materials)
- [Change log](https://github.com/QiuyuYu3/fMRI-QCtoolkit/blob/main/CHANGELOG.md)

## Citation

A paper describing fMRI-QCtoolkit is in preparation. Until then, cite the software with the details in [CITATION.cff](https://github.com/QiuyuYu3/fMRI-QCtoolkit/blob/main/CITATION.cff) ("Cite this repository" on GitHub). The tools and papers to cite along with it are listed in the [handbook](https://qiuyuyu3.github.io/fMRI-QCtoolkit/citation.html).

## License

[Apache License 2.0](https://github.com/QiuyuYu3/fMRI-QCtoolkit/blob/main/LICENSE)
