Added simulation of spatial data that matches the gene expression distribution of the PBMC3k scRNA-seq dataset, varying in the number of cells, cell types, and gene expression over space.
By default, the single-cell data is sampled. To simulate spatial data (dependent on a single gene), the function simulate_spatial_data needs to be called. To simulate exact positions for cells and spots (not just the grid field coordinate), the user needs to call the method simulate_exact_positions.
Cell types are saved alongside spot information in adata.uns['spots']
Provide several plotting functions for visualizing gene expression (spatial_heatmap_gene), local metric or statistic scores (spatial_heatmap_metric), and the spatial distribution of cells (spatial_cell_plot) and spots (spatial_spot_plot).
Ensured the entire simulation runs in a timely manner.
An exemplary test run can be made using the following code:
import txsim as tx
sim = tx.simulation.Simulation()
sim.plot_kde()
sim.simulate_spatial_data('IL32')
sim.spatial_heatmap_gene('IL32', flavor="sum")
# simulate exact positions and plot cells and spots
sim.simulate_exact_positions(radius_range=(0.01, 0.05), cell_sampling_type='uniform', spot_sampling_type='uniform')
sim.spatial_cell_plot(s=10)
sim.spatial_spot_plot(s=2)
# look at spots in one grid field
adata_sp_subset = sim.adata_sp[(sim.adata_sp.obs['grid_x'] == 25) & (sim.adata_sp.obs['grid_y'] == 5)]
adata_sp_subset.uns['spots'] = sim.adata_sp.uns['spots'][sim.adata_sp.uns['spots']['cell_id'].isin(adata_sp_subset.obs_names)]
sim.spatial_spot_plot(adata_sp=adata_sp_subset)
Okay I merge this for now as it's quite separate from all other parts in the package anyway.
Will be important to make some adjustments at some point, but already useful in current state.
Changes proposed in this pull request:
simulate_spatial_data
needs to be called. To simulate exact positions for cells and spots (not just the grid field coordinate), the user needs to call the methodsimulate_exact_positions
.adata.uns['spots']
spatial_heatmap_gene
), local metric or statistic scores (spatial_heatmap_metric
), and the spatial distribution of cells (spatial_cell_plot
) and spots (spatial_spot_plot
).An exemplary test run can be made using the following code: