BIDS Neuroimaging Pipeline Guide: Reproducible MRI, fMRI & PET Analysis in Python
End-to-end engineering tutorial for downloading, validating, preprocessing, and modeling OpenNeuro BIDS datasets.
The Brain Imaging Data Structure (BIDS) has transformed neuroimaging from bespoke laboratory folder trees into an interoperable software ecosystem. This technical tutorial walks through the complete workflow for querying OpenNeuro datasets, understanding BIDS raw vs. derivatives hierarchies, running containerized quality control (MRIQC) and preprocessing (fMRIPrep), and extracting functional connectivity matrices with Nilearn.
1. Anatomy of a BIDS Dataset: Raw vs. Derivatives & JSON Sidecars
- Never overwrite raw BIDS files; store all preprocessed outputs under derivatives/<pipeline-name>/.
- Inspect RepetitionTime (TR), PhaseEncodingDirection, and SliceTiming in the JSON sidecars before preprocessing.
- Use DataLad or openneuro-py to fetch specific modalities without downloading terabytes of unused runs.
2. Motion Denoising & Functional Connectome Extraction with Nilearn
Python Example: Extracting Parcellated Functional Connectivity Matrix with Nilearn
Standard Python template ready for integration into local Jupyter notebooks or automated pipelines.
from nilearn import datasets
from nilearn.maskers import NiftiLabelsMasker
from nilearn.connectome import ConnectivityMeasure
import pandas as pd
# 1. Fetch Harvard-Oxford or Schaefer cortical parcellation atlas
atlas = datasets.fetch_atlas_harvard_oxford("cort-maxprob-thr25-2mm")
masker = NiftiLabelsMasker(labels_img=atlas.maps, standardize="zscore_sample", low_pass=0.1, high_pass=0.01, t_r=2.0)
# 2. Load fMRIPrep motion & physiological confounds
confounds_df = pd.read_csv("sub-01_task-rest_desc-confounds_timeseries.tsv", sep="\t")
confound_cols = ["trans_x", "trans_y", "trans_z", "rot_x", "rot_y", "rot_z", "csf", "white_matter"]
clean_confounds = confounds_df[confound_cols].fillna(0).values
# 3. Extract denoised ROI time series and compute Pearson correlation matrix
time_series = masker.fit_transform("sub-01_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz", confounds=clean_confounds)
correlation_measure = ConnectivityMeasure(kind="correlation")
connectome_matrix = correlation_measure.fit_transform([time_series])[0]
print("Functional Connectome Shape:", connectome_matrix.shape)Research Governance & Reproducibility Checklist
- Run bids-validator prior to launching preprocessing containers.
- Report mean Framewise Displacement (FD) per group and exclude subjects with mean FD > 0.5 mm.
- Use zscore_sample standardization in Nilearn to prevent variance leakage.
Key Biomarkers & Standards Referenced in This Guide
Community ISO-aligned standard for organizing and describing neuroimaging (MRI, fMRI, dMRI, PET) and neurophysiological (EEG, MEG, iEEG) datasets.
Non-invasive neuroimaging modality measuring blood-oxygen-level-dependent (BOLD) hemodynamic signals to map brain network activity and functional connectivity.
Molecular neuroimaging technique using radiolabeled tracers to quantify in vivo protein pathology (amyloid plaques, tau tangles), glucose metabolism, or synaptic density.
MRI technique measuring anisotropic water diffusion along white matter tracts to quantify axonal integrity, demyelination, and structural connectomes.
High-temporal-resolution recording of postsynaptic cortical electrical potentials and neural oscillations (delta, theta, alpha, beta, gamma bands).
Live Open Datasets & Papers Matching This Guide
OpenNeuro ds004504: Multimodal MRI & PET Repository for Early Alzheimer’s Disease and Mild Cognitive Impairment (BIDS)
An exceptional multimodal neuroimaging repository providing 3T structural MRI, resting-state fMRI, and [18F]Florbetapir Amyloid-PET scans from 180 subjects formatted strictly to BIDS standard. This open dataset serves as a benchmark resource for deep learning and diagnostic biomarker discovery in early Alzheimer's and MCI.
OpenNeuro ds003505: Dopaminergic Striato-Cortical Circuit Connectivity in Parkinson’s Disease during Motor Execution
This open-access 3T fMRI dataset evaluates striato-cortical circuit connectivity across 72 Parkinsonian patients and controls under levodopa ON vs. OFF states. Complete with behavioral logs, it offers foundational data for modeling dopaminergic network dynamics in motor execution.
OpenNeuro ds008898: sample dataset for odor- and speech-evoked fMRI experiment at 7 Tesla
BIDS neuroimaging dataset containing MRI scans from 1 Subjects. Freely available for computational neuroscience.
Aligning transformer circuit mechanisms to neural representations in relational reasoning
Relational reasoning, the capacity to understand how elements relate to one another, is a defining feature of human intelligence, yet its computational basis remains unclear. Here, we combined human neuroimaging (7T fMRI) with artificial neural network modeling to identify circuit-level analogues of...
Differential task-related fMRI effects of a single dose of guanfacine and lisdexamfetamine in youth with ADHD: a randomised, double-blind, placebo-controlled crossover study
BackgroundStimulant and non-stimulant medications increase fronto-striato-thalamic activation in youth with Attention-Deficit/Hyperactivity Disorder (ADHD). However, comparative effects of the more recently licensed stimulant lisdexamfetamine and non-stimulant guanfacine on functional magnetic reson...
A cascade of attentional and default mode network dynamics following the resolution of perceptual ambiguity
The neural mechanisms underlying spontaneous perceptual switches during bistable perception, particularly the dynamic interplay between large-scale brain networks, remain incompletely understood. Here, using functional magnetic resonance imaging (fMRI) in six participants and a bistable kinetic dept...