Skip to content

Commit

Permalink
Merge pull request #492 from Hugolyu/master
Browse files Browse the repository at this point in the history
[snp_modifyBuild] add local_chain + fix ftp error
close #491
  • Loading branch information
privefl authored Apr 18, 2024
2 parents 94b1058 + bac8eed commit 7417a58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 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.6
Date: 2023-10-18
Version: 1.12.7
Date: 2024-04-17
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.7

- In function `snp_modifyBuild()`, fix a ftp broken link, and add the possibility to use a local chain file specified by the new parameter `local_file`.

## bigsnpr 1.12.6

- Fix issue with `snp_subset()` when either `$fam` or `$map` are missing.
Expand Down
20 changes: 15 additions & 5 deletions R/modify-positions.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#' @param to Genome build to convert to. Default is `hg19`.
#' @param check_reverse Whether to discard positions for which we cannot go back
#' to initial values by doing 'from -> to -> from'. Default is `TRUE`.
#' @param local_chain Local chain file (e.g. `hg18ToHg19.over.chain.gz`) to use
#' 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/}.
#'
#' @references
#' Hinrichs, Angela S., et al. "The UCSC genome browser database: update 2006."
Expand All @@ -24,7 +28,8 @@
#'
snp_modifyBuild <- function(info_snp, liftOver,
from = "hg18", to = "hg19",
check_reverse = TRUE) {
check_reverse = TRUE,
local_chain = NULL) {

if (!all(c("chr", "pos") %in% names(info_snp)))
stop2("Expecting variables 'chr' and 'pos' in input 'info_snp'.")
Expand All @@ -44,10 +49,15 @@ snp_modifyBuild <- function(info_snp, liftOver,
BED, col.names = FALSE, sep = " ", scipen = 50)

# Need chain file
url <- paste0("ftp://hgdownload.cse.ucsc.edu/goldenPath/", from, "/liftOver/",
from, "To", tools::toTitleCase(to), ".over.chain.gz")
chain <- tempfile(fileext = ".over.chain.gz")
utils::download.file(url, destfile = chain, quiet = TRUE)
if (is.null(local_chain)) {
url <- paste0("https://hgdownload.soe.ucsc.edu/goldenPath/", 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
}

# Run liftOver (usage: liftOver oldFile map.chain newFile unMapped)
lifted <- tempfile(fileext = ".BED")
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.

8 changes: 7 additions & 1 deletion 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 7417a58

Please sign in to comment.