opendvp.tl.spatial_autocorrelation

opendvp.tl.spatial_autocorrelation#

spatial_autocorrelation(adata, method='moran', x_y=('x_centroid', 'y_centroid'), k=8, threshold=10.0, island_threshold=0.1)#

Compute spatial autocorrelation statistics (Moran’s I or Geary’s C) for each gene in an AnnData object.

Parameters:
  • adata (anndata.AnnData) – Annotated data matrix where observations are cells and variables are genes.

  • method ({'moran', 'geary'}, default 'moran') – Spatial statistic to compute: ‘moran’ or ‘geary’.

  • x_y (Sequence[str], default ("x_centroid", "y_centroid")) – Names of columns in adata.obs containing spatial coordinates.

  • k (int, default 8) – Number of neighbors for Moran’s I (ignored for Geary’s C).

  • threshold (int or float, default 10.0) – Distance threshold for neighbors for Geary’s C (ignored for Moran’s I).

  • island_threshold (float, default 0.1 (10%)) – If more than this fraction of samples are islands (no neighbors), raises error.

Returns:

Results are added to adata.var in-place.

Return type:

None

Raises:
  • ValueError – If method is not ‘moran’ or ‘geary’.

  • RuntimeError – If too many islands are detected in Geary’s C mode.