skbio.tree.TreeNode.path#

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

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

Parameters:
otherTreeNode

Final node of path.

include_ends: bool, optional

Whether to include the initial and final nodes in the list. Default is False.

Returns:
list

List of TreeNode objects.

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b)c,(d,e)f)root;"])
>>> 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