Skip to content

Commit

Permalink
fixing up some things
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelove committed Aug 11, 2023
1 parent e31a23c commit ef48e84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions R/easylift.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function takes a GRanges object with genomic coordinates in one genome
#' assembly and lifts them to another genome assembly using a chain file.
#'
#' @param gr A GRanges object with genomic coordinates in the original assembly.
#' @param x A GRanges object with genomic coordinates in the original assembly.
#' @param to The target genome assembly (e.g., "hg38").
#' @param chain The path to the chain file containing the liftover mapping.
#' Can be provided in gzipped or non-gzipped format.
Expand All @@ -14,21 +14,21 @@
#' @import tools
#' @import BiocFileCache
#' @export
easylift <- function(gr, to, chain) {
if (is.na(GenomeInfoDb::genome(gr))) {
easylift <- function(x, to, chain) {
if (any(is.na(GenomeInfoDb::genome(x)))) {
stop(
"The genome information for the 'gr' object is missing (NA). Please set the genome before using easylift."
"The genome information is missing. Please set genome(x) before using easylift."
)
}
# Convert the input GRanges to the "UCSC" seqlevels style if not already
if (GenomeInfoDb::seqlevelsStyle(gr) != "UCSC") {
GenomeInfoDb::seqlevelsStyle(gr) <- "UCSC"
if (GenomeInfoDb::seqlevelsStyle(x) != "UCSC") {
GenomeInfoDb::seqlevelsStyle(x) <- "UCSC"
}

if (missing(chain)) {
bfc <- BiocFileCache()
capTo <- paste0(toupper(substr(to,1,1)),substr(to,2,nchar(to))) # capitalize first letter
trychainfile <- paste0(genome(gr),"To",capTo,".over.chain")
trychainfile <- paste0(genome(x),"To",capTo,".over.chain")
q <- bfcquery(bfc, trychainfile)
if (nrow(q) >= 1) {
chain <- bfc[[q$rid[1]]]
Expand Down Expand Up @@ -57,7 +57,7 @@ easylift <- function(gr, to, chain) {
}

# LiftOver the genomic coordinates
cur <- unlist(rtracklayer::liftOver(gr, ch))
cur <- unlist(rtracklayer::liftOver(x, ch))

GenomeInfoDb::seqlevels(cur) <- GenomeInfoDb::seqlevels(to_seqinfo)
GenomeInfoDb::seqinfo(cur) <- to_seqinfo
Expand Down
4 changes: 2 additions & 2 deletions man/easylift.Rd

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

0 comments on commit ef48e84

Please sign in to comment.