spanorm_svg

spanorm_svg(
    data,
    backend='auto',
    verbose=True,
    layer=None,
    table_key=None,
    copy=False,
    random_state=0,
)

Model-based spatially variable gene (SVG) calling (R SpaNormSVG).

Uses the stored SpaNorm fit as the full model, fits (or reuses) a nested model without the splines representing biology, and compares them per gene by a likelihood ratio F-test. The statistics are written to var["svg_F"], var["svg_p"] and var["svg_fdr"], the unclamped statistic to var["svg_F_raw"], and the null fit is stored as spanorm_null. When the full fit is polished, the null is polished with the same settings (and the pre-polish null is kept as spanorm_null_unpolished).

Parameters

Name Type Description Default
data An AnnData or SpatialData on which :func:~spanormpy.spanorm has been run, with the raw counts in X or layer. required
backend str "auto", "cpu" or "gpu", used to fit the null model. 'auto'
verbose bool Print progress messages (to stderr, like R’s message). True
layer str | None Counts layer (default X) and, for SpatialData, the table. None
table_key str | None Counts layer (default X) and, for SpatialData, the table. None
copy bool Return a modified copy instead of modifying data in place. False
random_state int Seed of the generator behind the null model’s dispersion subsampling. 0

Returns

Name Type Description
None, or with copy=True a modified copy of the same container type.

Examples

Note

The code below runs when the site is built, on a small pre-fitted subset of HumanDLPFC (301 genes x 4015 spots; spanorm(sample_p=0.05, df_tps=2), spanorm_svg() and spanorm_pca() already applied) that is fitted once per build and loaded as adata. The outputs are those of the code shown.

import spanormpy as sn
# adata: the HumanDLPFC AnnData (raw counts in X, coordinates in obsm["spatial"]),
# already fitted with sn.spanorm(adata, sample_p=0.05, df_tps=2)
sn.spanorm_svg(adata)
adata.var.filter(like="svg_").head()
svg_F svg_p svg_fdr svg_F_raw
RPL22 0.000000 1.000000e+00 1.000000e+00 -19.906521
ENO1 0.000000 1.000000e+00 1.000000e+00 -9.582518
CLSTN1 0.000000 1.000000e+00 1.000000e+00 -16.271926
CAMK2N1 73.282994 5.073335e-60 1.272561e-58 73.282994
RPL11 12.258183 6.591901e-10 3.175903e-09 12.258183