spared.gene_features.compute_moran

spared.gene_features.compute_moran(adata: AnnData, from_layer: str, hex_geometry: bool) AnnData[source]

Compute Moran’s I statistic for each gene.

Compute average Moran’s I statistic for a collection of slides. Internally cycles over each slide in the adata collection and computes the Moran’s I statistic for each gene. After that, it averages the Moran’s I for each gene across all slides and saves it in adata.var[f'{from_layer}_moran'].The input data for the Moran’s I computation is adata.layers[from_layer].

Parameters:
  • adata (ad.AnnData) – The AnnData object to update. Must have expression values in adata.layers[from_layer].

  • from_layer (str) – The key in adata.layers with the values used to compute Moran’s I.

  • hex_geometry (bool) – Whether the geometry is hexagonal or not. This is used to compute the spatial neighbors before computing Moran’s I. Only True for visium datasets.

Returns:

The updated AnnData object with the average Moran’s I for each gene in adata.var[f'{from_layer}_moran'].

Return type:

ad.AnnData