get_distance#

biotite.sequence.phylo.get_distance(tree: DiGraph, node1: Any, node2: Any, topological: bool = False) → float[source]#

Get the distance between two nodes in a tree.

The distance is the sum of all edge distances from each of the two nodes to their lowest common ancestor.

Parameters:
treeDiGraph

The tree.

node1, node2hashable

The two nodes to calculate the distance for.

topologicalbool, optional

If true, the topological distance is measured, i.e. each edge has a distance of 1. Otherwise, the "distance" attribute of the edges is used.

Returns:
distancefloat

The distance between the nodes.

Raises:
ValueError

If the nodes have no common ancestor, i.e. they are not part of the same tree.

Examples

>>> tree = from_newick("((0:5.0,1:7.0):3.0,2:10.0);")
>>> print(get_distance(tree, 0, 1))
12.0
>>> print(get_distance(tree, 0, 2))
18.0
>>> print(get_distance(tree, 0, 2, topological=True))
3.0