skbio.tree.TreeNode.remove_deleted#

TreeNode.remove_deleted(func, uncache=True)[source]#

Remove nodes of a tree that meet certain criteria.

Changed in version 0.6.3: This method was renamed from remove_deleted.

Parameters:
funccallable

A function that accepts a TreeNode and returns True or False, where True indicates the node is to be deleted.

uncachebool, optional

Whether to clear caches of the tree if present (default: True). See details.

Added in version 0.6.3.

See also

pop
remove

Notes

This method has the potential to drop entire clades. That is, if an internal node is removed, all its descendants are no longer connected to the tree, even if they are not explicitly removed.

This method has the potential to leave single-child internal nodes in the tree, which can be further collapsed by prune().

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["(a,b)c;"])
>>> tree.remove_by_func(lambda x: x.name == 'b')
>>> print(tree)
(a)c;