| Title: | Spatial Lag Regression for Spatial Transcriptomics |
|---|---|
| Description: | Tests each gene in spatial transcriptomics data for association between a spot's expression and the expression of its neighbours. For every gene, a quasi-Poisson generalized linear model is fitted with a library-size offset, user-defined design terms from the colData, and the spatial lag of the gene's own normalised counts as an additional covariate. The lag is a row-normalised, inverse-distance weighted mean over spots within a given radius, computed separately for each sample. The coefficient, p-value and adjusted p-value of the lag are stored in the rowData of the input SpatialExperiment. Weights are computed in C++ with RcppArmadillo, and genes are fitted in parallel with BiocParallel. The p-values are intended for exploratory use. Plotting functions and a Shiny explorer are included. |
| Authors: | Sahal Paladan [aut, cre] (ORCID: <https://orcid.org/0009-0005-0120-128X>) |
| Maintainer: | Sahal Paladan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.4 |
| Built: | 2026-11-25 13:11:17 UTC |
| Source: | https://github.com/BiocStaging/spatialLagGLM |
Simulates a 30 x 30 grid of spots and 50 negative binomial genes. Spots
within 7 units of the grid centre are labelled "TumorCore", the
rest "Margin", and Gene1 is up-regulated in the core.
makeMockSpatial()makeMockSpatial()
A SpatialExperiment object with
synthetic counts and coordinates.
se <- makeMockSpatial()se <- makeMockSpatial()
Volcano Plot of Spatial Lag Results
plotLagVolcano(se, alpha = 0.05, effect_cutoff = 0.5)plotLagVolcano(se, alpha = 0.05, effect_cutoff = 0.5)
se |
A |
alpha |
A single number in (0, 1]: adjusted p-value cutoff. |
effect_cutoff |
A single non-negative number: effect size cutoff. |
A ggplot2 object.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotLagVolcano(analyzed)se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotLagVolcano(analyzed)
Plots either the raw counts of a gene or its spatial lag (the weighted mean
of its neighbours' normalised counts, i.e. the covariate used by
spatialLagGLM). With several samples, each is drawn in its
own panel.
plotSpatialLag( se, gene_id, metric = c("expression", "spatial_lag"), assay.type = "counts" )plotSpatialLag( se, gene_id, metric = c("expression", "spatial_lag"), assay.type = "counts" )
se |
A |
gene_id |
A single gene name. |
metric |
|
assay.type |
A string naming the assay with raw counts. |
A ggplot2 object.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotSpatialLag(analyzed, gene_id = "Gene1", metric = "expression") plotSpatialLag(analyzed, gene_id = "Gene1", metric = "spatial_lag")se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) plotSpatialLag(analyzed, gene_id = "Gene1", metric = "expression") plotSpatialLag(analyzed, gene_id = "Gene1", metric = "spatial_lag")
Launch Interactive Spatial Lag Explorer
runSpatialLagExplorer(se)runSpatialLagExplorer(se)
se |
A |
Called for its side effect of starting a Shiny app; returns nothing useful.
if (interactive()) { se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) runSpatialLagExplorer(analyzed) }if (interactive()) { se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) runSpatialLagExplorer(analyzed) }
For every gene, fits a quasi-Poisson regression with a library-size offset,
the terms of design, and the spatial lag of the gene's own
size-factor-normalised counts as an extra covariate. The coefficient of the
spatial lag, its p-value and its Benjamini-Hochberg adjusted p-value are
stored in rowData(se).
spatialLagGLM( se, design, radius = 2.5, assay.type = "counts", size.factors = NULL, BPPARAM = BiocParallel::bpparam() )spatialLagGLM( se, design, radius = 2.5, assay.type = "counts", size.factors = NULL, BPPARAM = BiocParallel::bpparam() )
se |
A |
design |
A formula using variables in |
radius |
A positive number: the distance within which spots are
neighbours, in the units of |
assay.type |
A string naming the assay with raw counts. |
size.factors |
|
BPPARAM |
A |
For spot and a given gene, the model is
where is the size factor (library size divided by its geometric
mean), the row of the design matrix, and
the spatial lag. The weights
are inverse distances between spots within radius,
row-normalised, and are computed separately for each sample_id.
The null hypothesis tested is : given the offset and the
design terms, a spot's expression is not associated with the weighted mean
of its neighbours' normalised expression.
Because the lag is built from the same gene's counts, this is not a spatial autoregressive model, and the quasi-Poisson p-values have not been shown to be calibrated for this test. Treat them as exploratory and, where it matters, check them against a permutation of the spot coordinates.
Genes whose fit fails or does not converge get NA results, and a
warning reports how many.
The results are stored in rowData(se) as spatial_effect_size
(), p_value and adjusted_p_value. The
radius, assay and size factors used are stored in
metadata(se)$spatialLagGLM.
se with spatial_effect_size, p_value and
adjusted_p_value added to rowData.
se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) head(SummarizedExperiment::rowData(analyzed))se <- makeMockSpatial() analyzed <- spatialLagGLM(se, design = ~condition, radius = 2.5) head(SummarizedExperiment::rowData(analyzed))