phylo2vec.utils.vector.get_node_depth#
- phylo2vec.utils.vector.get_node_depth(vector_or_matrix, node: int) float[source]#
Get the depth of a node in a Phylo2Vec tree.
The depth of a node is the length of the path from the root to that node (i.e., distance from root). This follows the BEAST/ETE convention.
The root has depth 0, and depths increase as you move toward the leaves.
For vectors, topological depth is returned (all branch lengths = 1). For matrices, actual branch lengths are used.
- Parameters:
vector_or_matrix (numpy.ndarray) – Phylo2Vec vector (ndim == 1) or matrix (ndim == 2)
node (int) – A node in the tree (0 to 2*n_leaves - 2)
- Returns:
Depth of the node (distance from root)
- Return type:
float
Examples
>>> import numpy as np >>> from phylo2vec.utils.vector import get_node_depth >>> # Tree: (0,(1,(2,3)4)5)6 >>> v = np.array([0, 1, 2]) >>> get_node_depth(v, 6) # Root has depth 0 0.0 >>> get_node_depth(v, 0) # Leaf 0 is 1 edge from root 1.0