SPI connectivity-analysis pipeline for fMRI group comparisons
Project description
brain-spi
Comparison of pairwise statistics for fMRI connectivity estimation, and a pipeline for finding group differences across them.
brain_spi wraps the SPI connectivity-analysis workflow into a small, importable
library. It lets you run the full pipeline in one call and then inspect either the
aggregated cross-SPI result or any individual SPI's intermediate artifacts.
Try it now in Colab (no install, nothing to clone):
What it does
- Connectivity — derive functional network connectivity (FNC) matrices from multivariate fMRI time series using many pairwise statistics (SPIs), via pyspi plus a small custom set.
- Group differences — per SPI, find edges that differ between two groups using a Welch t-test (Bonferroni-corrected) and a Random-Forest importance mask, then intersect them.
- Aggregate — average the per-SPI masks into a consensus matrix: the fraction of SPIs that flag each edge.
- Robustness — subject-resampling (
bootstrap) and label-shuffle permutation nulls. - Plots & caching — heatmaps with network guides, per-SPI triptychs, the aggregate panel; on-disk caching of the (slow) pyspi computations.
Install
I recommend installing brains-spi in a separate python enviroment: brains-spi relies on pyspi, and it relies on numpy < 2, which can conflict with other packages.
pip install -e . # from the repo root
# core deps: numpy, scipy, scikit-learn, matplotlib, pandas, pyyaml, pyspi
Quickstart
import numpy as np
from brain_spi import BrainSPI
# data: (B subjects, T timepoints, C channels/ROIs); labels: (B,) with 2 unique values
pipe = BrainSPI(group_names=('HC', 'patient')) # sensible defaults (9 curated SPIs)
result = pipe.fit(data, labels)
# headline result — cross-SPI aggregate (computed lazily, cached on first access)
result.aggregate.mean_and # (C, C) float: fraction of SPIs flagging each edge
result.aggregate.plot() # one-shot figure
# inspect a single SPI
result['kendalltau'].mean_matrix() # (C, C) mean connectivity across subjects
result['kendalltau'].and_mask # significant-p AND RF-important edges
result['kendalltau'].plot_triptych() # 3-panel: sig-p / RF / AND
# not sure what's available? every result object has a repr + .help()
result.help()
Choosing SPIs
BrainSPI() # default 9-SPI curated set
BrainSPI(spis='spis_all') # the broad pyspi set
BrainSPI(spis='/path/to/my_spis.yaml') # a config file
BrainSPI(spis=['kendalltau', 'spearmanr']) # an explicit list
SPIs are computed one at a time across all subjects, with a progress bar and a
per-SPI wall-time log (enable with logging.basicConfig(level=logging.INFO)), so
it's easy to spot and drop slow ones.
Robustness
boot = result.bootstrap(n=20, frac=0.66) # 20 subject-resampled cross-SPI AND maps
boot.mean # average of the 20 (resampling-smoothed aggregate)
boot.survival_rate() # how often each edge is flagged (reproducibility)
null = result.label_shuffle(n=100) # permutation null
null.p_value(result.aggregate.mean_and) # per-edge permutation p-values (low = significant)
Saving results
The first fit is slow (pyspi dominates); subsequent fits on the same data are
near-instant thanks to the on-disk cache (~/.cache/brain_spi/, override with
BrainSPI(cache_dir=...)). To save a finished result:
result.to_npz('result.npz') # portable — open with plain numpy.load, no package needed
result.to_pickle('result.pkl') # exact object
import brain_spi
result = brain_spi.load_npz('result.npz') # or load_pickle(...)
The .npz is a flat collection of arrays with a self-describing README key inside.
Example notebook
examples/colab_quickstart.ipynb
runs end-to-end on public data — ABIDE (controls vs. autism) by default, or COBRE
(schizophrenia) via a one-line switch. Part 1 computes SPIs and inspects their mean
connectivity; Part 2 runs the significant-differences pipeline. Datasets download
automatically via
examples/datasets.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brain_spi-0.1.0.tar.gz.
File metadata
- Download URL: brain_spi-0.1.0.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38758241044f825f3367ff2d3330732e7322e9f962d6e16398fa0df726f14205
|
|
| MD5 |
1a374319a61d1388c33ef072c889426f
|
|
| BLAKE2b-256 |
e5fe5636207c141e3dc98f8bbd7575497a93018f430dbb5835f95386fd8b7808
|
File details
Details for the file brain_spi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: brain_spi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0405b3e1d6a514b921c7d7ca81e66f033780a51902fa53cdc5495c8a8cfe357
|
|
| MD5 |
ec3c8fd518f0dec52b540c94446b900c
|
|
| BLAKE2b-256 |
9e20528e61c18fe61e2ab04370b51504d8a601c0e97c97ab120dc7b33394c5bf
|