scviva.tools.harreman.tools.compute_knn_graph#

scviva.tools.harreman.tools.compute_knn_graph(adata, compute_neighbors_on_key=None, distances_obsp_key=None, weighted_graph=False, neighborhood_radius=None, n_neighbors=None, neighborhood_factor=3, sample_key=None, tree=None, use_gpu=None, verbose=False, random_state=0)[source]#

Computes the spatial proximity graph.

Parameters:
adata AnnData

AnnData object.

compute_neighbors_on_key str | None

Key in adata.obsm to use for computing neighbors. If None, use neighbors stored in adata. If no neighbors have been previously computed an error will be raised.

distances_obsp_key str | None

Distances encoding cell-cell similarities directly. Shape is (cells x cells). Input is key in adata.obsp.

weighted_graph bool | None

Whether or not to create a weighted graph.

neighborhood_radius int | None

Neighborhood radius.

n_neighbors int | None

Neighborhood size.

neighborhood_factor int | None

Used when creating a weighted graph. Sets how quickly weights decay relative to distances within the neighborhood. The weight for a cell with distance d decays as exp(-d^2/D), where D is the distance to the n_neighbors/neighborhood_factor-th neighbor.

sample_key str | None

Sample information in case the data contains different samples or samples from different conditions. Input is key in adata.obs.

tree

Root tree node. Can be created using ete3.Tree

use_gpu bool | None

Whether to use GPU acceleration via rapids_singlecell/cuML. None (default) tries GPU and falls back to CPU automatically; False forces CPU; True raises if GPU fails.

verbose bool | None

Whether to print progress and status messages.

random_state int | Generator | None

Seed (or generator) for the random tie-breaking in the tree-based KNN path (used only when tree is given), for reproducible neighbor selection. Defaults to 0.