scviva.tools.vision.compute_knn_weights_anndata

scviva.tools.vision.compute_knn_weights_anndata#

scviva.tools.vision.compute_knn_weights_anndata(adata, obsm_key='X_pca', K=None, obsp_key='weights', exact=False)[source]#

Compute VISION exponential KNN weights and store in adata.obsp.

Reads the latent space from adata.obsm[obsm_key] and writes the resulting (n_cells, n_cells) sparse weight matrix to adata.obsp[obsp_key]. This replaces the L1-normalised scanpy connectivities previously used by visionpy as a proxy for VISION weights.

Parameters:
  • adata (AnnData) – Annotated data matrix. Must have obsm_key in adata.obsm (e.g. produced by compute_latent_space()).

  • obsm_key (str, optional) – Key in adata.obsm for the latent-space coordinates, by default "X_pca".

  • K (int, optional) – Number of neighbors. Defaults to round(sqrt(n_cells)).

  • obsp_key (str, optional) – Key under which to store the weight matrix in adata.obsp, by default "weights".

  • exact (bool, optional) – If True, use sklearn’s exact neighbor search instead of pynndescent. See find_knn().

Returns:

The input adata modified in-place with adata.obsp[obsp_key] populated.

Return type:

AnnData

Raises:

KeyError – If obsm_key is not present in adata.obsm.