pop_recomb | R Documentation |
Each new genome has breaks drawn from the recombination model accelerated for the desired number of generations G
, and haplotypes are drawn and copied randomly from the population.
This results in a population with individuals drawn independently and identically distributed but with LD within individuals, since the ancestral LD is preserved to some extent (attenuated by recombination after G
generations).
If there is no LD in haps
, then the output will not have LD either except when the number of columns of haps
is very small (which resembles a bottleneck).
This model does not introduce mutations (unlike the original Li-Stephens).
Genotypes, when requested, are simply sums of independently drawn haplotype values.
pop_recomb(
haps,
bim,
map,
G,
n_ind,
geno = TRUE,
loci_on_cols = FALSE,
indexes_loci = NULL,
indexes_chr_ends = NULL
)
haps |
Regular matrix or |
bim |
The table of variants of |
map |
The genetic map, a list of chromosomes each of which is a data.frame/tibble with columns |
G |
Number of generations since most recent common ancestor of population (to multiply standard recombination rate) |
n_ind |
Number of individuals (if geno = TRUE) or haplotypes (half individuals, if geno = FALSE) desired in output |
geno |
If |
loci_on_cols |
If |
indexes_loci |
Vector of index ranges (start, end) of loci to simulate, to request to simulate only a subset of the loci in |
indexes_chr_ends |
Optional vector mapping each chromosome (index in vector) to the last index in the |
A matrix with the same number of rows as haps
and n_ind
columns, with values copied from haps
in (recombination) blocks if geno = FALSE
, or sums of two such values drawn independently when geno = TRUE
.
# simulate a tiny population with few SNPs for example
library(tibble)
bim <- tibble(
chr = c(2, 2, 3, 3, 22),
pos = c(100, 121, 53, 154, 66) * 1e6
)
m_loci <- nrow( bim )
# Most often, haplotypes are binary data as simulated here.
# Here haplotypes will be totally unstructured, but to have LD in the output use real human data
# or data simulated to have LD
n_ind_haps <- 5
haps <- matrix(
rbinom( m_loci * n_ind_haps, 1, 0.5 ),
nrow = m_loci,
ncol = n_ind_haps
)
# makes sense to have a lot of recombination at the population level
G <- 500
# ask for small output for example
n_ind <- 7
# use the recombination map for the same genome build as your data!
map <- recomb_map_hg38
# simulate genotypes! (Usually more convenient, but phase information is lost)
X <- pop_recomb( haps, bim, map, G, n_ind )
# simulate haplotypes instead (preserves true phase)
H <- pop_recomb( haps, bim, map, G, n_ind, geno = FALSE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.