Skip to contents

Retrieves genotype data from:
- all segregating sites (pullSegSiteGeno)
- quantitative trait loci (QTL) for a trait (pullQtlGeno)
- SNP chip markers (pullSnpGeno)
- a user-defined set of markers by name (pullMarkerGeno)

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 pullSegSiteGeno and pullMarkerGeno.

Usage

pullSegSiteGeno(
  pop,
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullQtlGeno(
  pop,
  trait = 1,
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullSnpGeno(
  pop,
  snpChip = 1,
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullMarkerGeno(
  pop,
  markers,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

Arguments

pop

An object of Pop-class or MultiPop-class. MapPop-class objects are only supported by pullSegSiteGeno and pullMarkerGeno.

chr

Integer vector of chromosomes to retrieve. If NULL, all chromosomes are retrieved.

asRaw

Logical; if TRUE, returns genotypes in raw (byte) format.

simParam

An object of class SimParam for non- MapPop-class inputs. If NULL, the object named SP in the global environment is used. Ignored when pop is a MapPop-class.

nThreads

Number of threads to use if OpenMP is available. If NULL, uses getNumThreads for MapPop-class objects and simParam$nThreads otherwise.

simplify

Logical. Used only when pop is a MultiPop-class. If TRUE, flattens pop to level with flattenMultiPop, combines terminal results with rbind, and attaches a "source" attribute indicating row origins.

level

Integer scalar \(\ge 1\). Used only when pop is a MultiPop-class and simplify=TRUE. Number of MultiPop levels to preserve. Passed to flattenMultiPop. Ignored when simplify=FALSE.

trait

An integer or a trait name. Indicates which trait's QTL genotypes to retrieve.

snpChip

SNP chip whose genotypes are retrieved. Either an integer index or a SNP chip name.

markers

Character vector of marker names to retrieve.

Value

For a non-MultiPop input, a genotype matrix of allele dosages, (\(0=\) homozygous ancestral genotype, rows = individuals, columns = loci) with row names set to individual IDs when available.

For a MultiPop-class input:
- if simplify=FALSE, a nested list matching the MultiPop structure, with one genotype matrix per terminal population.
- if simplify=TRUE, a simplified object where terminal genotype matrices are combined (within each retained branch) using rbind. A "source" attribute records row origins. When level=1, the result is a single genotype 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.

See also

Examples

# Create founder haplotypes
founderPop = quickHaplo(nInd=10, nChr=1, segSites=15)

# Retrieve genotypes from all segregating loci in founder haplotypes
pullSegSiteGeno(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    1   1   1   1   1   0   1   2   2    1    0    1    1    1    2
#> 2    1   2   2   1   0   0   2   2   2    2    0    2    2    1    0
#> 3    1   1   1   1   2   0   1   2   1    1    0    1    1    1    1
#> 4    0   0   1   1   0   1   2   1   1    1    1    1    2    2    2
#> 5    1   2   0   1   1   1   2   1   2    0    0    1    1    2    0
#> 6    2   1   0   2   1   0   1   1   1    2    1    2    0    1    1
#> 7    1   1   2   1   0   1   2   2   1    1    1    0    0    1    0
#> 8    1   1   0   1   1   2   1   1   2    1    1    1    0    2    1
#> 9    0   0   1   0   1   2   0   0   2    1    2    0    0    1    0
#> 10   1   0   0   1   2   0   2   1   0    1    0    0    1    1    1

# Retrieve genotypes from a specific set of markers in founder haplotypes
pullMarkerGeno(founderPop, markers=c("1_1","1_2"))
#>    1_1 1_2
#> 1    1   1
#> 2    1   2
#> 3    1   1
#> 4    0   0
#> 5    1   2
#> 6    2   1
#> 7    1   1
#> 8    1   1
#> 9    0   0
#> 10   1   0

# 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 genotypes from all segregating loci
pullSegSiteGeno(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    1   1   1   1   1   0   1   2   2    1    0    1    1    1    2
#> 2    1   2   2   1   0   0   2   2   2    2    0    2    2    1    0
#> 3    1   1   1   1   2   0   1   2   1    1    0    1    1    1    1
#> 4    0   0   1   1   0   1   2   1   1    1    1    1    2    2    2
#> 5    1   2   0   1   1   1   2   1   2    0    0    1    1    2    0
#> 6    2   1   0   2   1   0   1   1   1    2    1    2    0    1    1
#> 7    1   1   2   1   0   1   2   2   1    1    1    0    0    1    0
#> 8    1   1   0   1   1   2   1   1   2    1    1    1    0    2    1
#> 9    0   0   1   0   1   2   0   0   2    1    2    0    0    1    0
#> 10   1   0   0   1   2   0   2   1   0    1    0    0    1    1    1

# Retrieve genotypes from QTL for a specific trait
pullQtlGeno(pop, trait="Trait1", simParam=SP)
#>    1_2 1_3 1_4 1_7 1_8 1_10 1_11 1_12 1_13 1_15
#> 1    1   1   1   1   2    1    0    1    1    2
#> 2    2   2   1   2   2    2    0    2    2    0
#> 3    1   1   1   1   2    1    0    1    1    1
#> 4    0   1   1   2   1    1    1    1    2    2
#> 5    2   0   1   2   1    0    0    1    1    0
#> 6    1   0   2   1   1    2    1    2    0    1
#> 7    1   2   1   2   2    1    1    0    0    0
#> 8    1   0   1   1   1    1    1    1    0    1
#> 9    0   1   0   0   0    1    2    0    0    0
#> 10   0   0   1   2   1    1    0    0    1    1

# Retrieve genotypes from a SNP chip
pullSnpGeno(pop, snpChip="5SNPchip", simParam=SP)
#>    1_1 1_5 1_6 1_9 1_14
#> 1    1   1   0   2    1
#> 2    1   0   0   2    1
#> 3    1   2   0   1    1
#> 4    0   0   1   1    2
#> 5    1   1   1   2    2
#> 6    2   1   0   1    1
#> 7    1   0   1   1    1
#> 8    1   1   2   2    2
#> 9    0   1   2   2    1
#> 10   1   2   0   0    1

# Retrieve genotypes from a specific set of markers
pullMarkerGeno(pop, markers=c("1_1","1_2"), simParam=SP)
#>    1_1 1_2
#> 1    1   1
#> 2    1   2
#> 3    1   1
#> 4    0   0
#> 5    1   2
#> 6    2   1
#> 7    1   1
#> 8    1   1
#> 9    0   0
#> 10   1   0

# 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 genotypes at different simplification levels
pullQtlGeno(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()
pullQtlGeno(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()
pullQtlGeno(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()