scviva.tools.vision.compute_knn_weights_from_tree_lca#
- scviva.tools.vision.compute_knn_weights_from_tree_lca(newick, obs_names=None, min_size=20)[source]#
Build LCA-based uniform KNN weights from a phylogenetic tree.
For each cell, walks up the tree until the smallest enclosing clade contains at least min_size other cells. That clade’s members become the cell’s neighbors with equal weight (row-normalised to 1). This is the
lcaKNN=TRUEmode in R VISION’s PhyloVision.Note: R VISION’s LCA weight matrix has an encoding inversion bug (it passes membership indicators as distances, giving higher weight to non-clade cells). This implementation uses the correct semantics: uniform weights within the clade, zero outside.
- Parameters:
- newick
str Newick-format tree string. All leaf labels must be cell barcodes.
- obs_names
Sequence[str] |None Desired row/column order. If provided, the matrix is reordered/subset to this order. If
None, tree leaf order is used.- min_size
int Minimum number of neighbors (excluding self) required before a clade is accepted. Default 20, matching R VISION’s
minSizedefault.
- newick
- Return type:
- Returns:
scipy.sparse.csr_matrix of shape (n_cells, n_cells) Row-normalised sparse weight matrix.
- Raises:
ValueError – If any name in obs_names is not found among the tree’s leaves.