Calculate and retrieve allele frequencies from:
- all segregating sites (pullSegSiteAf)
- quantitative trait loci (QTL) for a trait (pullQtlAf)
- SNP chip markers (pullSnpAf)
- a user-defined set of markers by name (pullMarkerAf)
Supports Pop-class and MultiPop-class inputs.
For MultiPop objects, output can optionally be simplified to a
chosen nesting level.
MapPop-class objects are supported by
pullSegSiteAf and pullMarkerAf.
Usage
pullSegSiteAf(
pop,
chr = NULL,
sample = NULL,
simParam = NULL,
nThreads = NULL,
simplify = FALSE,
level = 1L
)
pullQtlAf(
pop,
trait = 1,
chr = NULL,
sample = NULL,
simParam = NULL,
nThreads = NULL,
simplify = FALSE,
level = 1L
)
pullSnpAf(
pop,
snpChip = 1,
chr = NULL,
sample = NULL,
simParam = NULL,
nThreads = NULL,
simplify = FALSE,
level = 1L
)
pullMarkerAf(
pop,
markers,
sample = NULL,
simParam = NULL,
nThreads = NULL,
simplify = FALSE,
level = 1L
)Arguments
- pop
An object of
Pop-classorMultiPop-class.MapPop-classobjects are only supported bypullSegSiteAfandpullMarkerAf.- chr
Integer vector of chromosomes to retrieve. If
NULL, all chromosomes are retrieved.- sample
A positive integer giving the number of individuals to sample from
popat random for allele frequency calculation. Passed tosampleassample(seq_len(nInd(pop)), size=sample). IfNULL, no sampling is done and all individuals inpopare used.- simParam
An object of class
SimParamfor non-MapPop-classinputs. IfNULL, the object namedSPin the global environment is used. Ignored whenpopis aMapPop-class.- nThreads
Number of threads to use if OpenMP is available. If
NULL, usesgetNumThreadsforMapPop-classobjects andsimParam$nThreadsotherwise.- simplify
Logical. Used only when
popis aMultiPop-class. IfTRUE, flattenspoptolevelwithflattenMultiPop, combines terminal results withrbind, and attaches a"source"attribute indicating row origins.- level
Integer scalar \(\ge 1\). Used only when
popis aMultiPop-classandsimplify=TRUE. Number ofMultiPoplevels to preserve. Passed toflattenMultiPop. Ignored whensimplify=FALSE.- trait
An integer or a trait name. Indicates which trait's QTL allele frequencies to retrieve.
- snpChip
SNP chip whose allele frequencies are calculated and retrieved. Either an integer index or a SNP chip name.
- markers
Character vector of marker names to calculate and retrieve.
Value
For Pop-class or MapPop-class input, a
one-row matrix of allele frequencies (\(0\)=all (sampled)
individuals carry the ancestral allele and \(1\)=all (sampled)
individuals carry the mutant allele).
For a MultiPop-class input:
- if simplify=FALSE, a nested list matching the MultiPop
structure, with a one-row matrix of allele-frequencies per terminal
population.
- if simplify=TRUE, a simplified object where terminal
allele-frequency matrices are combined (within each retained branch) using
rbind. A "source" attribute records row origins.
When level=1, the result is a single allele-frequency matrix.
Details
With simplify=FALSE, MultiPop structure is preserved and output
follows the same nesting as pop.
With simplify=TRUE, output is simplified to the requested
level. If level exceeds the nesting depth of pop, the
original structure is returned unchanged.
Simplified output includes a "source" attribute: a data frame with
columns level1, level2, etc., giving the source population
name (or index) for each row at each retained level.
Examples
# Create founder haplotypes
founderPop = quickHaplo(nInd=10, nChr=1, segSites=15)
# Retrieve allele frequencies from all segregating
# loci in founder haplotypes
pullSegSiteAf(founderPop)
#> 1_1 1_2 1_3 1_4 1_5 1_6 1_7 1_8 1_9 1_10 1_11 1_12 1_13 1_14 1_15
#> [1,] 0.4 0.4 0.4 0.4 0.4 0.35 0.6 0.55 0.5 0.55 0.6 0.5 0.45 0.3 0.65
# Retrieve allele frequencies from a specific
# set of markers in founder haplotypes
pullMarkerAf(founderPop, markers=c("1_1","1_2"))
#> 1_1 1_2
#> [1,] 0.4 0.4
# Set simulation parameters
SP = SimParam$new(founderPop)
# Add an additive trait with 10 QTL
SP$addTraitA(10, name="Trait1")
# Add a SNP chip
SP$addSnpChip(nSnpPerChr=5, name="5SNPchip")
# Create population
pop = newPop(founderPop, simParam=SP)
# Retrieve allele frequencies from all segregating loci
pullSegSiteAf(pop, simParam=SP)
#> 1_1 1_2 1_3 1_4 1_5 1_6 1_7 1_8 1_9 1_10 1_11 1_12 1_13 1_14 1_15
#> [1,] 0.4 0.4 0.4 0.4 0.4 0.35 0.6 0.55 0.5 0.55 0.6 0.5 0.45 0.3 0.65
# Retrieve allele frequencies from QTL for a specific trait
pullQtlAf(pop, trait="Trait1", simParam=SP)
#> 1_2 1_3 1_4 1_5 1_6 1_7 1_9 1_10 1_11 1_15
#> [1,] 0.4 0.4 0.4 0.4 0.35 0.6 0.5 0.55 0.6 0.65
# Retrieve allele frequencies from a SNP chip
pullSnpAf(pop, snpChip="5SNPchip", simParam=SP)
#> 1_1 1_8 1_12 1_13 1_14
#> [1,] 0.4 0.55 0.5 0.45 0.3
# Retrieve allele frequencies from a specific set of markers
pullMarkerAf(pop, markers=c("1_1","1_2"), simParam=SP)
#> 1_1 1_2
#> [1,] 0.4 0.4
# Create a nested MultiPop
pop2 = randCross(pop, nCrosses=3, nProgeny=4)
#> Error in getSimParam(simParam): simParam was not supplied and there is no SimParam called SP in the global environment. Supply simParam or create SP with SimParam$new()
mp1 = splitPop(
pop2,
by = list(
function(x) rep(LETTERS[1:2], length.out=length(x)),
function(x) paste(x@mother, x@father, sep="_")
)
)
#> Error: object 'pop2' not found
# Retrieve QTL allele frequencies at different simplification levels
pullQtlAf(mp1, simplify=FALSE)
#> Error in getSimParam(simParam): simParam was not supplied and there is no SimParam called SP in the global environment. Supply simParam or create SP with SimParam$new()
pullQtlAf(mp1, simplify=TRUE, level=2)
#> Error in getSimParam(simParam): simParam was not supplied and there is no SimParam called SP in the global environment. Supply simParam or create SP with SimParam$new()
pullQtlAf(mp1, simplify=TRUE, level=1)
#> Error in getSimParam(simParam): simParam was not supplied and there is no SimParam called SP in the global environment. Supply simParam or create SP with SimParam$new()