haploSimulate: Simulate haplotype frequencies

View source: R/haploSimulate.R

haploSimulateR Documentation

Simulate haplotype frequencies

Description

Given a matrix of haplotype structure simulates time series for haplotype frequencies under neutrality (drift only) or with selection. Returns haplotype frequency time series data, haplotype structure matrix, and the matrix of allele frequency time series data computed from the haplotypes. Sequencing noise can be added to the allele frequency. In this case also a coverage matrix is returned.

Usage

haploSimulate(
  hp_str,
  Ne,
  tp,
  meancov = NULL,
  hp0 = NULL,
  benef_all = NULL,
  s = 0,
  haploid = FALSE
)

Arguments

hp_str

Haplotype structure matrix. nrow(hp_str) is number of SNP locations and ncol(hp_str) is number of haploypes.

Ne

One integer value corresponding to the effective population size.

tp

A vecotr of integer values corresponding to the generations of interest

meancov

One integer value specifying the mean coverage to simulate sequencing noise. If NULL the true allele frequencies are returned.

hp0

Haplotype frequency matrix at generation 0. length(hp0) is number of haploypes. If NULL all haplotypes are assumed to start at equal frequency 1/ncol(hp_str)

benef_all

A vector of integer numbers corresponding to the rows of hp_str with beneficial allele(s). If NULL neutral simulations are performed.

s

A vector of length nrow(hp_str) where 0 indicates that the corresponding allele is not beneficial, and selection coefficients are entered for each beneficial allele.

haploid

Logical. TRUE for haploid simulations and FALSE for diploids.

Value

List with allele frequency matrix, haplotype frequency matrix and haplotype structure matrix. If meancov!=NULL the allele frequency matrix contains noisy allele frequencies and an additional element corresponding to the coverage matrix is returned.

Examples

hp_str <- matrix(sample(c(rep(0,20), rep(1,30)), 50), nrow = 10, ncol = 5)
Ne <- 300
tp <- seq(0,60,10)
meancov = 80
hp0 = c(0.1,0.3,0.2, 0.05, 0.35)
benef_all = c(1,3)
s = c(0.05,0,0.2,rep(0,7))
haploSimulate(hp_str, Ne, tp, meancov) #to simulate under neutrality. All haplotypes starting with equal frequency
haploSimulate(hp_str, Ne, tp, meancov, hp0) #to simulate under neutrality. Custom starting haplotype frequency.
haploSimulate(hp_str, Ne, tp, meancov,  benef_all, s) #to simulate with selection

MartaPelizzola/haploSep documentation built on May 26, 2023, 11:36 a.m.