cassiopeia.sim.SpatialLeafSubsampler#

class cassiopeia.sim.SpatialLeafSubsampler(bounding_box=None, space=None, ratio=None, number_of_leaves=None, attribute_key='spatial', merge_cells=False)[source]#

Methods

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

Subsamples leaves within a given tree.

Subsets the leaves of a CassiopeiaTree to those within a region of interest 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 Optional[bool] (default: True)

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

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.

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 invalid region of number of leaves