skbio.tree.TreeNode.prune#

TreeNode.prune()[source]#

Reconstruct correct topology after nodes have been removed.

Internal nodes with only one child will be removed and new connections will be made to reflect change. This method is useful to call following node removals as it will clean up nodes with singular children.

Names and properties of singular children will override the names and properties of their parents following the prune.

Node lookup caches are invalidated.

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b)c,(d,e)f)root;"])
>>> to_delete = tree.find('b')
>>> tree.remove_deleted(lambda x: x == to_delete)
>>> print(tree)
((a)c,(d,e)f)root;

>>> tree.prune()
>>> print(tree)
((d,e)f,a)root;