skbio.tree.BPTree.collapse#

BPTree.collapse()[source]#

Collapse single-child internal nodes.

Every internal node with exactly one child is removed from the tree, and the removed node’s branch length is added to that of its single child so that root-to-tip path lengths are preserved. The root and all tips are always retained, as are internal nodes with two or more children.

Returns:
BPTree

A new tree with all single-child internal nodes removed. Node names and the merged branch lengths are carried over; edge numbers are not retained.

Notes

A new BPTree is returned; the original tree is not modified.