scikit-bio is back in active development! Check out our announcement of revitalization.

skbio.tree.TreeNode.unpack_by_func#

TreeNode.unpack_by_func(func)[source]#

Unpack internal nodes of a tree that meet certain criteria.

Parameters:
funcfunction

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

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);