Skip to content

robinson_foulds

piqtree.robinson_foulds(trees)

Pairwise Robinson-Foulds distance between a sequence of trees.

For the given collection of trees, returns a numpy array containing the pairwise distances between the trees.

PARAMETER DESCRIPTION
trees

The sequence of trees to calculate the pairwise Robinson-Foulds distances of.

TYPE: Sequence[PhyloNode]

RETURNS DESCRIPTION
ndarray

Pairwise Robinson-Foulds distances.

Source code in src/piqtree/iqtree/_robinson_foulds.py
def robinson_foulds(trees: Sequence[PhyloNode]) -> np.ndarray:
    """Pairwise Robinson-Foulds distance between a sequence of trees.

    For the given collection of trees, returns a numpy array containing
    the pairwise distances between the trees.

    Parameters
    ----------
    trees : Sequence[PhyloNode]
        The sequence of trees to calculate the pairwise Robinson-Foulds
        distances of.

    Returns
    -------
    np.ndarray
        Pairwise Robinson-Foulds distances.

    """
    pairwise_distances = np.zeros((len(trees), len(trees)))
    for i in range(1, len(trees)):
        for j in range(i):
            rf = iq_robinson_fould(get_newick(trees[i]), get_newick(trees[j]))
            pairwise_distances[i, j] = rf
            pairwise_distances[j, i] = rf
    return pairwise_distances

Usage

For usage, see "Calculate pairwise Robinson-Foulds distances between trees".