Skip to content

Commit

Permalink
Further simplify examples and tests related to lawremi/rtracklayer#83
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed May 21, 2024
1 parent aaa0947 commit 7e903b0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 56 deletions.
11 changes: 8 additions & 3 deletions R/coverage_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 8 additions & 4 deletions R/expressed_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 8 additions & 3 deletions man/coverage_matrix.Rd

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

12 changes: 8 additions & 4 deletions man/expressed_regions.Rd

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

69 changes: 27 additions & 42 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7e903b0

Please sign in to comment.