omicverse.space.svg#
- omicverse.space.svg(adata, mode='prost', n_svgs=3000, target_sum=500000.0, platform='visium', mt_startwith='MT-', library_key=None, selection='significant', **kwargs)[source]#
Identify spatially variable genes using multiple methods.
This function identifies genes that show significant spatial variation in their expression patterns across the tissue. It supports spatial methods including PROST, Moran’s I, Spateo, SOMDE, and SpatialDE. A clearly marked Pearson-residual non-spatial prefilter is retained for compatibility.
- Parameters:
adata (AnnData) – Spatial AnnData containing expression matrix and coordinates in
adata.obsm['spatial'].mode ({'prost', 'moran', 'spateo', 'somde', 'spatialde', 'pearson_residuals'}, default='prost') – SVG detection backend.
'pearson_residuals'is retained as a non-spatial HVG prefilter for compatibility; it does not use coordinates and must not be interpreted as an SVG significance test. The legacy spelling'pearsonr'is an alias for that prefilter.selection ({'significant', 'top_n'}, default='significant') – For Moran, SOMDE and SpatialDE, select significant genes before applying the count cap. Use top_n explicitly for the legacy ranked prefilter. Multiple libraries retain separate backend tests, q-values and selections; the global mask is the union of their selected candidates.
n_svgs (int, default=3000) – Maximum number of genes to select. Significance-based methods may return fewer when fewer genes pass
qval_threshold.target_sum (float, default=50*1e4) – Target-sum used during normalization.
platform (str, default='visium') – Platform identifier used by PROST preprocessing.
mt_startwith (str, default='MT-') – Mitochondrial gene prefix excluded by default.
library_key (str or None, default=None) – Observation column identifying independent slides for Moran, SOMDE or SpatialDE. Each slide is tested separately, so overlapping coordinate systems cannot create cross-slide edges or pooled tests.
**kwargs – Additional method-specific options. For
somde:k,qval_threshold,retrain_epoch. Forspatialde:qval_threshold,min_total_count,regress_formula,n_jobs,kernel_space,approx_rank,approx_seed,approx_models,show_progress.
- Returns:
AnnData – Updated AnnData with SVG flags in
adata.var['space_variable_features']andadata.var['highly_variable'].Notes –
Moran defaults to the analytical normal approximation (n_perms=None). Explicit positive n_perms enables Squidpy 1.8.3 graph-row permutations. Their minimum p-value is 1/(n_perms+1); choose a budget appropriate for the number of tested genes and the desired FDR threshold.
Autocorrelation statistics and tail conventions follow Squidpy 1.8.3 with n_jobs=1. SVG significance selection additionally requires positive Moran’s I. Constant genes are excluded from the testable family.
Independent libraries retain each backend’s per-library q-values and selections. The global mask is their union; adding another library does not change the first library’s significance results.
PROST mode requires opencv-python package
- Different modes use different statistical approaches:
PROST: Pattern recognition and spatial autocorrelation
pearson_residuals: non-spatial Pearson-residual HVG prefilter
spateo: Wasserstein distance-based spatial variation
somde: SOM-compressed SpatialDE GP test (fast for large datasets)
SOMDE kwargs:
k(cells/node, default 20),qval_threshold(default 0.05),retrain_epoch(extra SOM epochs, default 0)SOMDE stores
adata.var['somde_LLR'],somde_pval,somde_qval,somde_FSVSOMDE requires
somocluandpatsyspatialde: GP-based test directly on single-cell coordinates (no SOM compression), uses bundled NaiveDE + SpatialDE packages from
omicverse/external/SpatialDE kwargs:
qval_threshold(default 0.05),min_total_count(default 3),regress_formula(default'np.log(total_counts)'),n_jobs(default1),kernel_space(optional custom covariance search space),approx_rank(optional Nyström low-rank approximation rank),approx_seed(landmark sampling seed),approx_models(kernel list for approximation, default('SE',)),show_progress(whether to show tqdm progress bars, defaultTrue)SpatialDE stores
adata.var['spatialde_LLR'],spatialde_pval,spatialde_qval,spatialde_FSV,spatialde_lSpatialDE requires
patsyandtqdmMitochondrial genes are excluded by default
Results are normalized and log-transformed
Examples – >>> import scanpy as sc >>> import omicverse as ov >>> # Load spatial data >>> adata = sc.read_visium(…) >>> # Find SVGs using PROST >>> adata = ov.space.svg( … adata, … mode=’prost’, … n_svgs=2000, … platform=’visium’ … ) >>> # Access SVGs >>> svgs = adata.var_names[adata.var[‘space_variable_features’]]