skbio.tree.TreeNode.bifurcate#

TreeNode.bifurcate(insert_length=None, include_self=True, inplace=True, uncache=True)[source]#

Convert the tree into a bifurcating tree.

All nodes that have more than two children will have additional intermediate nodes inserted to ensure that every node has only two children.

Parameters:
insert_lengthint, optional

The branch length assigned to all inserted nodes.

include_selfbool, optional

If False, will not convert the current node. This is useful for keeping an unrooted tree unrooted. Default is True.

Added in version 0.6.3.

inplacebool, optional

Whether to modify the tree in place (True, default) or to create a modified copy of the tree (False).

Added in version 0.7.4.

uncachebool, optional

Whether to clear caches of the tree if present (default: True). See details. Only applicable when inplace is True.

Added in version 0.6.3.

Returns:
TreeNode

The resulting tree.

Changed in version 0.7.4: Now returns the tree. Previously the method returned nothing.

Notes

This method does not modify single-child nodes. These nodes can be collapsed using prune prior to this method to create a strictly bifurcating tree.

This method modifies the subtree under the current node.

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b,g,h)c,(d,e)f)root;"])
>>> print(tree.ascii_art())
                    /-a
                   |
                   |--b
          /c-------|
         |         |--g
         |         |
-root----|          \-h
         |
         |          /-d
          \f-------|
                    \-e
>>> tree = tree.bifurcate()
>>> print(tree.ascii_art())
                    /-h
          /c-------|
         |         |          /-g
         |          \--------|
         |                   |          /-a
-root----|                    \--------|
         |                              \-b
         |
         |          /-d
          \f-------|
                    \-e