Skip to content

Commit

Permalink
Deprecate read_bigwig() and read_gtf()
Browse files Browse the repository at this point in the history
Closes #422
  • Loading branch information
jayhesselberth committed Dec 21, 2024
1 parent a9779af commit 3f341f8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Imports:
Rcpp (>= 1.0.0),
readr,
rlang,
rtracklayer,
stringr,
tibble (>= 1.4.2)
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# valr (development version)

* `read_bigwig()` and `read_gtf()` were deprecated as rtracklayer is no longer avilable on CRAN.

* valr now depends on R >= 4.0.0.

# valr 0.8.2
Expand Down
53 changes: 32 additions & 21 deletions R/read_bed.r
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ bed12_coltypes <- list(

#' Import and convert a bigwig file into a valr compatible tbl
#'
#' @description This function will output a 5 column tibble with
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function will output a 5 column tibble with
#' zero-based chrom, start, end, score, and strand columns.
#'
#' @param path path to bigWig file
Expand All @@ -196,21 +199,28 @@ bed12_coltypes <- list(
#' @importFrom rtracklayer import
#' @export
read_bigwig <- function(path, set_strand = "+") {
check_required(path)
# note that rtracklayer will produce a one-based GRanges object
res <- rtracklayer::import(path)
res <- dplyr::as_tibble(res)
res <- dplyr::mutate(res,
chrom = as.character(seqnames),
start = start - 1L,
strand = set_strand
lifecycle::deprecate_stop(
when = "0.8.2",
what = "read_bigwig()",
details = c(
x = paste0(
"read_bigwig() was removed because rtracklayer is",
"no longer available on CRAN"
),
i = paste0(
"use `bigWigToBedGraph` to convert bw to bedGraph,",
"and then `read_bedgraph()`."
)
)
)
dplyr::select(res, chrom, start, end, score, strand)
}

#' Import and convert a GTF/GFF file into a valr compatible bed tbl format
#'
#' @description This function will output a tibble with the
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function will output a tibble with the
#' required chrom, start, and end columns, as well as other columns depending
#' on content in GTF/GFF file.
#'
Expand All @@ -225,14 +235,15 @@ read_bigwig <- function(path, set_strand = "+") {
#' @importFrom rtracklayer import
#' @export
read_gtf <- function(path, zero_based = TRUE) {
gtf <- rtracklayer::import(path)
gtf <- as.data.frame(gtf)
gtf <- dplyr::mutate_if(gtf, is.factor, as.character)
res <- dplyr::rename(gtf, chrom = seqnames)

if (zero_based) {
res <- dplyr::mutate(res, start = start - 1L)
}

tibble::as_tibble(res)
lifecycle::deprecate_stop(
when = "0.8.2",
what = "read_gtf()",
details = c(
x = paste0(
"read_gtf() was removed because rtracklayer is",
"no longer available on CRAN"
),
i = "convert GTF to BED, and then `read_bed()`."
)
)
}
8 changes: 4 additions & 4 deletions tests/testthat/test_read_bed.r
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ test_that("read broadPeak", {

test_that("read bigwig", {
skip_on_os("windows")
x <- read_bigwig(bigwig_path)
expect_equal(ncol(x), 5)
expect_error(read_bigwig(bigwig_path))
# expect_equal(ncol(x), 5)
})


test_that("read gtf", {
x <- read_gtf(gtf_path)
expect_equal(ncol(x), 26)
expect_error(read_gtf(gtf_path))
# expect_equal(ncol(x), 26)
})

0 comments on commit 3f341f8

Please sign in to comment.