cassiopeia.sim.UniformLeafSubsampler#

class cassiopeia.sim.UniformLeafSubsampler(ratio=None, number_of_leaves=None)[source]#

Methods

subsample_leaves(tree, keep_singular_root_edge=True)[source]#

Uniformly subsample leaf samples of a given tree.

Generates a uniform random sample on the leaves of the given CassiopeiaTree and returns a tree pruned to contain lineages relevant to only leaves in the sample (the “induced subtree” on the sample). All fields on the original character matrix persist, but maintains character states, meta data, and the dissimilarity map for the sampled cells only.

Has the option to keep the single edge leading from the root in the induced subtree, if it exists. This edge is often used to represent the time that the root lives before any divisions occur in the phyologeny, and is useful in instances where the branch lengths are critical, like simulating ground truth phylogenies or estimating branch lengths.

Parameters:
tree CassiopeiaTree

The CassiopeiaTree for which to subsample leaves

keep_singular_root_edge bool (default: True)

Whether or not to collapse the single edge leading from the root in the subsample, if it exists

Return type:

CassiopeiaTree

Returns:

A new CassiopeiaTree that is the induced subtree on a sample of the

leaves in the given tree

Raises:

LeafSubsamplerError if the sample size is <= 0, or larger than the – number of leaves in the tree