deconvatac.tl.simulate#

Classes#

Sampler

Class to sample cells and clusters from a given dataset.

Functions#

conway_maxwell_poisson(lambda_, nu)

Sample from the Conway-Maxwell-Poisson distribution.

generate_spatial_data(→ [anndata.AnnData, muon.MuData])

Generate spatial data.

Module Contents#

deconvatac.tl.simulate.conway_maxwell_poisson(lambda_, nu)#

Sample from the Conway-Maxwell-Poisson distribution.

class deconvatac.tl.simulate.Sampler(reference: [muon.MuData, anndata.AnnData], cell_type_key: str, num_spots: int, n_regions: int, region_type: str = 'stripes', cell_number_mean: [int, list] = 6, cell_number_nu: [float, list] = 20.0, cell_type_number: [int, list] = 4, balance: str | None = 'balanced')#

Class to sample cells and clusters from a given dataset.

reference#
cell_type_key#
num_spots#
obs#
n_regions#
region_type = 'stripes'#
init_sample_prob(balance='unbalanced')#

Initialize the sample probabilities based on cell type counts.

Returns#

None

define_regions(used_clusters)#

Define the regions to sample from.

Parameters#

used_clustersdict

A dictionary containing the clusters to be used in each region.

Returns#

None

Raises#

ValueError

If the region_type parameter is not one of [‘stripes’, ‘circles’, ‘gradient_number’, ‘gradient_celltype’]

stripe_regions()#

Define regions as stripes.

Returns#

None

circle_regions()#

Define regions in circles.

Returns#

None

gradient_number_regions()#

Define regions as a gradient.

Returns#

None

gradient_celltype_regions(used_clusters)#

Define regions as a gradient.

Parameters#

used_clusterslist

The clusters to be used in the gradient cell type regions.

Returns#

None

sample_data()#

Sample data from the given dataset.

Returns#

tuple

A tuple of expression and density arrays.

sample_spots(params)#

Sample cells based on given parameters.

Parameters#

paramsnp.ndarray

Array of cell and cluster counts.

Returns#

tuple

A tuple of expression and density arrays.

Raises#

None

get_coords()#

Get the coordinates for the spots.

Returns#

tuple

A tuple of X and Y coordinates.

deconvatac.tl.simulate.generate_spatial_data(reference: [muon.MuData, anndata.AnnData], cell_type_key: str, num_spots: int = 1024, n_regions: int = 5, balance: str | None = None, cell_number_mean: [int, list] = 6, cell_number_nu: [float, list] = 20.0, cell_type_number: [int, list] = 4, **kwargs) [anndata.AnnData, muon.MuData]#

Generate spatial data.

Parameters#

referenceUnion[mu.MuData, ad.AnnData]

The reference dataset used for generating spatial data.

cell_type_keystr

The key in the reference dataset that specifies the cell type information.

num_spotsint, optional

The number of spots (locations) to generate, by default 1024.

n_regionsint, optional

The number of spatial regions to generate, by default 5.

balancestr, optional

The balancing method to use for generating spatial data, by default None.

cell_number_meanUnion[int, list], optional

The mean number of cells per spot, by default 6.

cell_number_nuUnion[float, list], optional

The dispersion parameter for the negative binomial distribution used to model cell numbers, by default 20.0.

cell_type_numberUnion[int, list], optional

The number of cell types to generate, by default 4.

**kwargs

Additional keyword arguments.

referenceUnion[mu.MuData, ad.AnnData]

The reference dataset used for generating spatial data.

cell_type_keystr

The key in the reference dataset that specifies the cell type information.

num_spotsint, optional

The number of spots (locations) to generate, by default 1024.

n_regionsint, optional

The number of spatial regions to generate, by default 5.

balancestr, optional

The balancing method to use for generating spatial data, by default None.

cell_number_meanUnion[int, list], optional

The mean number of cells per spot, by default 6.

cell_number_nuUnion[float, list], optional

The dispersion parameter for the negative binomial distribution used to model cell numbers, by default 20.0.

cell_type_numberUnion[int, list], optional

The number of cell types to generate, by default 4.

**kwargs

Additional keyword arguments.

Returns#

Union[ad.AnnData, mu.MuData]

The generated spatial data.

Notes#

This function generates spatial data based on a reference dataset. It uses a sampling approach to generate synthetic spatial data with specified characteristics such as cell type composition, cell numbers, and spatial organization.

The generated spatial data is returned as an AnnData object if the reference dataset is an AnnData object, or as a MuData object if the reference dataset is a MuData object. Union[ad.AnnData, mu.MuData]

The generated spatial data.

Notes#

This function generates spatial data based on a reference dataset. It uses a sampling approach to generate synthetic spatial data with specified characteristics such as cell type composition, cell numbers, and spatial organization.

The generated spatial data is returned as an AnnData object if the reference dataset is an AnnData object, or as a MuData object if the reference dataset is a MuData object.