diff --git a/R/coverage_matrix.R b/R/coverage_matrix.R index f6556b9..f55675f 100644 --- a/R/coverage_matrix.R +++ b/R/coverage_matrix.R @@ -55,15 +55,20 @@ #' @examples #' #' if (.Platform$OS.type != "windows") { +#' ## Workaround for https://github.com/lawremi/rtracklayer/issues/83 +#' download_study("SRP002001", type = "mean") +#' download_study("SRP002001", type = "samples") +#' #' ## Reading BigWig files is not supported by rtracklayer on Windows #' ## Define expressed regions for study DRP002835, chrY -#' regions <- expressed_regions("DRP002835", "chrY", +#' regions <- expressed_regions("SRP002001", "chrY", #' cutoff = 5L, -#' maxClusterGap = 3000L +#' maxClusterGap = 3000L, +#' outdir = "SRP002001" #' ) #' #' ## Now calculate the coverage matrix for this study -#' rse <- coverage_matrix("DRP002835", "chrY", regions) +#' rse <- coverage_matrix("SRP002001", "chrY", regions, outdir = "SRP002001") #' #' ## One row per region #' identical(length(regions), nrow(rse)) diff --git a/R/expressed_regions.R b/R/expressed_regions.R index dc5c3f7..449ceec 100644 --- a/R/expressed_regions.R +++ b/R/expressed_regions.R @@ -37,17 +37,21 @@ #' [railMatrix][derfinder::railMatrix] #' #' @examples -#' ## Define expressed regions for study SRP009615, chrY +#' ## Define expressed regions for study DRP002835, chrY #' if (.Platform$OS.type != "windows") { +#' ## Workaround for https://github.com/lawremi/rtracklayer/issues/83 +#' download_study("SRP002001", type = "mean") +#' #' ## Reading BigWig files is not supported by rtracklayer on Windows -#' regions <- expressed_regions("SRP009615", "chrY", +#' regions <- expressed_regions("SRP002001", "chrY", #' cutoff = 5L, -#' maxClusterGap = 3000L +#' maxClusterGap = 3000L, +#' outdir = "SRP002001" #' ) #' } #' \dontrun{ #' ## Define the regions for multiple chrs -#' regs <- sapply(chrs, expressed_regions, project = "SRP009615", cutoff = 5L) +#' regs <- sapply(chrs, expressed_regions, project = "SRP002001", cutoff = 5L) #' #' ## You can then combine them into a single GRanges object if you want to #' library("GenomicRanges") diff --git a/man/coverage_matrix.Rd b/man/coverage_matrix.Rd index 2bcbb0c..f1a625a 100644 --- a/man/coverage_matrix.Rd +++ b/man/coverage_matrix.Rd @@ -92,15 +92,20 @@ Note that you will need to run \link{scale_counts} after running \examples{ if (.Platform$OS.type != "windows") { + ## Workaround for https://github.com/lawremi/rtracklayer/issues/83 + download_study("SRP002001", type = "mean") + download_study("SRP002001", type = "samples") + ## Reading BigWig files is not supported by rtracklayer on Windows ## Define expressed regions for study DRP002835, chrY - regions <- expressed_regions("DRP002835", "chrY", + regions <- expressed_regions("SRP002001", "chrY", cutoff = 5L, - maxClusterGap = 3000L + maxClusterGap = 3000L, + outdir = "SRP002001" ) ## Now calculate the coverage matrix for this study - rse <- coverage_matrix("DRP002835", "chrY", regions) + rse <- coverage_matrix("SRP002001", "chrY", regions, outdir = "SRP002001") ## One row per region identical(length(regions), nrow(rse)) diff --git a/man/expressed_regions.Rd b/man/expressed_regions.Rd index 5ee22e6..9b95fc5 100644 --- a/man/expressed_regions.Rd +++ b/man/expressed_regions.Rd @@ -52,17 +52,21 @@ identify the expressed regions (ERs) for a given chromosome. It returns a defined by \link[derfinder:findRegions]{findRegions}. } \examples{ -## Define expressed regions for study SRP009615, chrY +## Define expressed regions for study DRP002835, chrY if (.Platform$OS.type != "windows") { + ## Workaround for https://github.com/lawremi/rtracklayer/issues/83 + download_study("SRP002001", type = "mean") + ## Reading BigWig files is not supported by rtracklayer on Windows - regions <- expressed_regions("SRP009615", "chrY", + regions <- expressed_regions("SRP002001", "chrY", cutoff = 5L, - maxClusterGap = 3000L + maxClusterGap = 3000L, + outdir = "SRP002001" ) } \dontrun{ ## Define the regions for multiple chrs -regs <- sapply(chrs, expressed_regions, project = "SRP009615", cutoff = 5L) +regs <- sapply(chrs, expressed_regions, project = "SRP002001", cutoff = 5L) ## You can then combine them into a single GRanges object if you want to library("GenomicRanges") diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index 2bab781..ef7c2e6 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -109,53 +109,38 @@ test_that("Scaling", { }) if (.Platform$OS.type != "windows") { - range <- - GRanges(seqnames = "chrY", ranges = IRanges(1, 57227415)) - output <- - tryCatch( - rtracklayer::import( - "http://duffel.rail.bio/recount/SRP002001/bw/mean_SRP002001.bw", - selection = reduce(range), - as = "RleList" - ), - error = identity + regions <- expressed_regions("SRP002001", "chrY", cutoff = 5, outdir = tmpdir) + ## Artificially remove the mean coverage file so that the file will have to + ## get downloaded on the first test, then it'll be present for the second + ## test + unlink(localfiles["mean_SRP002001.bw"]) + + test_that("Expressed regions", { + expect_equal( + regions, + expressed_regions("SRP002001", "chrY", cutoff = 5, outdir = tmpdir) ) - if (inherits(output, "error")) { - warning("Remote BigWig file access is failing. See https://github.com/lawremi/rtracklayer/issues/83 for more details.") - } else { - regions <- expressed_regions("SRP002001", "chrY", cutoff = 5) - ## Artificially remove the mean coverage file so that the file will have to - ## get downloaded on the first test, then it'll be present for the second - ## test - unlink(localfiles["mean_SRP002001.bw"]) - - test_that("Expressed regions", { - expect_equal( - regions, - expressed_regions("SRP002001", "chrY", cutoff = 5, outdir = tmpdir) - ) - }) + }) - rse_ER <- coverage_matrix("SRP002001", "chrY", regions) - ## Same for the phenotype data and the sample bigwig file - unlink(localfiles["SRP002001.tsv"]) - unlink(localfiles["SRR036661.bw"]) + rse_ER <- coverage_matrix("SRP002001", "chrY", regions, outdir = tmpdir) + ## Same for the phenotype data and the sample bigwig file + unlink(localfiles["SRP002001.tsv"]) + unlink(localfiles["SRR036661.bw"]) - test_that("Coverage matrix", { - expect_equal( - rse_ER, - coverage_matrix("SRP002001", "chrY", regions, outdir = tmpdir) - ) - expect_equal( - rse_ER, - coverage_matrix("SRP002001", "chrY", regions, - outdir = tmpdir, - chunksize = 500 - ) + test_that("Coverage matrix", { + expect_equal( + rse_ER, + coverage_matrix("SRP002001", "chrY", regions, outdir = tmpdir) + ) + expect_equal( + rse_ER, + coverage_matrix("SRP002001", "chrY", regions, + outdir = tmpdir, + chunksize = 500 ) - }) - } + ) + }) } ## Check size once: