|
1 | 1 | # SpatialPerturb |
2 | 2 |
|
3 | | -Toolkit for combining **Spatial Transcriptomics** with **Perturb-seq** workflows — signatures, label transfer, spatial scoring, and graph/structure analysis. |
| 3 | +SpatialPerturb is an AnnData-native framework for spatial perturbation inference across sequencing-based and imaging-based platforms. |
| 4 | + |
| 5 | +It now ships a benchmark-oriented workflow built around: |
| 6 | + |
| 7 | +- a stable `AnnData` schema, |
| 8 | +- `fetch -> prepare -> load` public dataset lifecycle helpers, |
| 9 | +- intrinsic and neighborhood differential effects with `simple` and `pseudobulk` modes, |
| 10 | +- ligand-receptor differential scoring with fixed fallback or custom LR resources, |
| 11 | +- perturbation-program and cross-platform concordance metrics, |
| 12 | +- paper-style figure rendering and report manifests. |
4 | 13 |
|
5 | 14 | ## Install |
6 | 15 |
|
7 | 16 | ```bash |
8 | 17 | pip install SpatialPerturb |
9 | | -# or with GNN extras: |
10 | | -pip install 'SpatialPerturb[gnn]' |
| 18 | +``` |
| 19 | + |
| 20 | +For heavier ecosystem interop: |
| 21 | + |
| 22 | +```bash |
| 23 | +pip install "SpatialPerturb[interop]" |
11 | 24 | ``` |
12 | 25 |
|
13 | 26 | ## Quick start |
14 | 27 |
|
15 | 28 | ```python |
16 | 29 | import spatialperturb as sp |
17 | 30 |
|
18 | | -print(sp.__version__) |
| 31 | +adata = sp.load_demo_dataset() |
| 32 | + |
| 33 | +intrinsic = sp.intrinsic_de( |
| 34 | + adata, |
| 35 | + perturbation="Lrrk2", |
| 36 | + control="control", |
| 37 | + method="pseudobulk", |
| 38 | + sample_col="sample", |
| 39 | + cell_type="neuron", |
| 40 | + roi="hippocampus", |
| 41 | +) |
| 42 | + |
| 43 | +neighbor = sp.neighbor_de( |
| 44 | + adata, |
| 45 | + perturbation="Lrrk2", |
| 46 | + control="control", |
| 47 | + method="pseudobulk", |
| 48 | + sample_col="sample", |
| 49 | + aggregate="pseudobulk", |
| 50 | + cell_type="neuron", |
| 51 | + roi="hippocampus", |
| 52 | +) |
| 53 | + |
| 54 | +lr = sp.differential_lr(adata, perturbation="Lrrk2", control="control", lr_network="fallback") |
| 55 | +power = sp.power_curve(adata, perturbation="Lrrk2", control="control", method="pseudobulk", sample_col="sample") |
| 56 | +programs = sp.derive_perturbation_programs(intrinsic, top_n=10, direction="both") |
| 57 | +``` |
| 58 | + |
| 59 | +## Public dataset lifecycle |
| 60 | + |
| 61 | +```python |
| 62 | +import spatialperturb as sp |
| 63 | + |
| 64 | +sp.available_datasets() |
| 65 | + |
| 66 | +sp.fetch_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache") |
| 67 | +sp.prepare_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache") |
| 68 | +adata = sp.load_public_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache") |
19 | 69 | ``` |
20 | 70 |
|
21 | | -CLI: |
| 71 | +Registered public tracks: |
| 72 | + |
| 73 | +- `shen_2026_stereoseq` -> `GSE274447` |
| 74 | +- `shen_2026_scrnaseq` -> `GSE274058` |
| 75 | +- `demo_spatialperturb` -> deterministic paired demo data |
| 76 | + |
| 77 | +Notes: |
| 78 | + |
| 79 | +- `shen_2026_scrnaseq` supports automatic fetch and preparation from the GEO raw archive. |
| 80 | +- `shen_2026_stereoseq` supports automatic fetch and extraction, but final preparation still requires a preconverted `.h5ad` or tabular export from the raw GEF files. |
| 81 | + |
| 82 | +## Paper-grade benchmark workflow |
| 83 | + |
| 84 | +```python |
| 85 | +import spatialperturb as sp |
| 86 | + |
| 87 | +results = sp.run_core_benchmark( |
| 88 | + "demo_spatialperturb", |
| 89 | + config={ |
| 90 | + "cache_dir": ".spatialperturb-cache", |
| 91 | + "reference_dataset": "demo_spatialperturb", |
| 92 | + "method": "pseudobulk", |
| 93 | + "sample_col": "sample", |
| 94 | + "concordance_level": "both", |
| 95 | + }, |
| 96 | + output_dir="reports/demo_spatialperturb", |
| 97 | +) |
| 98 | +``` |
| 99 | + |
| 100 | +This writes: |
| 101 | + |
| 102 | +- tidy tables under `reports/.../tables/` |
| 103 | +- fixed paper figures under `reports/.../figures/` |
| 104 | +- a machine-readable `manifest.json` |
| 105 | +- the exact `input.h5ad` used for the run |
| 106 | + |
| 107 | +## CLI |
| 108 | + |
22 | 109 | ```bash |
23 | | -SpatialPerturb version |
| 110 | +spatialperturb datasets |
| 111 | +spatialperturb fetch-dataset shen_2026_scrnaseq |
| 112 | +spatialperturb prepare-dataset shen_2026_scrnaseq |
| 113 | +spatialperturb run-benchmark demo_spatialperturb --output-dir reports/demo |
| 114 | +spatialperturb render-paper-figures demo_spatialperturb --output-dir reports/demo-figs |
| 115 | +spatialperturb validate path/to/data.h5ad |
24 | 116 | ``` |
25 | 117 |
|
| 118 | +## Package layout |
| 119 | + |
| 120 | +- `spatialperturb.io`: AnnData ingestion helpers. |
| 121 | +- `spatialperturb.pp`: perturbation assignment and QC. |
| 122 | +- `spatialperturb.gr`: spatial graph construction and neighbor collection. |
| 123 | +- `spatialperturb.tl`: intrinsic DE, neighbor DE, ligand-receptor scoring, concordance, and power. |
| 124 | +- `spatialperturb.pl`: plotting helpers for benchmark figures. |
| 125 | +- `spatialperturb.signatures`: perturbation program derivation and scoring. |
| 126 | +- `spatialperturb.datasets`: dataset registry plus public `fetch/prepare/load`. |
| 127 | +- `spatialperturb.benchmarks`: benchmark orchestration and report manifests. |
| 128 | +- `spatialperturb.reports`: fixed paper figure rendering. |
| 129 | + |
26 | 130 | ## Development |
27 | 131 |
|
28 | 132 | ```bash |
29 | | -python -m pip install --upgrade build twine |
| 133 | +python -m pip install --upgrade build pytest twine |
30 | 134 | python -m build |
31 | | -twine upload --repository testpypi dist/* |
| 135 | +pytest -q |
32 | 136 | ``` |
33 | 137 |
|
34 | 138 | ## Citation |
|
0 commit comments