chrysalis.detect_svgs

chrysalis.detect_svgs(adata: AnnData, min_spots: float = 0.05, top_svg: int = 1000, min_morans: float = 0.2, neighbors: int = 6, geary: bool = False)

Calculate spatial autocorrelation (Moran’s I) to define spatially variable genes.

By default we only calculate autocorrelation for genes expressed in at least 5% of capture spots defined with min_spots.

Parameters:
  • adata – The AnnData data matrix of shape n_obs × n_vars. Rows correspond to cells and columns to genes. Spatial data needs to be stored in .obsm[‘spatial’] as X and Y coordinate columns.

  • min_spots – Run calculation only for genes expressed in equal or higher fraction of the total capture spots.

  • top_svg – Cutoff for top ranked spatially variable genes.

  • min_morans – Cutoff using Moran’s I. Specifying this parameter does not disable the cutoff set in top_svg. The ‘min_morans’ cutoff only activates when the cutoff value retains less genes than specified in top_svg.

  • neighbors – Number of nearest neighbours used for calculating Moran’s I.

  • geary – Calculate Geary’s C in addition to Moran’s I. Selected SVGs are not affect by this, stored in .var[“Geary’s C”].

Returns:

Updates .var with the following fields:

  • .var[“Moran’s I”] – Moran’s I value for all genes.

  • .var[“spatially_variable”] – Boolean labels of the examined genes based on the defined cutoffs.

Example usage:

>>> import chrysalis as ch
>>> import scanpy as sc
>>> adata = sc.datasets.visium_sge(sample_id='V1_Human_Lymph_Node')
>>> sc.pp.calculate_qc_metrics(adata, inplace=True)
>>> sc.pp.filter_cells(adata, min_counts=6000)
>>> sc.pp.filter_genes(adata, min_cells=10)
>>> ch.detect_svgs(adata)