skbio.tree.TreeNode.ancestors#
- TreeNode.ancestors(include_self=False)[source]#
Return all ancestral nodes from self back to the root.
- Returns:
- list of TreeNode
The path, toward the root, from self.
- include_selfbool, optional
Whether to include the initial node in the path (default: False).
Examples
>>> from skbio import TreeNode >>> tree = TreeNode.read(["((a,b)c,(d,e)f)g;"]) >>> print(tree.ascii_art()) /-a /c-------| | \-b -g-------| | /-d \f-------| \-e >>> tip = tree.find('a') >>> [node.name for node in tip.ancestors()] ['c', 'g'] >>> [node.name for node in tip.ancestors(include_self=True)] ['a', 'c', 'g']