skbio.tree.TreeNode.get_max_distance#

TreeNode.get_max_distance(use_length=True)[source]#

Return the maximum distance between any pair of tips in the tree.

Changed in version 0.6.3: Renamed from get_max_distance. The old name is kept as an alias.

This measure is also referred to as the diameter of a tree.

Parameters:
use_lengthbool, optional

Whether to return the sum of branch lengths (True, default) or the number of branches (False) connecting each pair of tips.

Added in version 0.6.3.

Returns:
float

The distance between the two most distant tips in the tree.

tuple of (TreeNode, TreeNode)

The two most distant tips in the tree.

Notes

This method identifies the two furthest apart tips in a tree, as measured by the sum of branch lengths (i.e., patristic distance) connecting them. Missing branch lengths will be replaced with 0. When use_length=False, the number of branches connecting two tips will be considered instead.

When a tie is observed among more than one pair of tips, only one pair will be returned. The choice is stable. This often happens when use_length=False.

This method operates on the subtree below the current node.

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a:1,b:2)c:3,(d:4,e:5)f:6)root;"])
>>> dist, tips = tree.maxdist()
>>> dist
16.0
>>> [n.name for n in tips]
['e', 'b']