skbio.tree.TreeNode.unpack_by_func#

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

Unpack internal nodes of a tree that meet certain criteria.

Parameters:
funccallable

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

uncachebool, optional

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

Added in version 0.6.3.

See also

unpack
prune

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(['((c:2,d:3)a:1,(e:1,f:2)b:2);'])
>>> tree.unpack_by_func(lambda x: x.length <= 1)
>>> print(tree)
((e:1.0,f:2.0)b:2.0,c:3.0,d:4.0);

>>> tree = TreeNode.read(['(((a,b)85,(c,d)78)75,(e,(f,g)64)80);'])
>>> tree.assign_supports()
>>> tree.unpack_by_func(lambda x: x.support < 75)
>>> print(tree)
(((a,b)85,(c,d)78)75,(e,f,g)80);