Skip to contents

Turn a simulate_nil() truth table into observed data under a generic sequencing model: per marker draw depth ~ Poisson(depth), mask a fraction p_missing (and zero-depth markers) to missing, and draw ALT reads ~ Binomial(depth, p) where p is the state's donor fraction (0 / 0.5 / 1) flipped by the per-read error. Returns the read_counts()-style columns plus a hard genotype g (masked to 3 where missing), so the result drives both the count callers (n_ref/n_alt) and the genotype callers (g). The named experiment-specific coverage regimes (skim / BRB / target) live in the pipeline, not here.

Usage

simulate_counts(truth, depth = 1, error = 0.01, p_missing = 0, seed = NULL)

Arguments

truth

A simulate_nil() table (needs name, donor, chr, pos, state).

depth

Mean per-marker read depth (Poisson mean).

error

Per-read error rate (homozygote miscall probability).

p_missing

Extra fraction of markers set missing (on top of zero-depth).

seed

Optional RNG seed.

Value

data.frame name, donor, chr, pos, n_ref, n_alt, g (g in {0,1,2,3}).

Examples

if (requireNamespace("simcross", quietly = TRUE)) {
  truth <- simulate_nil("BC2S2", n = 2, chr = 1:2, n_markers = 100, seed = 1)
  obs <- simulate_counts(truth, depth = 6, seed = 1)
  head(obs)
}
#>      name donor chr      pos n_ref n_alt g
#> 1 sim0001     B   1    37410     0     4 2
#> 2 sim0001     B   1  5642597     0     5 2
#> 3 sim0001     B   1 11247784     1     5 2
#> 4 sim0001     B   1 16852971     0     9 2
#> 5 sim0001     B   1 22458158     0     4 2
#> 6 sim0001     B   1 28063345     9     0 0