cassiopeia.sim.SupercellularSampler#

class cassiopeia.sim.SupercellularSampler(ratio=None, number_of_merges=None)[source]#

Methods

subsample_leaves(tree, collapse_source=None, collapse_duplicates=True)[source]#

Construct a new CassiopeiaTree by merging leaves.

Pairs of leaves in the given tree is iteratively merged until a stopping condition is met (specified by ratio or number_of_merges when initializing the sampler). Pairs of leaves are selected by the following procedure: 1) A random leaf A is selected. 2) Its pair B is randomly selected with probability inversely

proportional to the branch distance from the leaf selected in the previous step.

  1. The pair is merged into a new leaf with name A-B and character states merged in to ambiguous states. The new leaf is connected to the LCA of the two leaves and at time max(time of LCA, mean time of the two leaves).

Parameters:
tree CassiopeiaTree

The CassiopeiaTree for which to subsample leaves

collapse_source str | NoneOptional[str] (default: None)

The source node from which to collapse unifurcations

collapse_duplicates bool (default: True)

Whether or not to collapse duplicated character states, so that only unique character states are present in each ambiguous state. Defaults to True.

Raises:

LeafSubsamplerError if the number of merges exceeds the number of – leaves in the tree or no merges will be performed.

Return type:

CassiopeiaTree