skbio.tree.BPTree.preorder_select#
- BPTree.preorder_select(k)[source]#
Index of the node with a given preorder rank.
- Parameters:
- kint
Preorder rank to look up, from 1 (the root) to the number of nodes.
- Returns:
- int
Index of the node whose preorder rank is
k, or -1 ifkis not a rank of this tree.
Notes
The inverse of
preorder_rank. Returns an integer index into the parentheses bit array, not a node object.preorderyields the nodes in this order.Examples
>>> from skbio.tree import BPTree >>> tree = BPTree.read(["((a,b)c,(d,e)f)r;"]) >>> [tree.name(tree.preorder_select(k)) for k in range(1, len(tree) + 1)] ['r', 'c', 'a', 'b', 'f', 'd', 'e'] >>> tree.preorder_rank(tree.preorder_select(4)) 4 >>> tree.preorder_select(0) -1