nichecompass.benchmarking.compute_mlami

nichecompass.benchmarking.compute_mlami(adata, batch_key=None, spatial_knng_key='spatial_knng', latent_knng_key='nichecompass_latent_knng', spatial_key='spatial', latent_key='nichecompass_latent', n_neighbors=15, min_res=0.1, max_res=1.0, res_num=3, n_jobs=1, seed=0)

Compute the Maximum Leiden Adjusted Mutual Info (MLAMI). The MLAMI ranges between ‘0’ and ‘1’ with higher values indicating that the latent feature space more accurately preserves global spatial organization from the spatial (ground truth) feature space. To compute the MLAMI, Leiden clusterings with different resolutions are computed for both nearest neighbor graphs. The Adjusted Mutual Info (AMI) between all clustering resolution pairs is computed to quantify cluster overlap and the maximum value is returned as metric for spatial organization preservation.

If a ´batch_key´ is provided, the MLAMI will be computed on each batch separately (with latent Leiden clusters computed on the integrated latent space), and the average across all batches is returned.

If existent, uses precomputed nearest neighbor graphs stored in ´adata.obsp[spatial_knng_key + ‘_connectivities’]´ and ´adata.obsp[latent_knng_key + ‘_connectivities’]´. Alternatively, computes them on the fly using ´spatial_key´, ´latent_key´ and ´n_neighbors´, and stores them in ´adata.obsp[spatial_knng_key + ‘_connectivities’]´ and ´adata.obsp[latent_knng_key + ‘_connectivities’]´ respectively.

Parameters:
  • adata (AnnData) – AnnData object with precomputed nearest neighbor graphs stored in ´adata.obsp[spatial_knng_key + ‘_connectivities’]´ and ´adata.obsp[latent_knng_key + ‘_connectivities’]´ or spatial coordinates stored in ´adata.obsm[spatial_key]´ and the latent representation from a model stored in ´adata.obsm[latent_key]´.

  • batch_key (Optional[str] (default: None)) – Key under which the batches are stored in ´adata.obs´. If ´None´, the adata is assumed to only have one unique batch.

  • spatial_knng_key (str (default: 'spatial_knng')) – Key under which the spatial nearest neighbor graph is / will be stored in ´adata.obsp´ with the suffix ‘_connectivities’.

  • latent_knng_key (str (default: 'nichecompass_latent_knng')) – Key under which the latent nearest neighbor graph is / will be stored in ´adata.obsp´ with the suffix ‘_connectivities’.

  • spatial_key (Optional[str] (default: 'spatial')) – Key under which the spatial coordinates are stored in ´adata.obsm´.

  • latent_key (Optional[str] (default: 'nichecompass_latent')) – Key under which the latent representation from a model is stored in ´adata.obsm´.

  • n_neighbors (Optional[int] (default: 15)) – Number of neighbors used for the construction of the nearest neighbor graphs from the spatial coordinates and the latent representation from a model in case they are constructed.

  • min_res (float (default: 0.1)) – Minimum resolution for Leiden clustering.

  • max_res (float (default: 1.0)) – Maximum resolution for Leiden clustering.

  • res_num (int (default: 3)) – Number of linearly spaced Leiden resolutions between ´min_res´ and ´max_res´ for which Leiden clusterings will be computed.

  • n_jobs (int (default: 1)) – Number of jobs to use for parallelization of neighbor search.

  • seed (int (default: 0)) – Random seed for reproducibility.

Return type:

float

Returns:

mlami: MLAMI between all clustering resolution pairs.