Generates synthetic spectral flow cytometry data for development and
validation of AutoSpectral pipelines. Cells are assigned random fluorophore
expression levels drawn from three discrete expression layers (high, medium,
low), mixed into detector space via provided spectra (and optionally spectral
variants), and corrupted by configurable noise sources: binomial spillover
sampling, Poisson shot noise, and detector readout noise. Autofluorescence
variation is supported via a provided af.spectra matrix.
Ground-truth abundances, per-cell variant assignments, per-cell AF spectra, and synthetic scatter are returned alongside the raw detector-space matrix and a simple OLS unmixed result (no AF) for immediate inspection.
Usage
sim.flow.data(
spectra,
asp,
n.cells = 10000L,
complexity = 1/3,
layer.centroids = c(0.5, 0.05, 0.005),
layer.cv = 0.2,
af.spectra = NULL,
af.scale.range = c(0.001, 0.05),
af.scatter.slope = 0.1,
variants = NULL,
scatter.data = NULL,
fsc.mean.log = log(2e+05),
fsc.sd.log = 0.4,
ssc.mean.log = log(80000),
ssc.sd.log = 0.5,
fsc.ssc.cor = 0.6,
shot.noise = TRUE,
counts.per.unit = 0.5,
spillover.noise = TRUE,
detector.noise = TRUE,
af.variation = TRUE,
spectral.variation = TRUE,
seed = 42L
)Arguments
- spectra
Numeric matrix of fluorophore spectral signatures, L-infinity normalised, fluorophores in rows and detectors in columns. Required. Defines both the panel and the detector layout.
- asp
The AutoSpectral parameter list from
get.autospectral.param. Used to resolveexpr.data.maxand cytometer-specific detector noise presets.- n.cells
Integer. Number of synthetic cells to generate. Default
10000.- complexity
Numeric in (0, 1]. Fraction of fluorophores that are "on" (non-zero) per cell, drawn without replacement. Default
1/3.- layer.centroids
Numeric vector of length 3, giving the high, medium, and low expression centroids as fractions of
expr.data.max. Defaultc(0.5, 0.05, 0.005).- layer.cv
Numeric scalar. Coefficient of variation (on the log scale) for expression within each layer. Default
0.2.- af.spectra
Numeric matrix of autofluorescence spectra, L-infinity normalised, AF components in rows and detectors in columns. As returned by
get.af.spectra. IfNULL(default), no AF is added.- af.scale.range
Numeric vector of length 2. Range of the uniform distribution from which per-cell AF abundance is drawn, as a fraction of
expr.data.max. Defaultc(0.001, 0.05).- af.scatter.slope
Numeric scalar. Controls how much SSC drives AF abundance. AF abundance is multiplied by
1 + af.scatter.slope * (ssc - median(ssc)) / mad(ssc). Default0.1.- variants
List of spectral variant matrices as returned by
get.spectral.variantsorget.fluor.variants. Each element is named by fluorophore and contains a matrix of variant spectra (variants in rows, detectors in columns). IfNULL(default), the basespectrarows are used for all cells.- scatter.data
Optional numeric matrix of real scatter data (cells in rows, at least two columns for FSC and SSC). When provided, rows are sampled with replacement to generate synthetic scatter, bypassing the log-normal model. Default
NULL.- fsc.mean.log
Numeric. Mean of the log-normal FSC distribution (on the natural-log scale). Default
log(200000).- fsc.sd.log
Numeric. SD of the log-normal FSC distribution. Default
0.4.- ssc.mean.log
Numeric. Mean of the log-normal SSC distribution. Default
log(80000).- ssc.sd.log
Numeric. SD of the log-normal SSC distribution. Default
0.5.- fsc.ssc.cor
Numeric in (-1, 1). Pearson correlation between log(FSC) and log(SSC) in the synthetic scatter population. Default
0.6.- shot.noise
Logical. Whether to apply Poisson shot noise. Default
TRUE.- counts.per.unit
Numeric scalar for
shot.noise. Default0.5. Works inversely; higher numbers will decrease shot noise-driven spread.- spillover.noise
Logical. Whether to apply binomial spillover sampling. Default
TRUE.- detector.noise
Logical. Whether to apply detector readout noise (Gaussian, cytometer-specific). Default
TRUE.- af.variation
Logical. Whether to include autofluorescence variation (requires
af.spectra). DefaultTRUE.- spectral.variation
Logical. Whether to sample per-cell spectral variants (requires
variants). DefaultTRUE.- seed
Integer random seed for reproducibility. Default
42.
Value
A named list with elements:
rawNumeric matrix (cells x detectors) of simulated detector-space data, including all enabled noise sources.
unmixed.no.afNumeric matrix (cells x fluorophores) of OLS-unmixed data without AF, for immediate inspection.
truthNamed list:
abundancesMatrix (cells x fluorophores+AF), true abundance per cell. AF column appended as the last column when
af.spectrais provided.expression.layerCharacter matrix (cells x fluorophores),
"high","mid","low", orNA(off).variant.indexInteger matrix (cells x fluorophores), index of the variant spectrum used per cell per fluorophore.
NAwhen off or no variants provided.af.rowInteger vector (length cells), which row of
af.spectrawas assigned to each cell.NAwhen no AF.af.abundanceNumeric vector (length cells), true AF abundance per cell in instrument units.
0when no AF.scatterNumeric matrix (cells x 2, columns FSC and SSC), synthetic or resampled scatter values.
paramsNamed list of all simulation settings used, for reproducibility.