spared.filtering.filter_by_moran

spared.filtering.filter_by_moran(adata: AnnData, n_keep: int, from_layer: str) AnnData[source]

Filter prediction genes by Moran’s I.

This function filters the genes in adata.var by the Moran’s I statistic. It keeps the n_keep genes with the highest Moran’s I. The Moran’s I values will be selected from adata.var[f'{from_layer}_moran'] which must be already present in the adata. If n_keep <= 0, it means the number of genes is no specified and we proceed to automatically compute it in the following way:

  1. If adata.n_vars > 320 then n_keep = 128.

  2. else, n_keep = 32.

Parameters:
  • adata (ad.AnnData) – The AnnData object to update. Must have adata.var[f'{from_layer}_moran'] column.

  • n_keep (int) – The number of genes to keep. If less than 0 the number of genes to keep is computed automatically.

  • from_layer (str) – Layer for which the Moran’s I was already computed (adata.var[f'{from_layer}_moran']).

Returns:

The updated AnnData object with the filtered genes.

Return type:

ad.AnnData