Skip to content

consensus_tree

piqtree.consensus_tree(trees, *, min_support=0.5)

Build a consensus tree, defaults to majority-rule consensus tree.

The min_support parameter represents the proportion of trees a clade must appear in to be in the resulting consensus tree.

If min_support is 1.0, computes the strict consensus tree. If min_support is 0.0, computes the extended majority-rule consensus tree.

PARAMETER DESCRIPTION
trees

The trees to form a consensus tree from.

TYPE: Iterable[PhyloNode]

min_support

The minimum support for a clade to appear in the consensus tree, by default 0.5.

TYPE: float DEFAULT: 0.5

RETURNS DESCRIPTION
PhyloNode

The constructed consensus tree.

Source code in src/piqtree/iqtree/_tree.py
def consensus_tree(
    trees: Iterable[PhyloNode],
    *,
    min_support: float = 0.5,
) -> PhyloNode:
    """Build a consensus tree, defaults to majority-rule consensus tree.

    The min_support parameter represents the proportion of trees a clade
    must appear in to be in the resulting consensus tree.

    If min_support is 1.0, computes the strict consensus tree.
    If min_support is 0.0, computes the extended majority-rule consensus tree.

    Parameters
    ----------
    trees : Iterable[PhyloNode]
        The trees to form a consensus tree from.
    min_support : float, optional
        The minimum support for a clade to appear
        in the consensus tree, by default 0.5.

    Returns
    -------
    PhyloNode
        The constructed consensus tree.

    """
    if not 0 <= min_support <= 1:
        msg = f"Only min support values in the range 0 <= value <= 1 are supported, got {min_support}"
        raise ValueError(msg)

    if not _all_same_taxa_set(trees):
        msg = "Trees must be on same taxa set."
        raise ValueError(msg)

    newick_trees = [get_newick(tree) for tree in trees]

    return make_tree(iq_consensus_tree(newick_trees, min_support))

Usage

For usage, see "Construct a consensus tree from a collection of trees".