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 toadata.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_keyinadata.obsm(e.g. produced bycompute_latent_space()).obsm_key (str, optional) – Key in
adata.obsmfor 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 ofpynndescent. Seefind_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.