skbio.tree.TreeNode.find_all#

TreeNode.find_all(name)[source]#

Find all nodes that match a given name.

Parameters:
nameTreeNode or str

The name or node to find. If a TreeNode object is provided, all nodes with the same name will be returned.

Returns:
list of TreeNode

The found nodes.

Raises:
MissingNodeError

If the node to be searched for is not found.

Notes

All internal nodes (including root) and tips with the given name will be returned, with the former placed before the latter in the returned list.

The first call to find_all will cache a node lookup table in the tree on the assumption that additional calls to find_all will be made. See details.

Examples

>>> from skbio.tree import TreeNode
>>> tree = TreeNode.read(["((a,b)c,(d,e)d,(f,g)c);"])
>>> print(tree.ascii_art())
                    /-a
          /c-------|
         |          \-b
         |
         |          /-d
---------|-d-------|
         |          \-e
         |
         |          /-f
          \c-------|
                    \-g
>>> for node in tree.find_all('c'):
...     print(node.name, node.children[0].name, node.children[1].name)
c a b
c f g
>>> for node in tree.find_all('d'):
...     print(node.name, str(node))
d (d,e)d;

d d;