Deviance or Pearson residuals of the stored technical fit (spanorm_null, created by :func:~spanormpy.spanorm_svg) are computed for the top nsvgs SVGs (see :func:~spanormpy.top_svgs), centred per gene (not scaled), and decomposed.
Parameters
Name
Type
Description
Default
data
An AnnData or SpatialData on which spanorm and spanorm_svg have run.
required
nsvgs
int
Number of SVGs used, number of components, and the SVG FDR threshold.
3000
ncomponents
int
Number of SVGs used, number of components, and the SVG FDR threshold.
3000
svg_fdr
int
Number of SVGs used, number of components, and the SVG FDR threshold.
3000
residuals
str
"deviance" (default) or "pearson".
'deviance'
key_added
str
Scores go to obsm[key_added]; uns[key_added] holds variance (squared standard deviations), percent_var (R percentVar, percent of the variance of the computed components), svgs (the genes used) and the settings; varm[key_added + "_loadings"] holds the rotation (R rotation), zero for genes not used.
'X_spanorm_pca'
svd_solver
str
"exact" (numpy.linalg.svd, R ExactParam) or "randomized" (randomised SVD for large data; approximate; seeded by random_state).
'exact'
n_jobs
int
No effect; accepted for compatibility with R’s BPPARAM.
1
random_state
int
Seed of the randomised SVD (svd_solver="randomized" only).
0
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
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_pca(adata, ncomponents=10)adata.obsm["X_spanorm_pca"].shape