View source: R/genotypes_and_error.R
index_ab | R Documentation |
This implements the function to index genotypes so that we can put them into matrices. The paper mentions this indexing, in the section "Implementation."
index_ab(a, b, A)
a |
The first allele in the genotype |
b |
The second allele in the genotype |
A |
the total number of alleles at the locus in the population. |
If a is not an allele with index lower than b, then this function automatically reorients the alleles so that it is. This is vectorized and so should work over long vectors of alleles.
# Create some data to test/demonstrate this:
A <- 7
all_genos <- expand.grid(1:A, 1:A)[,c(2,1)] %>%
setNames(c("a", "b"))
# when a < b
right_ord <- all_genos %>%
dplyr::filter(a <= b) %>%
dplyr::mutate(Idx = 1:length(a),
Indab = index_ab(a, b, A))
# when a > b
wrong_ord <- all_genos %>%
dplyr::filter(a >= b) %>%
dplyr::arrange(b, a) %>%
dplyr::mutate(
Idx = 1:length(a),
Indab = index_ab(b, a, A)
)
# then check to make sure it all checks out
all(right_ord$Idx == right_ord$Indab)
all(wrong_ord$Idx == wrong_ord$Indab)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.