nichecompass.benchmarking.compute_gcs

nichecompass.benchmarking.compute_gcs(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, n_jobs=1, seed=0)

Compute the graph connectivity similarity (GCS). The GCS measures how accurately the latent nearest neighbor graph preserves edges and non-edges from the spatial (ground truth) nearest neighbor graph. A value of ‘1’ indicates perfect graph similarity and a value of ‘0’ indicates no graph connectivity similarity at all.

If a ´batch_key´ is provided, the GCS will be computed on each batch separately, 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´.

  • 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.

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

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

Returns:

gcs: Normalized matrix similarity between the spatial nearest neighbor graph and the latent nearest neighbor graph as measured by one minus the size-normalized Frobenius norm of the element-wise matrix differences.