[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/cpp-lln-lab/bidspm/main.svg)](https://results.pre-commit.ci/latest/github/cpp-lln-lab/bidspm/main)
[![miss hit](https://img.shields.io/badge/code%20style-miss_hit-000000.svg)](https://misshit.org/)
[![Documentation Status: main](https://readthedocs.org/projects/bidspm/badge/?version=stable)](https://bidspm.readthedocs.io/en/stable/?badge=stable)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/cpp-lln-lab/bidspm/main)
[![tests matlab](https://github.com/cpp-lln-lab/bidspm/actions/workflows/tests.yml/badge.svg)](https://github.com/cpp-lln-lab/bidspm/actions/workflows/tests.yml)
[![tests octave](https://github.com/cpp-lln-lab/bidspm/actions/workflows/tests_octave.yml/badge.svg)](https://github.com/cpp-lln-lab/bidspm/actions/workflows/tests_octave.yml)
[![codecov](https://codecov.io/gh/cpp-lln-lab/bidspm/branch/main/graph/badge.svg?token=PMQYH0DIPX)](https://codecov.io/gh/cpp-lln-lab/bidspm)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3554331.svg)](https://doi.org/10.5281/zenodo.3554331)
[![GitHub last commit](https://img.shields.io/github/last-commit/cpp-lln-lab/bidspm)](https://github.com/cpp-lln-lab/bidspm.git)
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](https://github.com/cpp-lln-lab/bidspm#contributors)
# bidspm
This is a Matlab / Octave toolbox to perform MRI data analysis on a
[BIDS data set](https://bids.neuroimaging.io/) using SPM12.
## Installation
### From docker hub
```bash
docker pull cpplab/bidspm:latest
```
### From the source
In a terminal or a git bash prompt, type:
```bash
git clone --recurse-submodules https://github.com/cpp-lln-lab/bidspm.git
```
To get the latest version that is on the `dev` branch.
```bash
git clone --recurse-submodules --branch dev https://github.com/cpp-lln-lab/bidspm.git
```
To start using bidspm, you just need to initialize it for this MATLAB / Octave session with:
```matlab
bidspm()
```
Please see our
[documentation](https://bidspm.readthedocs.io/en/latest/installation.html) for
more info.
### Installing the Command line Interface (CLI)
If you want to use the BIDS app python based CLI of bidspm.
You need to
- [python3](https://www.python.org/downloads/)
- pip
If you are using MATLAB, you need to edit the file `src/matlab.py`,
so that it returns the fullpath to the MATLAB executable on your computer.
You can then install the bidspm CLI from within the `bidspm` folder with:
```bash
pip install .
```
You can then type the following to see which command you have access to:
```bash
bidspm --help
```
### BIDS validation
After installing bidspm python package, you can get access to extra validation options.
### BIDS stats model validation
Please see [the documentation](https://bidspm.readthedocs.io/en/latest/bids_stats_model.html#using-the-bids-stats-model-python-package)
### BIDS dataset validation
To run the bids-validator when running bidspm, you
will need:
- [node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
- the bidspm python CLI (see above)
You can then install:
- the bids validator
by running from the command line in the root folder of the repository:
```bash
make install
```
or
```bash
npm install -g bids-validator
```
## Usage
For some of its functionality bidspm has a BIDS app like API.
See
[this page for more information](https://bidspm.readthedocs.io/en/latest/usage_notes.html).
But in brief they are of the form:
```matlab
bidspm(bids_dir, output_dir, ...
'analysis_level', ...
'action', 'what_to_do')
```
### Creating a default BIDS statistical model
Use a MATLAB / Octave script with:
```matlab
% path to your raw BIDS dataset
bids_dir = path_of_raw_bids_dataset;
% where you want to save the model
output_dir = path_where_the_output_should_go;
tasks_to_include_in_model = {'task1', 'task2', 'task3'};
% for example 'MNI152NLin2009cAsym'
space_to_include_in_model = {'spaceName'};
bidspm(bids_dir, output_dir, 'dataset', ...
'action', 'default_model', ...
'task', tasks_to_include_in_model, ...
'space', space_to_include_in_model)
```
### GLM
Use a MATLAB / Octave script with:
```matlab
% path to your raw BIDS dataset
bids_dir = path_of_raw_bids_dataset;
% where you want to save the model
output_dir = path_where_the_output_should_go;
preproc_dir = path_to_preprocessed_dataset; % for example fmriprep output
model_file = path_to_bids_stats_model_json_file;
subject_label = '01';
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {subject_label}, ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
'model_file', model_file)
```
### Preprocessing
```matlab
bids_dir = path_to_raw_bids_dataset;
output_dir = path_to_where_the_output_should_go;
subject_label = '01';
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {subject_label}, ...
'action', 'preprocess', ...
'task', {'yourTask'})
```
## Features
### Statistics
The model specification are set up using the
[BIDS stats model](https://bids-standard.github.io/stats-models/) and can be
used to perform:
- whole GLM at the subject level
- whole brain GLM at the group level à la SPM (meaning using a summary
statistics approach).
- ROI based GLM (using marsbar)
- model selection (with the MACS toolbox)
### Preprocessing
If your data is fairly "typical" (for example whole brain coverage functional
data with one associated anatomical scan for each subject), you might be better
off running [fmriprep](https://fmriprep.org/en/stable/) on your data.
If you have more exotic data that cannot be handled well by fmriprep then bidspm
has some automated workflows to perform amongst other things:
- remove dummies
- slice timing correction
- spatial preprocessing:
- realignment OR realignm and unwarp
- coregistration `func` to `anat`,
- `anat` segmentation and skull stripping
- (optional) normalization to SPM's MNI space
- smoothing
- fieldmaps processing and voxel displacement map creation (work in progress)
All (well almost all) preprocessed outputs are saved as BIDS derivatives with
BIDS compliant filenames.
### Quality control:
- anatomical data (work in progress)
- functional data (work in progress)
- GLM auto-correlation check
Please see our
[documentation](https://bidspm.readthedocs.io/en/latest/index.html) for more info.
## Citation
```bibtex
@software{bidspm,
author = {Gau, Rémi and Barilari, Marco and Battal, Ceren and Rezk, Mohamed and Collignon, Olivier and Gurtubay, Ane and Falagiarda, Federica and MacLean, Michèle and Cerpelloni, Filippo and Shahzad, Iqra and Nunes, Márcia and Caron-Guyon, Jeanne and Chouinard-Leclaire, Christine and Yang, Ying and Mattioni, Stefania and Van Audenhaege, Alice and Matuszewski, Jacek},
license = {GPL-3.0},
title = {{bidspm}},
url = {https://github.com/cpp-lln-lab/bidspm},
version = {3.1.0}
}
```
### Posters
- [OHBM 2023](https://doi.org/10.5281/zenodo.8099835)
## Contributors
Thanks goes to these wonderful people
([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the
[all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!