skbio.tree.TreeNode.accumulate_to_ancestor#

TreeNode.accumulate_to_ancestor(ancestor)[source]#

Calculate the distance between self and an ancestor.

The distance is the sum of branch lengths connecting the current node and the given ancestral node.

Parameters:
ancestorTreeNode

The ancestral node to accumulate distance to.

Returns:
float

The distance between self and ancestor.

Raises:
NoParentError

If the given ancestral node is not an ancestor of self.

NoLengthError

If one of the nodes between self and ancestor (including self) does not have branch length.

See also

distance

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a:1,b:2)c:3,(d:4,e:5)f:6)root;"])
>>> root = tree
>>> tree.find('a').accumulate_to_ancestor(root)
4.0