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 Key in
adata.obsmfor the latent-space coordinates, by default"X_pca".- K
int|None Number of neighbors. Defaults to
round(sqrt(n_cells)).- obsp_key
str Key under which to store the weight matrix in
adata.obsp, by default"weights".- exact
bool If
True, use sklearn’s exact neighbor search instead ofpynndescent. Seefind_knn().
- adata
- Return type:
- Returns:
AnnData The input adata modified in-place with
adata.obsp[obsp_key]populated.- Raises:
KeyError – If obsm_key is not present in
adata.obsm.