skbio.core.tree.TreeNode.root_at_midpoint

TreeNode.root_at_midpoint()[source]

Return a new tree rooted at midpoint of the two tips farthest apart

This method doesn’t preserve the internal node naming or structure, but does keep tip to tip distances correct. Uses unrooted_copy but operates on a full copy of the tree.

Returns:

TreeNode

A tree rooted at its midpoint

LengthError

Midpoint rooting requires length and will raise (indirectly) if evaluated nodes don’t have length.

Raises:

TreeError

If a tip ends up being the mid point

Examples

>>> from skbio.core.tree import TreeNode
>>> tree = TreeNode.from_newick("(((d:1,e:1,(g:1)f:1)c:1)b:1,h:1)a:1;")
>>> print tree.root_at_midpoint()
((d:1.0,e:1.0,(g:1.0)f:1.0)c:0.5,((h:1.0)b:1.0):0.5)root;