splisosm.simulation#

Simulation utilities for generating spatial isoform count data.

Functions#

simulate_isoform_counts([n_genes, grid_size, n_isos, ...])

Generate isoform-by-spot count matrix for multiple genes.

simulate_isoform_counts_single_gene([grid_size, ...])

Generate isoform-by-spot count matrix for a given gene.

Module Contents#

splisosm.simulation.simulate_isoform_counts(n_genes=1, grid_size=(30, 30), n_isos=3, total_counts_expected=100, var_sp=0, var_nsp=1, rho=0.99, design_mtx=None, beta_true=None, return_params=True)#

Generate isoform-by-spot count matrix for multiple genes.

Each gene is simulated independently. For simplicity we constrain all genes to have the same number of isoforms. (In fact in the current implementation all genes have the exact same distribution.)

Parameters:
  • n_genes (int) – Number of genes to simulate.

  • grid_size (tuple[int, int]) – Shape of the spatial grid.

  • n_isos (int) – Number of isoforms.

  • total_counts_expected (int | Tensor) – Expected total gene counts per spot.

  • var_sp (float) – Variance explained by spatial structure.

  • var_nsp (float) – Unstructured variance (white noise).

  • rho (float) – Spatial autocorrelation parameter.

  • design_mtx (Optional[Tensor]) – Shape (n_spots, n_factors). Design matrix for the isoform usage ratio.

  • beta_true (Optional[Tensor]) – Shape (n_factors, n_isoforms - 1). Factor coefficients for the design matrix.

  • return_params (bool) – Whether to return simulation parameters.

Returns:

If return_params is False, returns datadict with 'counts', 'coords', 'cov_sp', 'design_mtx'. If return_params is True, returns (data_dict, params_dict).

Return type:

dict or tuple[dict]

splisosm.simulation.simulate_isoform_counts_single_gene(grid_size=(30, 30), n_isos=3, total_counts_expected=100, var_sp=0, var_nsp=1, rho=0.99, design_mtx=None, beta_true=None, return_params=True)#

Generate isoform-by-spot count matrix for a given gene.

Each gene is simulated independently. For simplicity we constrain all genes to have the same number of isoforms. (In fact in the current implementation all genes have the exact same distribution.)

Parameters:
  • grid_size (tuple[int, int]) – Shape of the spatial grid.

  • n_isos (int) – Number of isoforms.

  • total_counts_expected (int | Tensor) – Expected total gene counts per spot.

  • var_sp (float) – Variance explained by spatial structure.

  • var_nsp (float) – Unstructured variance (white noise).

  • rho (float) – Spatial autocorrelation parameter.

  • design_mtx (Optional[Tensor]) – Shape (n_spots, n_factors). Design matrix for the isoform usage ratio.

  • beta_true (Optional[Tensor]) – Shape (n_factors, n_isoforms - 1). Factor coefficients for the design matrix.

  • return_params (bool) – Whether to return simulation parameters.

Returns:

If return_params is False, returns datadict with 'counts', 'coords', 'cov_sp', 'design_mtx'. If return_params is True, returns (data_dict, params_dict).

Return type:

dict or tuple[dict]