datasets.simulate_toy

datasets.simulate_toy(
    n_samples=6,
    n_per=80,
    n_genes=20,
    field=500,
    sd_lib_sample=0.15,
    sd_lib_celltype=0.35,
    beta=2,
    composition=0,
    seed=1,
)

Small synthetic spatial data set with a planted neighbourhood-dependent effect.

Port of spiDE’s internal .toySPE(). In the index cell type “A”, gene G1 is up-regulated in the “Responder” condition in proportion to the local density of the niche cell type “B” (B cells sit at high x, so B-niche density rises with x). The negative binomial count model follows splatter’s Splat model.

The generative model is R’s, but the random draws are not: numpy’s generator differs from R’s Mersenne-Twister, so the same seed gives a different data set from R’s. The global numpy RNG is not touched. Power to detect the planted effect at the default design is low (about 15% of seeds reach q < 0.05, as in R); use more samples and cells for a reliable detection.

Parameters

Name Type Description Default
n_samples int Number of samples (alternately Responder, Non-responder; ids S1, S2, …). 6
n_per int Cells per sample. 80
n_genes int Number of genes (G1, G2, …). 20
field float Side length of the square spatial field. 500
sd_lib_sample float Log-scale SD of the sample-level library-size term. 0.15
sd_lib_celltype float Log-scale SD of the cell-type-level library-size term. 0.35
beta float Maximum log-fold change of the planted G1 effect, planted as beta * x / field. The response is non-monotonic in beta; the default is the peak. 2
composition float Size of a planted between-sample composition confound on G2 in index type A (constant within sample, so the true within-sample niche slope is zero). 0 plants none and draws no extra random numbers. 0
seed int Seed of the numpy.random.default_rng used for every draw. 1

Returns

Name Type Description
anndata.AnnData Cells x genes counts in X and layers["counts"], obs columns sample_id, condition, x, y, cell_type, Age, cell_id, Area, nCount and obsm["spatial"].

See Also

toy_spide : The bundled data set from R. simulate_niche : The same without a condition. simulate_clustered : A null with patient-level clustering.

Examples

from spidepy.datasets import simulate_toy
adata = simulate_toy(n_samples=4, n_per=50, seed=1)
adata.shape
(200, 20)
adata.obs["condition"].unique().tolist()
['Responder', 'Non-responder']
bool((adata.X >= 0).all())
True