scviva.tools.vision.compute_knn_weights_from_tree#
- scviva.tools.vision.compute_knn_weights_from_tree(newick, obs_names=None, K=None)[source]#
Build exponential-kernel KNN weights from a phylogenetic tree.
Mirrors
compute_knn_weights()but uses cophenetic (patristic) distances between tree leaves instead of Euclidean latent-space distances. This is the core of PhyloVision: the same Gaussian kernel and row normalisation are applied, so all downstream autocorrelation and differential analyses run unchanged.- 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 to match and leaves absent from obs_names are dropped. If
None, tree leaf order is used.- K
int|None Number of neighbors. Defaults to
round(sqrt(n_cells)).
- newick
- Return type:
- Returns:
scipy.sparse.csr_matrix of shape (n_cells, n_cells) Row-normalised sparse weight matrix in obs_names order.
- Raises:
ValueError – If any name in obs_names is not found among the tree’s leaves.