spiDE
Neighbourhood-dependent differential expression in spatial transcriptomics

spiDE
Neighbourhood-dependent differential expression for spatial transcriptomics, with patients as the replicates, in R and Python.
spiDE finds neighbourhood-dependent differential expression in spatial transcriptomics. Within an index cell type, it asks whether a gene’s expression changes with the local density (the niche) of another cell type, within patients, and whether that dependence differs between two conditions. Patients are the unit of replication throughout: a triplet’s evidence (gene, index type, niche type) is how its niche slope varies between patients, never the number of cells.
This website covers both packages: the R package spiDE (Bioconductor) and the Python package spidepy (on AnnData). They share the method and the documentation, and R vs Python lists how they correspond.
Get started
A walk-through on the bundled toy data, every step in R and in Python: build niches, fit, test and plot the pooled and condition-specific results.
The model
What spiDE computes and why, one step at a time, in plain language and then in formulas.
Designing a study
How many patients and cells to plan for, and what to expect at small sizes.
Validation
How the tests were checked against real-data nulls, and what the error rates are.
Install
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# development version from GitHub (needs SpaNorm >= 1.7.15)
BiocManager::install("BhuvaLab/spiDE")library(spiDE)
data(toySpiDE)
res <- spiDE(toySpiDE, condition = "condition", sigma = 30)
results(res, test = "pooled") # niche-dependent expression, across patients
results(res, test = "condition") # its difference between the conditionsspidepy is not on PyPI yet. The extra index gives a CPU-only build of PyTorch, which it needs through spanormpy:
pip install --extra-index-url https://download.pytorch.org/whl/cpu "spidepy @ git+https://github.com/BhuvaLab/spidepy.git"import spidepy as sp
adata = sp.datasets.toy_spide()
res = sp.spide(adata, condition="condition", sigma=30)
sp.results(res, test="pooled") # niche-dependent expression, across patients
sp.results(res, test="condition") # its difference between the conditionsHow it works
Function names are given for R; spidepy uses the same steps as build_niches(), fit_spide() and test_spide().
- Niches (
buildNiches()): per sample, a Gaussian kernel density of every cell type at every cell. - Fit (
fitSpiDE()): for every index cell type, one negative binomial GLM per gene on the niche densities with an intercept per patient, fitted with SpaNorm’s Newton solver. Each niche coefficient is a within-patient slope. - Test (
testSpiDE()): the pooled test (is the slope non-zero, consistently across patients?) always, and the condition-specific test (does it differ between conditions?) when given a condition.
Project
Links and licence
- Source: BhuvaLab/spiDE (R), BhuvaLab/spidepy (Python)
- Report a bug: spiDE issues, spidepy issues
- Cite:
citation("spiDE")in R; spidepy asks to cite the R package, which defines the method - Licence: GPL (>= 3)