Skip to content

random_tree

piqtree.random_tree(num_taxa, tree_mode, rand_seed=None)

Generate a random phylogenetic tree.

Generates a random tree through IQ-TREE.

PARAMETER DESCRIPTION
num_taxa

The number of taxa per tree.

TYPE: int

tree_mode

How the tree is generated.

TYPE: TreeGenMode

rand_seed

The random seed - None means no seed is used, by default None.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
PhyloNode

A random phylogenetic tree.

Source code in src/piqtree/iqtree/_random_tree.py
def random_tree(
    num_taxa: int,
    tree_mode: TreeGenMode,
    rand_seed: int | None = None,
) -> PhyloNode:
    """Generate a random phylogenetic tree.

    Generates a random tree through IQ-TREE.

    Parameters
    ----------
    num_taxa : int
        The number of taxa per tree.
    tree_mode : TreeGenMode
        How the tree is generated.
    rand_seed : int | None, optional
        The random seed - None means no seed is used, by default None.

    Returns
    -------
    PhyloNode
        A random phylogenetic tree.

    """
    rand_seed = process_rand_seed_nonzero(rand_seed)

    newick = iq_random_tree(num_taxa, tree_mode.name, 1, rand_seed).strip()
    return make_tree(newick)

piqtree.TreeGenMode

Bases: Enum

Setting under which to generate a random tree.

BALANCED = auto() class-attribute instance-attribute

BIRTH_DEATH = auto() class-attribute instance-attribute

CATERPILLAR = auto() class-attribute instance-attribute

STAR_TREE = auto() class-attribute instance-attribute

UNIFORM = auto() class-attribute instance-attribute

YULE_HARDING = auto() class-attribute instance-attribute

Usage

For usage, see "Make a randomly generated phylogenetic tree".