Learn R Programming

seedy (version 1.3)

simulatepopulation: Simulate a pathogen population

Description

Simulates a pathogen population undergoing a Wright-Fisher discrete-time evolutionary process.

Usage

simulatepopulation(m.rate, runtime, equi.pop, sample.times, n.samples=1, 
genomelength=100000, shape=flat, bottle.times=0, bottle.size=1, full=FALSE, 
feedback=1000, init.freq=1, libr=NULL, nuc=NULL, ref.strain=NULL, ...)

Arguments

m.rate
Mutation rate (per sequence per generation).
runtime
Number of generations for simulation to run.
equi.pop
Equilibrium effective population size of pathogens within-host.
sample.times
Vector of times at which to sample population.
n.samples
Number of samples to take at each sampling point (if deepseq=FALSE).
genomelength
Length of genome.
shape
Function describing the population growth dynamics. See Details.
bottle.times
Vector of population bottleneck times.
bottle.size
Size of population bottleneck (if bottle.times!=0).
full
Should complete samples (all genotypes and their frequencies) be returned?
feedback
Intervals between R feedback on simulation progress.
init.freq
Vector of initial frequencies of genotypes, if initial population should be specified. By default, the population grows from a single, randomly generated genotype.
libr
Initial list of genotypes, if initial population should be specified. Must have same length as init.freq.
nuc
Initial list of mutations, if initial population should be specified. Must have same length as init.freq.
ref.strain
Reference strain. By default, this is randomly generated.
...
Additional arguments to be passed to the shape function.

Value

  • Returns a list of sampling data;
  • librList of unique genotypes observed. Each entry is a vector of mutant loci relative to the reference strain.
  • nucList of mutation types corresponding to libr. Each entry is a vector of nucleotides mutated from the reference strain, corresponding to entries in libr.
  • librstrainsVector of unique genotype IDs corresponding to the libr object.
  • obs.strainIf full=TRUE, list of observed genotypes, each entry corresponding to the sample.times. If full=FALSE, a vector of genotype IDs, corresponding to the returned vector obs.time.
  • obs.freqList of observed genotype frequencies returned if full=TRUE.
  • obs.timeVector of observation times returned if full=FALSE.
  • ref.strainReference strain used.

Details

Simulation of a bacterial population. Population is by default initially clonal, and initiated by a single genotype. Population is prevented from extinction at all times. Population can be passed through repeated bottlenecks using the arguments bottle.times and bottle.size. Population growth dynamics are defined by the function called by 'shape'. This function returns the expected population size at each time step, given the total simulation time. By default, the population is expected to grow exponentially until reaching an equilibrium level, specified by equi.pop (flat). Alternatively, the population can follow a sinusoidal growth curve, peaking at runtime/2 (hump). User-defined functions should be of the form function(time,span,equi.pop,...), where span is equal to runtime in this setting.

Examples

Run this code
# Generate 5 genome samples at 5 time points
X <- simulatepopulation(m.rate=0.0005, runtime=10000, equi.pop=2000,
                      sample.times=(1:5)*2000, n.samples=5, 
                      genomelength=10000, full=FALSE)
	
# Generate complete observations at 5 time points
X <- simulatepopulation( m.rate=0.0005, runtime=10000, equi.pop=2000,
                      sample.times=(1:5)*2000, genomelength=10000, 
                      bottle.times=5000, bottle.size=1, full=TRUE)

Run the code above in your browser using DataLab