skbio.tree.TreeNode.remove_by_func#
- TreeNode.remove_by_func(func, uncache=True)[source]#
Remove nodes of a tree that meet certain criteria.
Changed in version 0.6.3: Renamed from
remove_deleted
. The old name is kept as an alias. But it may be removed in a future version.- 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.
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;