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

Key in adata.obsm for 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 of pynndescent. See find_knn().

Return type:

AnnData

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.