skbio.tree.TreeNode.get_max_distance#
- TreeNode.get_max_distance(use_length=True)[source]#
Return the maximum path distance between any pair of tips.
This 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
If a node does not have an associated branch length, 0 will be used.
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.
Examples
>>> from skbio import TreeNode >>> tree = TreeNode.read(["((a:1,b:2)c:3,(d:4,e:5)f:6)root;"]) >>> dist, tips = tree.get_max_distance() >>> dist 16.0 >>> [n.name for n in tips] ['e', 'b']