spatialvi.utils.spatial_autocorrelation

spatialvi.utils.spatial_autocorrelation#

spatialvi.utils.spatial_autocorrelation(adata, var_names=None, spatial_key='spatial', n_neighbors=20, method='moran', layer=None)[source]#

Compute spatial autocorrelation for genes.

Parameters:
  • adata (AnnData) – AnnData object.

  • var_names (list[str] | None) – List of genes to compute. If None, computes for all.

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

  • n_neighbors (int) – Number of neighbors for weight matrix.

  • method (str) – Autocorrelation method: “moran” or “geary”.

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

  • adata (AnnData)

  • var_names (list[str] | None)

  • spatial_key (str)

  • n_neighbors (int)

  • method (str)

  • layer (str | None)

Return type:

dict[str, float]

Returns:

Dictionary mapping gene names to autocorrelation values.