skbio.tree.TreeNode.path#

TreeNode.path(other, include_ends=False)[source]#

Return the list of nodes in the path from self to another node.

Parameters:
otherTreeNode

Final node of path.

include_ends: bool, optional

Whether to include the initial (self) and final (other) nodes in the list. Default is False.

Returns:
list

List of TreeNode objects.

See also

distance

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b)c,(d,e)f)root;"])
>>> print(tree.ascii_art())
                    /-a
          /c-------|
         |          \-b
-root----|
         |          /-d
          \f-------|
                    \-e
>>> node_1, node_2 = tree.find('a'), tree.find('d')
>>> path = node_1.path(node_2)
>>> print(len(path))
3
>>> print('-'.join(x.name for x in path))
c-root-f
>>> path_2 = node_1.path(node_2, include_ends=True)
>>> print(len(path_2))
5
>>> print('-'.join(x.name for x in path_2))
a-c-root-f-d