---
title: "Automating liftover"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Automating liftover}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
if (!requireNamespace("R.utils", quietly = TRUE)) {
  message("Please install the R.utils package to run the code in this vignette")
}

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(GwasDataImport)
library(data.table)
```

There are three ways to determine the build of a dataset:

- `determine_build` - Lookup build against a selected number of HM3 SNPs, matching by rsid
- `determine_build_position` - Lookup build against a selected number of HM3 SNPs, matching by chromosome and position
- `determine_build_biomart` - Lookup positions on biomaRt

The `liftover_gwas()` function determines the build using each of those options, and then performs the liftover automatically.

```{r eval=requireNamespace("R.utils", quietly = TRUE)}
filename <-
  system.file(package = "GwasDataImport", "extdata/pos_0002.txt.gz")
dat <- data.table::fread(filename)
a <-
  liftover_gwas(
    dat,
    to = 38,
    chr_col = "CHROM",
    pos_col = "POS",
    snp_col = "RSID",
    ea_col = "ALT",
    oa_col = "REF"
  )
```
