wf.traj: Simulate Random Genetic Drift

Description Usage Arguments Value Author(s) Examples

View source: R/simaf.R

Description

wf.traj simulates allele frequency trajectories based on the Wright-Fisher model.

Usage

1
wf.traj(p0, Ne, t, s = 0, h = 0.5, haploid = FALSE, approximate = FALSE)

Arguments

p0

numeric vector with starting allele frequencies.

Ne

integer specifying the desired effective population size. The unit is haploid (if haploid = TRUE) or diploid (if haploid = FALSE) individuals. If is.na(Ne) an infinitely large population size without random genetic drift will be simulated.

t

numeric vector defining for which generations allele frequencies should be returned.

s

numeric specifying the selection coefficient used. By default (s = 0) no selection is applied.

h

numeric indicating the dominance coefficient. This parameter will be ignored if haploid = TRUE.

haploid

logical indicating wether a population of haploid (haploid = TRUE) or diploid (default) individuals should be simulated.

approximate

logical. If approximate = true a continuous time approximation is used if applicable. Alternatively, forward in time simulations are performed (default).

Value

wf.traj returns either a vector (if length(p0) == 1 and length(s) == 1 and length(h) == 1) or a matrix that contains allele frequency trajectories. Columns correspond to the time points defined in t and rows to individual replicates. If only one replicate should be simulated a numeric vector is returned instead of a matrix.

Allele frequencies in the output are guaranteed to be ordered increasing by the number of generations.

Author(s)

Thomas Taus

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# simulate allele frequency trajectories of individual loci using the Wright-Fisher model (diploid individuals)
Ne <- 200
gen <- seq(0, 100, by=10)
alleleFreqs <- wf.traj(p0=rep(0.5, times=500), Ne=Ne, t=gen)
# look at a subset of the generated data
head(alleleFreqs)

# plot allele frequency trajectories
plot(1, type="n", xlim=c(0, max(gen)), ylim=c(0, 1), main="Neutral Genetic Drift", xlab="Generation", ylab="Allele frequency (%)")
for(r in 1:nrow(alleleFreqs)) {
  lines(gen, alleleFreqs[r,])
}

# simulate allele frequency trajectories including selection
alleleFreqs <- wf.traj(p0=rep(0.05, times=500), Ne=Ne, t=gen, s=0.1, h=0.5)

# plot results
plot(1, type="n", xlim=c(0, max(gen)), ylim=c(0, 1), main="Positive Selection", xlab="Generation", ylab="Allele frequency (%)")
for(r in 1:nrow(alleleFreqs)) {
  lines(gen, alleleFreqs[r,])
}

# add the trajectory under selection for a population of infinite size (no random genetic drift)
lines(gen, wf.traj(p0=0.05, Ne=NA, t=gen, s=0.1, h=0.5), col="red")

ThomasTaus/poolSeq documentation built on Oct. 22, 2018, 7:21 p.m.