profileSim: Simulation of complete DNA profiles

View source: R/profileSim.R

profileSimR Documentation

Simulation of complete DNA profiles

Description

Simulation of DNA profiles for specified pedigree members. Some pedigree members may already be genotyped; in that case the simulation is conditional on these. The main work of this function is done by markerSim().

Usage

profileSim(
  x,
  N = 1,
  ids = NULL,
  markers = NULL,
  loopBreakers = NULL,
  seed = NULL,
  numCores = 1,
  simplify1 = TRUE,
  verbose = TRUE
)

Arguments

x

A ped object or a list of such.

N

The number of complete simulations to be performed.

ids

A character (or coercible to character) of ID labels indicating whose genotypes should be simulated. Alternatively, a function taking x as input and returning a character vector of ID labels.

markers

Either a vector indicating a subset of markers attached to x (default: all), or a named list of frequency vectors. In the former case, simulations are conditional on all locus attributes (allele frequencies, mutation models, etc) and any existing genotypes in the indicated markers. If markers is a list of frequency vectors, these are attached as new markers to x (removing any existing markers) and used for unconditional simulations.

loopBreakers

A vector containing IDs of individuals to be used as loop breakers. Can usually be left as NULL, in which case automatic loop breaking is applied. See pedtools::breakLoops().

seed

An integer seed for the random number generator. Used only when no mirai workers are set. For parallel simulations, set the seed in mirai::daemons().

numCores

Deprecated. Use mirai::daemons() to set the number of workers.

simplify1

A logical, by default TRUE, removing the outer list layer when N = 1. See Value.

verbose

A logical, by default TRUE.

Details

Parallel profile simulation

Simulations can be distributed across several R processes using the mirai package. To use this, start mirai workers before calling profileSim():

mirai::daemons(8, seed = 123)

x = nuclearPed()
db = NorwegianFrequencies
res = profileSim(x, N = 100, markers = db)

mirai::daemons(0)

The call to mirai::daemons(8, seed = 123) starts 8 persistent workers and configures reproducible parallel RNG. These workers remain available for later calls until stopped with mirai::daemons(0).

If no mirai daemons are set, profileSim() runs normally, and the seed argument works as before. When mirai daemons are used, set the seed in mirai::daemons(n, seed = ...) and omit the seed argument to profileSim().

Value

A list of N objects similar to x, but with simulated genotypes. Any previously attached markers are replaced by the simulated profiles. If the indicated markers contained genotypes for some pedigree members, these are still present in the simulated profiles.

If N = 1 and simplify1 = TRUE, the outer list layer is removed, i.e., profileSim(..., N = 1, simplify1 = T) is equivalent to profileSim(..., N = 1, simplify1 = F)[[1]]. This is usually the desired object in interactive use, and works well with piping.

When using profileSim() in other functions, it is recommended to add simplify1 = FALSE to safeguard against issues with N = 1.

Examples

# Example pedigree with two brothers
x = nuclearPed(children = c("B1", "B2"))

### Simulate profiles using built-in freq database
profileSim(x, markers = NorwegianFrequencies[1:3])

### Conditioning on known genotypes for one brother

# Attach two SNP markers with genotypes for B1
y = x |>
  addMarker(B1 = "1/2", alleles = 1:2) |>
  addMarker(B1 = "1",   alleles = 1:2, chrom = "X")

# Simulate 2 profiles of B2 conditional on the above
profileSim(y, N = 2, ids = "B2", seed = 123)


forrel documentation built on June 28, 2026, 5:07 p.m.