skbio.tree.TreeNode.root_at_midpoint#
- TreeNode.root_at_midpoint(reset=True, branch_attrs=[], root_name=None, inplace=False)[source]#
Reroot the tree at the midpoint of the two tips farthest apart.
- Parameters:
- resetbool, optional
Whether to remove the original root of a rooted tree before performing the rerooting operation. Default is True.
Added in version 0.6.2.
Changed in version 0.7.0: Set the default value to True.
- branch_attrsiterable of str, optional
Attributes of each node that should be considered as attributes of the branch connecting the node to its parent. This is important for the correct rerooting operation. “length” and “support” will be automatically included as they are always branch attributes.
Added in version 0.6.2.
Changed in version 0.7.0: Removed
name
from the default values.- root_namestr or None, optional
Name for the new root node, if it doesn’t have one.
Added in version 0.6.2.
Changed in version 0.7.0: Set the default value to None.
- inplacebool, optional
Whether to reroot the tree in place (True) or to create a rerooted copy of the tree (False, default).
Added in version 0.6.3.
- Returns:
- TreeNode
A tree rooted at its midpoint.
- Raises:
- TreeError
If a tip ends up being the mid point.
- LengthError
Midpoint rooting requires length and will raise (indirectly) if evaluated nodes don’t have length.
See also
Notes
The midpoint rooting (MPR) method was originally described in [1].
Tree caches (see
details
) will not be retained in the returned tree. In in-place mode, they will be cleared prior to rerooting. In copying mode, they will not be copied to the new tree.References
[1]Farris, J. S. (1972). Estimating phylogenetic trees from distance matrices. The American Naturalist, 106(951), 645-668.
Examples
>>> from skbio import TreeNode >>> tree = TreeNode.read(["((a:1,b:1)c:2,(d:3,e:4)f:5,g:1)h;"]) >>> print(tree.ascii_art()) /-a /c-------| | \-b | -h-------| /-d |-f-------| | \-e | \-g
>>> t = tree.root_at_midpoint() >>> print(t) ((d:3.0,e:4.0)f:2.0,((a:1.0,b:1.0)c:2.0,g:1.0)h:3.0); >>> print(t.ascii_art()) /-d /f-------| | \-e ---------| | /-a | /c-------| \h-------| \-b | \-g