cassiopeia.sim.ClonalSpatialDataSimulator#

class cassiopeia.sim.ClonalSpatialDataSimulator(shape=None, space=None, random_seed=None)[source]#

Simulate spatial data with a clonal spatial autocorrelation constraint.

This subclass of SpatialDataSimulator simulates the spatial coordinates of each cell in the provided CassiopeiaTree with spatial constraints such that subclones are more likely to be spatially autocorrelated.

The simulation procedure is as follows. 1. N coordinates are randomly sampled in space, where N is the number of

leaves. Note that there is no mapping between leaves and coordinates (yet). All N coordinates are assigned to the root of the tree.

  1. The tree is traversed from the root to the leaves. At each node, the

    coordinates assigned to that node are split according to the number of leaves in each child. A spatial constraint is applied to this step by iteratively assigning each coordinate to the spatially closest child.

Parameters:
shape Tuple[int, ...] | NoneOptional[Tuple[int, ...]] (default: None)

Shape of the space to place cells on. For instance, (100, 100) means a 2D surface of 100x100 pixels. By default in two dimensions (length is 2), an elliptical surface is used. In higher dimensions, the entire (hyper)cuboid is used.

space ndarray | NoneOptional[ndarray] (default: None)

Numpy array mask representing the space that cells may be placed. For example, to place cells on a 2D circlular surface, this argument will be a boolean Numpy array where the circular surface is indicated with True.

random_seed int | NoneOptional[int] (default: None)

A seed for reproducibility

Raises:

DataSimulatorError if neither shape nor space are provided

Methods

sample_points(n)[source]#

Sample the given number of points within the shape of this object.

Points are sampled using Poisson-Disc sampling to generate approximately equally-spaced points. The Bridson algorithm is used, which is implemented in the poisson_disc package. https://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf

Parameters:
n int

Number of points to sample.

Return type:

ndarray

Returns:

n sampled points within shape

overlay_data(tree, attribute_key='spatial')[source]#

Overlays spatial data onto the CassiopeiaTree via Brownian motion.

Parameters:
tree CassiopeiaTree

The CassiopeiaTree to overlay spatial data on to.

attribute_key str (default: 'spatial')

The name of the attribute to save the coordinates as. This also serves as the prefix of the coordinates saved into the cell_meta attribute as {attribute_key}_i where i is an integer from 0…`dim-1`.