Skip to contents

Retrieve haplotype data from:
- all segregating sites (pullSegSiteHaplo)
- quantitative trait loci (QTL) for a trait (pullQtlHaplo)
- SNP chip markers (pullSnpHaplo)
- a user-defined set of markers by name (pullMarkerHaplo)
- identity-by-descent (IBD) recombination tracking (pullIbdHaplo)

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 pullSegSiteHaplo and pullMarkerHaplo.

Usage

pullSegSiteHaplo(
  pop,
  haplo = "all",
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullQtlHaplo(
  pop,
  trait = 1,
  haplo = "all",
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullSnpHaplo(
  pop,
  snpChip = 1,
  haplo = "all",
  chr = NULL,
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullMarkerHaplo(
  pop,
  markers,
  haplo = "all",
  asRaw = FALSE,
  simParam = NULL,
  nThreads = NULL,
  simplify = FALSE,
  level = 1L
)

pullIbdHaplo(
  pop,
  chr = NULL,
  snpChip = NULL,
  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 pullSegSiteHaplo and pullMarkerHaplo.

haplo

Either "all" for all haplotypes, or an integer selecting one haplotype set. In diploids, use haplo=1 for female-derived haplotypes and haplo=2 for male-derived haplotypes.

chr

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

asRaw

Logical; if TRUE, returns haplotypes 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 haplotypes to retrieve.

snpChip

SNP chip whose haplotypes 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 haplotype matrix (\(0\)=ancestral allele and \(1\)=mutant allele; rows = individuals, columns = loci) with row names set to individual IDs when available, using suffixes for each haplotype set. In diploids, "_1" denotes the maternal haplotype and "_2" denotes the paternal haplotype. pullIbdHaplo returns an integer matrix, where each value represents a unique founder haplotype.

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

pullIbdHaplo requires activating recombination tracking with SimParam$setTrackRec().

See also

Examples

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

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

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

# Set simulation parameters
SP = SimParam$new(founderPop)

# Enable recombination tracking for `pullIbdHaplo()`
SP$setTrackRec(TRUE)

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

# Retrieve haplotypes from QTL for a specific trait
pullQtlHaplo(pop, trait="Trait1", simParam=SP)
#>      1_1 1_2 1_3 1_5 1_6 1_7 1_10 1_11 1_13 1_14
#> 1_1    0   0   0   0   1   1    1    1    1    0
#> 1_2    0   0   1   1   0   1    1    1    0    1
#> 2_1    0   0   0   1   0   1    0    1    0    1
#> 2_2    1   1   0   1   0   1    1    0    0    1
#> 3_1    0   1   0   0   1   1    0    0    0    1
#> 3_2    1   0   1   0   1   1    0    0    1    1
#> 4_1    0   0   0   0   1   0    0    1    0    1
#> 4_2    0   1   0   0   0   0    0    0    0    0
#> 5_1    0   1   1   0   1   1    1    0    1    0
#> 5_2    1   0   1   0   1   0    0    0    1    1
#> 6_1    1   0   0   0   0   1    0    0    1    0
#> 6_2    0   1   0   1   0   0    0    1    1    1
#> 7_1    0   0   0   0   0   1    1    1    1    0
#> 7_2    1   0   1   0   1   0    0    0    1    1
#> 8_1    0   1   0   0   1   0    0    0    1    1
#> 8_2    0   0   1   0   1   0    0    0    0    1
#> 9_1    1   0   1   1   1   0    1    1    0    0
#> 9_2    1   0   0   1   1   1    1    0    1    0
#> 10_1   0   0   0   1   1   0    1    1    1    1
#> 10_2   0   0   0   1   1   1    1    0    1    1

# Retrieve haplotypes from a SNP chip
pullSnpHaplo(pop, snpChip="5SNPchip", simParam=SP)
#>      1_4 1_8 1_9 1_12 1_15
#> 1_1    1   0   1    0    1
#> 1_2    0   1   0    1    1
#> 2_1    0   1   0    0    1
#> 2_2    1   1   1    1    0
#> 3_1    1   1   1    1    1
#> 3_2    1   0   0    0    1
#> 4_1    1   0   1    1    0
#> 4_2    1   1   1    0    1
#> 5_1    0   0   0    1    1
#> 5_2    1   1   1    1    1
#> 6_1    1   0   1    0    1
#> 6_2    1   0   1    1    1
#> 7_1    1   1   1    0    1
#> 7_2    0   1   1    1    0
#> 8_1    1   0   1    1    1
#> 8_2    1   1   1    1    1
#> 9_1    1   0   0    0    0
#> 9_2    1   1   1    0    0
#> 10_1   0   1   1    0    0
#> 10_2   1   1   1    1    1

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

# Retrieve IBD haplotype data for all segregating loci
pullIbdHaplo(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   1   1   1   1   1    1    1    1    1    1    1
#> 1_2    2   2   2   2   2   2   2   2   2    2    2    2    2    2    2
#> 2_1    3   3   3   3   3   3   3   3   3    3    3    3    3    3    3
#> 2_2    4   4   4   4   4   4   4   4   4    4    4    4    4    4    4
#> 3_1    5   5   5   5   5   5   5   5   5    5    5    5    5    5    5
#> 3_2    6   6   6   6   6   6   6   6   6    6    6    6    6    6    6
#> 4_1    7   7   7   7   7   7   7   7   7    7    7    7    7    7    7
#> 4_2    8   8   8   8   8   8   8   8   8    8    8    8    8    8    8
#> 5_1    9   9   9   9   9   9   9   9   9    9    9    9    9    9    9
#> 5_2   10  10  10  10  10  10  10  10  10   10   10   10   10   10   10
#> 6_1   11  11  11  11  11  11  11  11  11   11   11   11   11   11   11
#> 6_2   12  12  12  12  12  12  12  12  12   12   12   12   12   12   12
#> 7_1   13  13  13  13  13  13  13  13  13   13   13   13   13   13   13
#> 7_2   14  14  14  14  14  14  14  14  14   14   14   14   14   14   14
#> 8_1   15  15  15  15  15  15  15  15  15   15   15   15   15   15   15
#> 8_2   16  16  16  16  16  16  16  16  16   16   16   16   16   16   16
#> 9_1   17  17  17  17  17  17  17  17  17   17   17   17   17   17   17
#> 9_2   18  18  18  18  18  18  18  18  18   18   18   18   18   18   18
#> 10_1  19  19  19  19  19  19  19  19  19   19   19   19   19   19   19
#> 10_2  20  20  20  20  20  20  20  20  20   20   20   20   20   20   20
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()
pullIbdHaplo(pop2, simParam=SP)
#> Error: object 'pop2' not found

# Create a nested MultiPop
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 haplotypes at different simplification levels
pullQtlHaplo(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()
pullQtlHaplo(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()
pullQtlHaplo(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()