Computes 0/1/2 genotype dosages (sum of alleles across an individual's
haplotype strands) from the long ind_haplotype table and writes them to the
on-demand ind_genotype cache. ind_genotype is never auto-populated by
add_founders() or add_offspring() — call add_dosage() explicitly when
you need dosage values for marker-assisted selection, allele-frequency
queries, or other downstream analysis.
Pipe a tidybreed_table (from get_table() and optionally dplyr::filter()) as the
first argument to select individuals. As with add_tbv(), the distinct
id_ind values in the collected table form the candidate set, so a table with
multiple rows per individual (e.g. ind_phenotype) does not multiply work.
Arguments
- tbl
A
tidybreed_tablefromget_table()(optionally filtered). Any table with anid_indcolumn is accepted.- chip_name
Character or
NULL. Name of a chip defined viadefine_chip()(which writesis_<chip_name>togenome_meta). Loci are restricted tois_<chip_name> = TRUE. Errors if the column is missing.- locus_names
Character vector or
NULL. Explicit loci to materialize. Takes precedence overchip_namewhen both are supplied.- overwrite_dosage
Logical. When
TRUE, existingind_genotyperows for the candidate individuals are deleted before inserting (cache-scope reset). WhenFALSE(default), rows are upserted viaINSERT OR REPLACE— dosage is fully determined by the haplotypes, so re-running is idempotent.
add_dosage() vs. add_genotypes()
These are different operations despite similar names.
add_genotypes() marks animals as physically genotyped on a chip by
writing a BOOLEAN has_<chip> column to ind_meta; it touches no dosage
data. add_dosage() materializes simulated dosage values (ground truth
from ind_haplotype) into ind_genotype.
Examples
if (FALSE) { # \dontrun{
# Dosage for all generation-5 candidates on the 50K chip
pop <- pop |>
get_table("ind_meta") |>
dplyr::filter(gen == 5L) |>
add_dosage(chip_name = "50K")
# Dosage at specific QTL only
pop <- pop |>
get_table("ind_meta") |>
add_dosage(locus_names = c("Locus_1", "Locus_42"))
# Marker-assisted selection: homozygous-favorable at a QTL
ids <- pop |>
get_table("ind_genotype") |>
dplyr::filter(locus_name == "Locus_1", dosage_value == 2L) |>
dplyr::pull(id_ind)
} # }
