Skip to main content

AnnData-native framework for spatial perturbation inference across sequencing-based and imaging-based platforms.

Project description

SpatialPerturb

SpatialPerturb is an AnnData-native framework for spatial perturbation inference across sequencing-based and imaging-based platforms.

It now ships a benchmark-oriented workflow built around:

  • a stable AnnData schema,
  • fetch -> prepare -> load public dataset lifecycle helpers,
  • intrinsic and neighborhood differential effects with simple and pseudobulk modes,
  • ligand-receptor differential scoring with fixed fallback or custom LR resources,
  • perturbation-program and cross-platform concordance metrics,
  • paper-style figure rendering and report manifests.

Install

pip install SpatialPerturb

For heavier ecosystem interop:

pip install "SpatialPerturb[interop]"

Quick start

import spatialperturb as sp

adata = sp.load_demo_dataset()

intrinsic = sp.intrinsic_de(
    adata,
    perturbation="Lrrk2",
    control="control",
    method="pseudobulk",
    sample_col="sample",
    cell_type="neuron",
    roi="hippocampus",
)

neighbor = sp.neighbor_de(
    adata,
    perturbation="Lrrk2",
    control="control",
    method="pseudobulk",
    sample_col="sample",
    aggregate="pseudobulk",
    cell_type="neuron",
    roi="hippocampus",
)

lr = sp.differential_lr(adata, perturbation="Lrrk2", control="control", lr_network="fallback")
power = sp.power_curve(adata, perturbation="Lrrk2", control="control", method="pseudobulk", sample_col="sample")
programs = sp.derive_perturbation_programs(intrinsic, top_n=10, direction="both")

Public dataset lifecycle

import spatialperturb as sp

sp.available_datasets()

sp.fetch_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache")
sp.prepare_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache")
adata = sp.load_public_dataset("shen_2026_scrnaseq", cache_dir=".spatialperturb-cache")

Registered public tracks:

  • shen_2026_stereoseq -> GSE274447
  • shen_2026_scrnaseq -> GSE274058
  • demo_spatialperturb -> deterministic paired demo data

Notes:

  • shen_2026_scrnaseq supports automatic fetch and preparation from the GEO raw archive.
  • shen_2026_stereoseq supports automatic fetch and extraction, but final preparation still requires a preconverted .h5ad or tabular export from the raw GEF files.

Paper-grade benchmark workflow

import spatialperturb as sp

results = sp.run_core_benchmark(
    "demo_spatialperturb",
    config={
        "cache_dir": ".spatialperturb-cache",
        "reference_dataset": "demo_spatialperturb",
        "method": "pseudobulk",
        "sample_col": "sample",
        "concordance_level": "both",
    },
    output_dir="reports/demo_spatialperturb",
)

This writes:

  • tidy tables under reports/.../tables/
  • fixed paper figures under reports/.../figures/
  • a machine-readable manifest.json
  • the exact input.h5ad used for the run

CLI

spatialperturb datasets
spatialperturb fetch-dataset shen_2026_scrnaseq
spatialperturb prepare-dataset shen_2026_scrnaseq
spatialperturb run-benchmark demo_spatialperturb --output-dir reports/demo
spatialperturb render-paper-figures demo_spatialperturb --output-dir reports/demo-figs
spatialperturb validate path/to/data.h5ad

Package layout

  • spatialperturb.io: AnnData ingestion helpers.
  • spatialperturb.pp: perturbation assignment and QC.
  • spatialperturb.gr: spatial graph construction and neighbor collection.
  • spatialperturb.tl: intrinsic DE, neighbor DE, ligand-receptor scoring, concordance, and power.
  • spatialperturb.pl: plotting helpers for benchmark figures.
  • spatialperturb.signatures: perturbation program derivation and scoring.
  • spatialperturb.datasets: dataset registry plus public fetch/prepare/load.
  • spatialperturb.benchmarks: benchmark orchestration and report manifests.
  • spatialperturb.reports: fixed paper figure rendering.

Development

python -m pip install --upgrade build pytest twine
python -m build
pytest -q

Citation

Please cite the package if you find it useful. See CITATION.cff.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatialperturb-0.3.0.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spatialperturb-0.3.0-py3-none-any.whl (48.6 kB view details)

Uploaded Python 3

File details

Details for the file spatialperturb-0.3.0.tar.gz.

File metadata

  • Download URL: spatialperturb-0.3.0.tar.gz
  • Upload date:
  • Size: 48.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for spatialperturb-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2a467aa196ede03a85f1a248b2d8f49252c6ffd7a152586d24fc14c15a95523e
MD5 e734e9c9f6133aa0568a42be9d7ce6c7
BLAKE2b-256 568009150596f024f469d4fd4eb6b5d1111b09491fc58278e221a1cb49d5e0e4

See more details on using hashes here.

File details

Details for the file spatialperturb-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: spatialperturb-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 48.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for spatialperturb-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96fbfd08478d0b1c70fb04ffb8ecf35d9f7cc13632d670670eeecd071cf06b4e
MD5 d953cca801eb4fb773db48e88547a95a
BLAKE2b-256 dafeeb0b58f436b62b6995ee9f99b39ae8f0c84e79f4a9c5f10bafc0ea104706

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page