The data frame should be of the format of long_markers. This function will reset the values of AlleIdx and LocIdx in case some markers (or some alleles) were removed. It also rescales the allele frequencies to sum to one, and, of course, sorts the loci into map order along the chromosomes.

reindex_markers(M)

Arguments

M

a data frame of markers.

Examples

# subsample alleles from the long_markers data frame.
# Note, you would never subsample alleles like this but it
# helps to demonstrate the function.
set.seed(5);  # for reproducibility
A_few_markers <- long_markers %>%
  dplyr::sample_n(1000) %>%     # subsample 4000 alleles
  dplyr::group_by(Chrom, Locus) %>%
  dplyr::mutate(NumAlle = dplyr::n()) %>%
  dplyr::filter(NumAlle > 1)  %>%  # chuck out loci only one allele now...
  dplyr::select(-NumAlle)  # get rid of the NumAlle column we created

  reindex_markers(A_few_markers)   # then reindex them
#> # A tibble: 101 × 7
#>    Chrom Locus          Pos Allele LocIdx AlleIdx   Freq
#>    <int> <chr>        <dbl> <chr>   <int>   <int>  <dbl>
#>  1     4 chr4-731  38196983 a2          1       1 0.613 
#>  2     4 chr4-731  38196983 a7          1       2 0.387 
#>  3     4 chr4-912  47705397 a6          2       1 0.555 
#>  4     4 chr4-912  47705397 a5          2       2 0.365 
#>  5     4 chr4-912  47705397 a1          2       3 0.0804
#>  6     4 chr4-934  48505426 a6          3       1 0.609 
#>  7     4 chr4-934  48505426 a5          3       2 0.391 
#>  8     4 chr4-1445 75110217 a2          4       1 0.539 
#>  9     4 chr4-1445 75110217 a4          4       2 0.461 
#> 10     4 chr4-1453 75564909 a8          5       1 0.667 
#> # ℹ 91 more rows