Skip to contents

This function reorders the loci table so that positions within a chromosome are sequential. It also re-saves the genotypes into a new file backed matrix with the new order, so that it can be used by functions such as loci_ld_clump() and gt_pca_autoSVD(). If the loci table is already ordered, the original gen_tibble is returned.

Usage

gt_order_loci(
  .x,
  use_current_table = FALSE,
  ignore_genetic_dist = TRUE,
  quiet = FALSE,
  ...
)

Arguments

.x

a gen_tibble

use_current_table

boolean, if FALSE (the default), the table will be reordered; if TRUE, then the current loci table, which might have been reordered manually, will be used, but only if the positions within each chromosome are sequential

ignore_genetic_dist

boolean to ignore the genetic distance when checking. Note that, if genetic_dist are being ignored and they are not sorted, the function will set them to zero to avoid problems with other software.

quiet

boolean to suppress information about the files

...

other arguments

Value

A gen_tibble

Examples

example_gt <- example_gt("gen_tbl") %>% select_loci(c(1, 5, 2, 6, 4, 3))

# Loci are in the wrong order
show_loci(example_gt)
#> # A tibble: 6 × 8
#>   big_index name  chromosome position genetic_dist allele_ref allele_alt chr_int
#>       <int> <chr> <chr>         <int>        <dbl> <chr>      <chr>        <int>
#> 1         1 rs1   chr1              3            0 A          T                1
#> 2         5 rs5   chr2             23            0 C          G                2
#> 3         2 rs2   chr1              5            0 T          C                1
#> 4         6 rs6   chr2            456            0 T          A                2
#> 5         4 rs4   chr1            343            0 G          C                1
#> 6         3 rs3   chr1             65            0 C          NA               1

# Reorder the loci, ignoring genetic distance
example_gt_ordered <- gt_order_loci(example_gt, ignore_genetic_dist = TRUE)
#> Genetic distances are not sorted, setting them to zero
#> 
#> gen_backing files updated, now
#> using bigSNP file: /tmp/RtmpyN1xne/file22a251b9e08f_v2.rds
#> with backing file: /tmp/RtmpyN1xne/file22a251b9e08f_v2.bk
#> make sure that you do NOT delete those files!

# Loci are now in the correct order
show_loci(example_gt_ordered)
#> # A tibble: 6 × 8
#>   big_index name  chromosome position genetic_dist allele_ref allele_alt chr_int
#>       <int> <chr> <chr>         <int>        <dbl> <chr>      <chr>        <int>
#> 1         1 rs1   chr1              3            0 A          T                1
#> 2         2 rs2   chr1              5            0 T          C                1
#> 3         3 rs3   chr1             65            0 C          NA               1
#> 4         4 rs4   chr1            343            0 G          C                1
#> 5         5 rs5   chr2             23            0 C          G                2
#> 6         6 rs6   chr2            456            0 T          A                2