spatialvi.external.VIVS#

class spatialvi.external.VIVS(adata, spatial_key='spatial', layer=None, n_neighbors=20, n_scales=5)[source]#

Bases: object

VIVS model for identifying spatially variable genes.

VIVS (Variable Importance via Variance Statistics) identifies genes with significant spatial patterns by comparing observed and expected variance under different spatial scales.

Parameters:
  • adata (AnnData) – AnnData object with spatial transcriptomics data.

  • spatial_key (str) – Key in obsm for spatial coordinates.

  • layer (str | None) – Layer in adata to use. If None, uses X.

  • n_neighbors (int) – Number of spatial neighbors to consider.

  • n_scales (int) – Number of spatial scales to analyze.

  • adata (AnnData)

  • spatial_key (str)

  • layer (str | None)

  • n_neighbors (int)

  • n_scales (int)

Examples

>>> import spatialvi
>>> adata = spatialvi.data.synthetic_spatial()
>>> model = VIVS(adata, spatial_key="spatial")
>>> model.fit()
>>> svg = model.get_spatially_variable_genes()
__init__(adata, spatial_key='spatial', layer=None, n_neighbors=20, n_scales=5)[source]#
Parameters:

Methods

__init__(adata[, spatial_key, layer, ...])

fit([n_permutations, batch_size, use_gpu])

Fit the VIVS model.

get_scale_contributions([gene_names])

Get contribution of each scale to gene importance.

get_spatially_variable_genes([n_top, ...])

Get spatially variable genes.

to_adata()

Store results in AnnData object.

fit(n_permutations=100, batch_size=100, use_gpu=False)[source]#

Fit the VIVS model.

Parameters:
  • n_permutations (int) – Number of permutations for null distribution.

  • batch_size (int) – Batch size for processing genes.

  • use_gpu (bool) – Whether to use GPU acceleration.

  • n_permutations (int)

  • batch_size (int)

  • use_gpu (bool)

Return type:

VIVS

Returns:

Self.

get_spatially_variable_genes(n_top=None, fdr_threshold=0.05)[source]#

Get spatially variable genes.

Parameters:
  • n_top (int | None) – Number of top genes to return. If None, returns all genes below FDR threshold.

  • fdr_threshold (float) – FDR threshold for significance.

  • n_top (int | None)

  • fdr_threshold (float)

Return type:

DataFrame

Returns:

DataFrame with gene names, importance scores, and p-values.

get_scale_contributions(gene_names=None)[source]#

Get contribution of each scale to gene importance.

Parameters:
Return type:

DataFrame

Returns:

DataFrame with scale contributions per gene.

to_adata()[source]#

Store results in AnnData object.

Adds the following to adata.var: - ‘vivs_importance’: Importance scores - ‘vivs_pvalue’: P-values - ‘vivs_fdr’: FDR-adjusted p-values

Return type:

None