
Extract genotype data for individuals, by chip and/or QTL loci
Source:R/extract_genotypes.R
extract_genotypes.RdReturns a tibble of genotypes (0/1/2 encoding) for a set of individuals,
restricted to loci selected by a chip definition, a filtered
genome_effects table, or both. Pipe a tidybreed_table (from
get_table() and optionally dplyr::filter()) as the first argument to restrict
which individuals are included.
At least one of chip_name or effects_tbl must be provided. When both
are given the locus sets are unioned (deduplicated, ordered by
locus_id).
Chip path — the returned individual set is the intersection of:
Animals with
has_<chip_name> == TRUEinind_metaAnimals matching any pending
filter()predicates ontblLoci with
is_<chip_name> == TRUEingenome_meta
QTL path (effects_tbl) — the returned individual set is:
Animals matching any pending
filter()predicates ontbl(or all individuals inind_haplotypewhen no filter is applied)Loci whose
locus_nameappears in the collectedeffects_tbl
Usage
extract_genotypes(
tbl,
chip_name = NULL,
effects_tbl = NULL,
loci_tbl = NULL,
col_name = NULL
)Arguments
- tbl
A
tidybreed_tableobject fromget_table()(optionally piped throughdplyr::filter()). The table must contain anid_indcolumn when a filter is applied.- chip_name
Character or
NULL. Name of a chip previously defined viadefine_chip()and applied to animals viaadd_genotypes(). WhenNULLthe chip path is skipped.- effects_tbl
A
tidybreed_tablefromget_table(pop, "genome_effects")(optionally filtered), orNULL. The collected table must contain alocus_namecolumn. Usedplyr::filter()to restrict bytrait_name,genome_effect_type,genome_value,line_name, etc. WhenNULLthe QTL path is skipped.- loci_tbl
A
tidybreed_tablefromget_table(pop, "genome_meta")(optionally filtered), orNULL. A general locus filter independent of chips and QTL sets — e.g.filter(!chr_name %in% c("X", "Y", "MT"))to restrict to autosomes. The collected table'slocus_namevalues become the locus set. Unioned withchip_name/effects_tblwhen combined.- col_name
Character. Name of the BOOLEAN column in
ind_metathat records chip genotyping status. Default:paste0("has_", chip_name). Ignored whenchip_nameisNULL.
Value
A tibble with one row per individual and one column per selected
locus (id_ind + locus_N columns). Locus columns use 0/1/2 integer
encoding and are ordered by locus_id.
Examples
if (FALSE) { # \dontrun{
# All genotyped animals on the 50k chip (unchanged usage)
geno <- pop |> get_table("ind_meta") |> extract_genotypes("50k")
# Only females genotyped on the HD chip
geno <- pop |>
get_table("ind_meta") |>
dplyr::filter(sex == "F") |>
extract_genotypes("HD")
# QTL loci for a trait (all individuals)
geno <- pop |>
get_table("ind_meta") |>
extract_genotypes(
effects_tbl = get_table(pop, "genome_effects") |>
dplyr::filter(trait_name == "ADG")
)
# Large-effect QTL only, females only
geno <- pop |>
get_table("ind_meta") |>
dplyr::filter(sex == "F") |>
extract_genotypes(
effects_tbl = get_table(pop, "genome_effects") |>
dplyr::filter(trait_name == "ADG", abs(genome_value) > 0.15)
)
# Chip loci + QTL loci unioned
geno <- pop |>
get_table("ind_meta") |>
extract_genotypes(
chip_name = "50k",
effects_tbl = get_table(pop, "genome_effects") |>
dplyr::filter(trait_name == "ADG")
)
} # }