10  Tutorial Chapter 4: Resting-state derivatives

Time: ~5-10 minutes after make preprocess finishes. Prereqs: Chapter 1 (setup + download); Chapter 2 (make preprocess done). If you haven’t run preprocessing yet, you can still follow along by pointing at the example LC-study synthetic outputs at examples/lc-study/ (see “Quick demo” below).

This chapter generates the four canonical resting-state derivative maps (ALFF, fALFF, ReHo, seed-FC, atlas-FC) from your preprocessed BOLD. Each is one make command and ~30 seconds per subject.

💡 Why ds000102 for resting-state? It’s a task dataset (Flanker), so we pretend the entire run is rest. Not realistic — we just want to demonstrate the pipeline without downloading another GB of rest data. For real rest analysis, use ds000030 or ds002785.

10.1 1. Locate the preprocessed BOLD

BOLD=$(find data/ds000102/derivatives/fmriprep \
  -name 'sub-08_task-flanker_run-01_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz' \
  | head -1)
echo "BOLD: $BOLD"

If empty, you haven’t run make preprocess yet for sub-08. Go back to Chapter 2 or use the LC-study example below.

10.2 2. Compute ALFF

make alff BOLD="$BOLD" OUT=data/ds000102/derivatives/restingstate/sub-08_alff.nii.gz

Expected output:

Wrote data/ds000102/derivatives/restingstate/sub-08_alff.nii.gz
(mean ALFF in mask: 4.532)

The ALFF map shows per-voxel low-frequency power in the standard 0.01-0.10 Hz band. Higher values = more low-frequency oscillation.

10.3 3. Compute fALFF

make falff BOLD="$BOLD" OUT=data/ds000102/derivatives/restingstate/sub-08_falff.nii.gz

fALFF normalises by total spectral power, making it less sensitive to physiological noise. Values are in [0, 1].

10.4 4. Compute ReHo

make reho BOLD="$BOLD" OUT=data/ds000102/derivatives/restingstate/sub-08_reho.nii.gz

ReHo (Kendall’s W) measures regional homogeneity — how strongly each voxel’s neighbours share its time-course. Useful for detecting spatially coherent signal (e.g., default-mode network nodes).

10.5 5. Compute seed-based FC

Pick a seed voxel — let’s use the PCC (posterior cingulate, a classic default-mode hub). In MNI152NLin2009cAsym, PCC is roughly at voxel coordinates (45, 67, 33) for a 91×109×91 grid. Adjust if your fMRIPrep used a different output space:

make seed-fc BOLD="$BOLD" SEED="45,67,33" \
    OUT=data/ds000102/derivatives/restingstate/sub-08_seed-pcc_fc.nii.gz

The output is a Fisher z-transformed correlation map. Voxels strongly correlated with the PCC should light up in the typical default-mode locations: medial prefrontal, angular gyri, lateral temporal cortex.

10.6 6. Compute atlas-FC matrix

Get a parcellation atlas from Nilearn (Schaefer 100 ROIs):

.venv/bin/python -c "
from nilearn.datasets import fetch_atlas_schaefer_2018
import nibabel as nib
atlas = fetch_atlas_schaefer_2018(n_rois=100)
# Save the atlas image at the same resolution as our BOLD
img = nib.load(atlas.maps)
img.to_filename('data/ds000102/derivatives/atlases/schaefer_100.nii.gz')
print('Saved schaefer_100.nii.gz')
"

Then the FC matrix:

make atlas-fc BOLD="$BOLD" \
    ATLAS=data/ds000102/derivatives/atlases/schaefer_100.nii.gz \
    OUT=data/ds000102/derivatives/restingstate/sub-08_schaefer100_fc.npy \
    REGION_TS_OUT=data/ds000102/derivatives/restingstate/sub-08_schaefer100_ts.tsv

You now have a 100×100 region-by-region FC matrix in NumPy format, plus a TSV of per-region mean time-series for downstream analyses (graph theory, connectome stability, HGNN inputs, etc.).

10.7 7. Quick demo with synthetic data

If you don’t have a fMRIPrep run yet, you can exercise the same pipeline against the LC-study synthetic BIDS:

bash scripts/demo/run_lc_demo.sh    # ~2 seconds on a populated venv

This produces the full QC dashboard + slide deck from synthetic 5-subject BIDS without any external data.

10.8 What you’ve produced

data/ds000102/derivatives/restingstate/
├── sub-08_alff.nii.gz
├── sub-08_falff.nii.gz
├── sub-08_reho.nii.gz
├── sub-08_seed-pcc_fc.nii.gz
├── sub-08_schaefer100_fc.npy        # 100×100 matrix
└── sub-08_schaefer100_ts.tsv         # per-region time-series

These outputs follow the HALFpipe-inspired uniform schema, so any downstream group analysis (Chapter 6) can iterate over subjects and stack results without per-feature special-casing.

Chapter 4 complete. Continue to 05_task_glm.md (pending) for task-GLM analysis on the same data.