/usr/lib/R/site-library/rtracklayer/unitTests/test_bw.R is in r-bioc-rtracklayer 1.38.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | test_bw <- function() {
if (.Platform$OS.type == "windows")
return()
test_path <- system.file("tests", package = "rtracklayer")
test_bw <- file.path(test_path, "test.bw")
ir <- as(PartitioningByWidth(rep(300, 9)), "IRanges")
space <- factor(c(rep("chr2", 5), rep("chr19", 4)), c("chr2", "chr19"))
score <- seq(-1, 1, length = 9)
correct_fixed <- GRanges(space, ir, score = score)
si <- SeqinfoForBSGenome("hg19")
seqlengths(correct_fixed) <- seqlengths(si)[levels(space)]
test <- import(test_bw)
checkIdentical(test, correct_fixed)
test_bw_out <- file.path(tempdir(), "test_out.bw")
export(correct_fixed, test_bw_out)
on.exit(unlink(test_bw_out))
test <- import(test_bw_out)
checkIdentical(test, correct_fixed)
export.bw(correct_fixed, test_bw_out)
test <- import.bw(test_bw_out)
checkIdentical(test, correct_fixed)
correct_bedgraph <- correct_fixed
width(correct_bedgraph) <- seq(1, 300, length = 9)
export(correct_bedgraph, test_bw_out)
test <- import(test_bw_out)
checkIdentical(test, correct_bedgraph)
## TEST: 'which'
which <- GRanges(c("chr2", "chr2"), IRanges(c(1, 300), c(400, 1000)))
correct_which <- subsetByOverlaps(correct_bedgraph, which)
ranges(correct_which) <- ranges(intersect(correct_which, which))
test <- import(test_bw_out, which = which)
checkIdentical(test, correct_which)
## TEST: BigWigSelection (range, no score)
test <- import(test_bw_out,
selection = BigWigSelection(which, colnames = character()))
correct_which <- correct_which[, character()]
checkIdentical(test, correct_which)
## TEST: empty which
which <- GRanges()
correct_which <- subsetByOverlaps(correct_bedgraph, which)
test <- import(test_bw_out, which = which)
checkIdentical(test, correct_which)
## TEST: non-UCSC naming
correct_ncbi <- correct_bedgraph
seqlevels(correct_ncbi) <- sub("chr", "", seqlevels(correct_ncbi))
export(correct_ncbi, test_bw_out)
test <- import(test_bw_out)
checkIdentical(test, correct_ncbi)
## TEST: as="RleList"
correct_cov <- coverage(correct_ncbi, weight="score")
test <- import(test_bw_out, as="RleList")
checkIdentical(correct_cov, test)
## TEST: export RleList
export(correct_cov, test_bw_out)
test <- import(test_bw_out, as="RleList")
checkIdentical(correct_cov, test)
## TEST: export/import NumericList
correct_cov_short <- correct_cov[correct_cov != 0L]
correct_int <- as(correct_cov_short, "NumericList")
which <- GRanges(names(correct_int), IRanges(1, elementNROWS(correct_int)))
metadata(correct_int) <- list(ranges=which)
export(correct_int, test_bw_out)
test <- import(test_bw_out, as="NumericList")
checkIdentical(correct_int, test)
test <- import(test_bw_out, which=which[1], as="NumericList")
checkIdentical(elementNROWS(correct_int[1]), elementNROWS(test))
test <- import(test_bw_out, which=which[1:2], as="NumericList")
checkIdentical(correct_int, test)
}
|