Skip to content

Commit

Permalink
Add more flexibility to snp_modifyBuild()
Browse files Browse the repository at this point in the history
Enhance #491
  • Loading branch information
privefl committed May 15, 2024
1 parent aaec3d7 commit e7bb607
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Encoding: UTF-8
Package: bigsnpr
Type: Package
Title: Analysis of Massive SNP Arrays
Version: 1.12.8
Date: 2024-05-10
Version: 1.12.9
Date: 2024-05-15
Authors@R: c(
person("Florian", "Privé", email = "[email protected]", role = c("aut", "cre")),
person("Michael", "Blum", role = "ths"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## bigsnpr 1.12.9

- In function `snp_modifyBuild()`, you can now provide `local_chain` as a vector of two, for when using `check_reverse`. You can now also modify the `base_url` from where to download the chain files.

## bigsnpr 1.12.8

- In function `snp_ancestry_summary()`, now also report correlations between input frequencies and each reference frequencies as well as predicted frequencies. Also add a new parameter `min_cor` to error when the latter correlation is too small.
Expand Down
17 changes: 12 additions & 5 deletions R/modify-positions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#' instead of downloading one from parameters `from` and `to` (the default).
#' You can download one such file from e.g.
#' \url{https://hgdownload.soe.ucsc.edu/goldenPath/hg18/liftOver/}.
#' Provide a vector of two when using `check_reverse`.
#' @param base_url From where to download the chain files. Default is
#' \url{"https://hgdownload.soe.ucsc.edu/goldenPath/"}. You can also try
#' replacing `https` by `http`, and/or `soe` by `cse`.
#'
#' @references
#' Hinrichs, Angela S., et al. "The UCSC genome browser database: update 2006."
Expand All @@ -29,7 +33,8 @@
snp_modifyBuild <- function(info_snp, liftOver,
from = "hg18", to = "hg19",
check_reverse = TRUE,
local_chain = NULL) {
local_chain = NULL,
base_url = "https://hgdownload.soe.ucsc.edu/goldenPath/") {

if (!all(c("chr", "pos") %in% names(info_snp)))
stop2("Expecting variables 'chr' and 'pos' in input 'info_snp'.")
Expand All @@ -50,13 +55,13 @@ snp_modifyBuild <- function(info_snp, liftOver,

# Need chain file
if (is.null(local_chain)) {
url <- paste0("https://hgdownload.soe.ucsc.edu/goldenPath/", from, "/liftOver/",
url <- paste0(base_url, from, "/liftOver/",
from, "To", tools::toTitleCase(to), ".over.chain.gz")
chain <- tempfile(fileext = ".over.chain.gz")
utils::download.file(url, destfile = chain, quiet = TRUE)
} else {
assert_exist(local_chain)
chain <- local_chain
chain <- local_chain[[1]]
assert_exist(chain)
}

# Run liftOver (usage: liftOver oldFile map.chain newFile unMapped)
Expand All @@ -75,7 +80,9 @@ snp_modifyBuild <- function(info_snp, liftOver,

if (check_reverse) {
pos2 <- suppressMessages(
Recall(info_snp, liftOver, from = to, to = from, check_reverse = FALSE)$pos)
Recall(info_snp, liftOver, from = to, to = from, check_reverse = FALSE,
local_chain = local_chain[[2]], base_url = base_url)$pos
)
info_snp$pos[pos2 != pos0] <- NA_integer_
}

Expand Down
6 changes: 5 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/snp_modifyBuild.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7bb607

Please sign in to comment.