... | ... |
@@ -7,11 +7,11 @@ importFrom(BiocGenerics, "anyDuplicated", "cbind", "colnames", |
7 | 7 |
"combine", "density", "intersect", "lapply", "ncol", |
8 | 8 |
"nrow", "order", "paste", "pmax", "pmin", "rbind", |
9 | 9 |
"Reduce", "rep.int", "rownames", "sapply", "setdiff", |
10 |
- "strand", "strand<-", "union", "unique", "updateObject") |
|
10 |
+ "strand", "strand<-", "union", "unique", "updateObject", "unstrand") |
|
11 | 11 |
importFrom(stats, "approxfun", "fisher.test", "ppoints", |
12 | 12 |
"predict", "preplot", "qchisq", |
13 | 13 |
"qnorm", "qqplot", "qunif", "cov2cor", |
14 |
- "plogis") |
|
14 |
+ "plogis", "setNames") |
|
15 | 15 |
importFrom(graphics, "abline", "axis", "layout", "legend", "lines", |
16 | 16 |
"mtext", "par", "plot", "points", "polygon", "rect", "rug", "text") |
17 | 17 |
import(parallel) |
... | ... |
@@ -27,15 +27,15 @@ importMethodsFrom(Biobase, "annotatedDataFrameFrom", |
27 | 27 |
"pData", "pData<-", |
28 | 28 |
"sampleNames", "sampleNames<-") |
29 | 29 |
importFrom(Biobase, "validMsg") |
30 |
-importMethodsFrom(GenomeInfoDb, "seqlengths", "seqlengths<-", "seqinfo", "seqinfo<-", |
|
31 |
- "seqnames", "seqnames<-", "seqlevels", "seqlevels<-") |
|
30 |
+importMethodsFrom(GenomeInfoDb, "seqlengths", "seqlengths<-", "seqinfo", |
|
31 |
+ "seqinfo<-", "seqnames", "seqnames<-", "seqlevels", |
|
32 |
+ "seqlevels<-", "sortSeqlevels") |
|
33 |
+importFrom(GenomeInfoDb, "Seqinfo") |
|
32 | 34 |
import(S4Vectors) |
33 | 35 |
importFrom(gtools, "combinations") |
34 |
-# importFrom(data.table, "setnames", "setDT", "data.table", ":=", "setkey") |
|
35 |
-# TODO: More careful use of imports to avoid clashes (e.g., S4Vectors::shift() |
|
36 |
-# and data.table::shift()). |
|
37 |
-import(data.table) |
|
38 |
-importFrom(R.utils, "isGzipped", "gunzip") |
|
36 |
+# NOTE: data.table has some NAMESPACE clashes with functions in Bioconductor, |
|
37 |
+# e.g., shift(). If new ones are discovered, add them to this list. |
|
38 |
+import(data.table, except = c(shift, first, second)) |
|
39 | 39 |
import(limma) |
40 | 40 |
importFrom(permute, "shuffleSet", "how") |
41 | 41 |
import(DelayedArray) |
... | ... |
@@ -43,12 +43,12 @@ import(BiocParallel) |
43 | 43 |
importFrom(readr, "cols", "cols_only", "col_character", "col_integer", |
44 | 44 |
"col_skip", "col_double", "col_factor", "read_tsv", "tokenizer_tsv") |
45 | 45 |
importFrom(Biostrings, "DNAString", "vmatchPattern", "reverseComplement") |
46 |
+importFrom(utils, "read.delim") |
|
46 | 47 |
|
47 | 48 |
## |
48 | 49 |
## Exporting |
49 | 50 |
## |
50 | 51 |
|
51 |
- |
|
52 | 52 |
exportClasses("hasGRanges", |
53 | 53 |
"BSseq", |
54 | 54 |
"BSseqTstat", |
... | ... |
@@ -226,7 +226,11 @@ BSmooth <- function(BSseq, |
226 | 226 |
se.coef_sink <- NULL |
227 | 227 |
sink_lock <- NULL |
228 | 228 |
} else if (BACKEND == "HDF5Array") { |
229 |
- coef_sink <- HDF5RealizationSink( |
|
229 |
+ if (!requireNamespace("HDF5Array", quietly = TRUE)) { |
|
230 |
+ stop("HDF5Array package required for HDF5Array backend", |
|
231 |
+ call. = FALSE) |
|
232 |
+ } |
|
233 |
+ coef_sink <- HDF5Array::HDF5RealizationSink( |
|
230 | 234 |
dim = dim(M), |
231 | 235 |
# NOTE: Never allow dimnames. |
232 | 236 |
dimnames = NULL, |
... | ... |
@@ -237,7 +241,7 @@ BSmooth <- function(BSseq, |
237 | 241 |
sink_lock <- ipcid() |
238 | 242 |
on.exit(ipcremove(sink_lock), add = TRUE) |
239 | 243 |
if (keep.se) { |
240 |
- se.coef_sink <- HDF5RealizationSink( |
|
244 |
+ se.coef_sink <- HDF5Array::HDF5RealizationSink( |
|
241 | 245 |
dim = dim(M), |
242 | 246 |
# NOTE: Never allow dimnames. |
243 | 247 |
dimnames = NULL, |
... | ... |
@@ -53,3 +53,78 @@ |
53 | 53 |
stop("'type' = ", type, " is not supported") |
54 | 54 |
} |
55 | 55 |
} |
56 |
+ |
|
57 |
+# Helper functions for setting up ArrayGrid instances -------------------------- |
|
58 |
+ |
|
59 |
+# NOTE: Copy of minfi:::colGrid() |
|
60 |
+# TODO: Perhaps move this to DelayedMatrixStats? |
|
61 |
+colGrid <- function(x) { |
|
62 |
+ block_maxlen <- max(nrow(x), |
|
63 |
+ DelayedArray:::get_default_block_maxlength(type(x))) |
|
64 |
+ spacings <- DelayedArray:::get_spacings_for_linear_capped_length_blocks( |
|
65 |
+ refdim = dim(x), |
|
66 |
+ block_maxlen = block_maxlen) |
|
67 |
+ RegularArrayGrid(dim(x), spacings) |
|
68 |
+} |
|
69 |
+ |
|
70 |
+# NOTE: Copy of minfi:::rowGrid() |
|
71 |
+# TODO: Perhaps move this to DelayedMatrixStats? |
|
72 |
+rowGrid <- function(x) { |
|
73 |
+ block_maxlen <- max(ncol(x), |
|
74 |
+ DelayedArray:::get_default_block_maxlength(type(x))) |
|
75 |
+ spacings <- DelayedArray:::get_spacings_for_hypercube_capped_length_blocks( |
|
76 |
+ refdim = dim(x), |
|
77 |
+ block_maxlen = block_maxlen) |
|
78 |
+ RegularArrayGrid(dim(x), spacings) |
|
79 |
+} |
|
80 |
+ |
|
81 |
+# Advanced block processing routines ------------------------------------------- |
|
82 |
+ |
|
83 |
+# NOTE: Copy of minfi:::blockApplyWithRealization() |
|
84 |
+# TODO: Perhaps move this to DelayedMatrixStats? |
|
85 |
+# NOTE: DelayedArray::blockApply() with the option to write the blocks to |
|
86 |
+# 'sink'. Useful, for example, to apply a function across column-blocks |
|
87 |
+# of a DelayedMatrix, write these results to disk, and then wrap |
|
88 |
+# these in a DelayedMatrix. |
|
89 |
+# TODO: See https://github.com/Bioconductor/DelayedArray/issues/10 |
|
90 |
+blockApplyWithRealization <- function(x, FUN, ..., sink = NULL, x_grid = NULL, |
|
91 |
+ sink_grid = NULL, BPREDO = list(), |
|
92 |
+ BPPARAM = bpparam()) { |
|
93 |
+ FUN <- match.fun(FUN) |
|
94 |
+ |
|
95 |
+ # Check conformable dots_grids and sinks_grids |
|
96 |
+ x_grid <- DelayedArray:::.normarg_grid(x_grid, x) |
|
97 |
+ sink_grid <- DelayedArray:::.normarg_grid(sink_grid, sink) |
|
98 |
+ if (!identical(dim(x_grid), dim(sink_grid))) { |
|
99 |
+ stop("non-conformable 'x_grid' and 'sink_grid'") |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ # Loop over blocks of `x` and write to `sink` |
|
103 |
+ nblock <- length(x_grid) |
|
104 |
+ bplapply(seq_len(nblock), function(b) { |
|
105 |
+ if (DelayedArray:::get_verbose_block_processing()) { |
|
106 |
+ message("Processing block ", b, "/", nblock, " ... ", |
|
107 |
+ appendLF = FALSE) |
|
108 |
+ } |
|
109 |
+ x_viewport <- x_grid[[b]] |
|
110 |
+ sink_viewport <- sink_grid[[b]] |
|
111 |
+ block <- DelayedArray:::extract_block(x, x_viewport) |
|
112 |
+ if (!is.array(block)) { |
|
113 |
+ block <- DelayedArray:::.as_array_or_matrix(block) |
|
114 |
+ } |
|
115 |
+ attr(block, "from_grid") <- x_grid |
|
116 |
+ attr(block, "block_id") <- b |
|
117 |
+ block_ans <- FUN(block, ...) |
|
118 |
+ # NOTE: This is the only part different from DelayedArray::blockApply() |
|
119 |
+ if (!is.null(sink)) { |
|
120 |
+ write_block_to_sink(block_ans, sink, sink_viewport) |
|
121 |
+ block_ans <- NULL |
|
122 |
+ } |
|
123 |
+ if (DelayedArray:::get_verbose_block_processing()) { |
|
124 |
+ message("OK") |
|
125 |
+ } |
|
126 |
+ }, |
|
127 |
+ BPREDO = BPREDO, |
|
128 |
+ BPPARAM = BPPARAM) |
|
129 |
+} |
|
130 |
+ |
... | ... |
@@ -231,11 +231,12 @@ setMethod("findOverlaps", c("FWGRanges", "FWGRanges"), .findOverlaps_FWGRanges) |
231 | 231 |
# strand since no longer valid. |
232 | 232 |
dt[strand == "-", start := start - 1L][, strand := NULL] |
233 | 233 |
# Aggregate counts at loci with the same 'seqnames' and 'start'. |
234 |
- dt <- dt[, .(M = sum(M), U = sum(U)), by = c("seqnames", "start")] |
|
234 |
+ dt <- dt[, |
|
235 |
+ list(M = sum(M), U = sum(U)), by = c("seqnames", "start")] |
|
235 | 236 |
} |
236 | 237 |
# Identify loci with non-zero coverage then drop 'M' and 'U' as no |
237 | 238 |
# longer required. |
238 |
- dt <- dt[(M + U) > 0][, c("M", "U") := .(NULL, NULL)] |
|
239 |
+ dt <- dt[(M + U) > 0][, c("M", "U") := list(NULL, NULL)] |
|
239 | 240 |
} else { |
240 | 241 |
dt <- .readBismarkAsDT( |
241 | 242 |
file = file, |
... | ... |
@@ -42,7 +42,7 @@ setMethod( |
42 | 42 |
dim = c(nrow(x), length(idx)), |
43 | 43 |
dimnames = list(rownames(x), names(idx)), |
44 | 44 |
type = "double") |
45 |
- x_grid <- minfi:::colGrid(x) |
|
45 |
+ x_grid <- colGrid(x) |
|
46 | 46 |
sink_grid <- RegularArrayGrid( |
47 | 47 |
refdim = dim(sink), |
48 | 48 |
spacings = c(nrow(sink), ncol(sink) / length(x_grid))) |
... | ... |
@@ -53,7 +53,7 @@ setMethod( |
53 | 53 |
dimnames = list(names(idx), colnames(x)), |
54 | 54 |
type = "double") |
55 | 55 |
on.exit(close(sink)) |
56 |
- x_grid <- minfi:::rowGrid(x) |
|
56 |
+ x_grid <- rowGrid(x) |
|
57 | 57 |
sink_grid <- RegularArrayGrid( |
58 | 58 |
refdim = dim(sink), |
59 | 59 |
spacings = c(nrow(sink) / length(x_grid), ncol(sink))) |
... | ... |
@@ -62,7 +62,7 @@ setMethod( |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
# Loop over blocks of 'x' and write to 'sink'. |
65 |
- minfi:::blockApplyWithRealization( |
|
65 |
+ blockApplyWithRealization( |
|
66 | 66 |
x = x, |
67 | 67 |
FUN = .collapseMatrixLike, |
68 | 68 |
idx = idx, |
... | ... |
@@ -63,7 +63,7 @@ |
63 | 63 |
on.exit(close(sink)) |
64 | 64 |
|
65 | 65 |
# Set up ArrayGrid instance over columns of `sink`. |
66 |
- sink_grid <- minfi:::colGrid(sink) |
|
66 |
+ sink_grid <- colGrid(sink) |
|
67 | 67 |
|
68 | 68 |
# Loop over column grid of 'sink', identify samples required for that |
69 | 69 |
# block, bring that data into memory, pass down to .combineList_matrix(), |
... | ... |
@@ -184,7 +184,7 @@ |
184 | 184 |
# strand since no longer valid. |
185 | 185 |
dt[strand == "-", start := start - 1L][, strand := NULL] |
186 | 186 |
# Aggregate counts at loci with the same 'seqnames' and 'start'. |
187 |
- dt <- dt[, .(M = sum(M), U = sum(U)), by = c("seqnames", "start")] |
|
187 |
+ dt <- dt[, list(M = sum(M), U = sum(U)), by = c("seqnames", "start")] |
|
188 | 188 |
} |
189 | 189 |
|
190 | 190 |
# Construct FWGRanges ------------------------------------------------------ |
... | ... |
@@ -214,7 +214,7 @@ |
214 | 214 |
M <- matrix(rep(0L, length(loci)), ncol = 1) |
215 | 215 |
Cov <- matrix(rep(0L, length(loci)), ncol = 1) |
216 | 216 |
M[subjectHits(ol)] <- dt[queryHits(ol), ][["M"]] |
217 |
- Cov[subjectHits(ol)] <- dt[queryHits(ol), .(Cov = (M + U))][["Cov"]] |
|
217 |
+ Cov[subjectHits(ol)] <- dt[queryHits(ol), list(Cov = (M + U))][["Cov"]] |
|
218 | 218 |
|
219 | 219 |
# Return 'M' and 'Cov' or write them to the RealizationSink objects -------- |
220 | 220 |
|
... | ... |
@@ -241,9 +241,13 @@ |
241 | 241 |
Cov_sink <- NULL |
242 | 242 |
sink_lock <- NULL |
243 | 243 |
} else if (BACKEND == "HDF5Array") { |
244 |
+ if (!requireNamespace("HDF5Array", quietly = TRUE)) { |
|
245 |
+ stop("HDF5Array package required for HDF5Array backend", |
|
246 |
+ call. = FALSE) |
|
247 |
+ } |
|
244 | 248 |
# TODO: HDF5Array is only in suggests, so need to qualify the use of |
245 | 249 |
# HDF5RealizationSink() |
246 |
- M_sink <- HDF5RealizationSink( |
|
250 |
+ M_sink <- HDF5Array::HDF5RealizationSink( |
|
247 | 251 |
dim = c(ans_nrow, ans_ncol), |
248 | 252 |
# NOTE: Never allow dimnames. |
249 | 253 |
dimnames = NULL, |
... | ... |
@@ -255,7 +259,7 @@ |
255 | 259 |
# level = NULL, |
256 | 260 |
...) |
257 | 261 |
on.exit(close(M_sink), add = TRUE) |
258 |
- Cov_sink <- HDF5RealizationSink( |
|
262 |
+ Cov_sink <- HDF5Array::HDF5RealizationSink( |
|
259 | 263 |
dim = c(ans_nrow, ans_ncol), |
260 | 264 |
# NOTE: Never allow dimnames. |
261 | 265 |
dimnames = NULL, |
... | ... |
@@ -294,7 +298,7 @@ |
294 | 298 |
# bar. Only SnowParam (and MulticoreParam by inheritance) have a |
295 | 299 |
# bptasks<-() method. |
296 | 300 |
# TODO: Check that setting number of tasks doesn't affect things (e.g., |
297 |
- # the cost of transfering loci_dt to the workers may be substantial). |
|
301 |
+ # the cost of transfering loci to the workers may be substantial). |
|
298 | 302 |
if (is(BPPARAM, "SnowParam") && bpprogressbar(BPPARAM)) { |
299 | 303 |
bptasks(BPPARAM) <- length(grid) |
300 | 304 |
} |
... | ... |
@@ -445,8 +449,7 @@ read.bismark <- function(files, |
445 | 449 |
# backends. If the realization backend is NULL then an |
446 | 450 |
# ordinary matrix is returned rather than a matrix-backed |
447 | 451 |
# DelayedMatrix. |
448 |
- stop("The '", realization_backend, "' realization backend is ", |
|
449 |
- "not supported.\n", |
|
452 |
+ stop("The '", BACKEND, "' realization backend is not supported.\n", |
|
450 | 453 |
"See help(\"BSmooth\") for details.", |
451 | 454 |
call. = FALSE) |
452 | 455 |
} |
... | ... |
@@ -70,7 +70,7 @@ BSmooth(BSseq, |
70 | 70 |
|
71 | 71 |
The choice of realization backend is controlled by the \code{BACKEND} |
72 | 72 |
argument, which defaults to the current value of |
73 |
- \code{DelayedArray::\link[DelayedArray]{getRealizationBackend()}}. |
|
73 |
+ \code{DelayedArray::\link[DelayedArray]{getRealizationBackend}()}. |
|
74 | 74 |
|
75 | 75 |
\code{BSmooth} supports the following realization backends: |
76 | 76 |
|
... | ... |
@@ -82,9 +82,8 @@ BSseq(M = NULL, Cov = NULL, coef = NULL, se.coef = NULL, |
82 | 82 |
# |
83 | 83 |
|
84 | 84 |
library(HDF5Array) |
85 |
- # See ?HDF5Array::writeHDF5Array for details |
|
86 |
- hdf5_M <- writeHDF5Array(M) |
|
87 |
- hdf5_Cov <- writeHDF5Array(Cov) |
|
85 |
+ hdf5_M <- realize(M, "HDF5Array") |
|
86 |
+ hdf5_Cov <- realize(Cov, "HDF5Array") |
|
88 | 87 |
hdf5_BS1 <- BSseq(chr = c("chr1", "chr2", "chr1"), |
89 | 88 |
pos = c(1, 2, 3), |
90 | 89 |
M = hdf5_M, |
... | ... |
@@ -8,7 +8,8 @@ |
8 | 8 |
} |
9 | 9 |
\usage{ |
10 | 10 |
getCoverage(BSseq, regions = NULL, type = c("Cov", "M"), |
11 |
- what = c("perBase", "perRegionAverage", "perRegionTotal")) |
|
11 |
+ what = c("perBase", "perRegionAverage", "perRegionTotal"), |
|
12 |
+ withDimnames = TRUE) |
|
12 | 13 |
} |
13 | 14 |
\arguments{ |
14 | 15 |
\item{BSseq}{An object of class \code{BSseq}.} |
... | ... |
@@ -17,6 +18,10 @@ getCoverage(BSseq, regions = NULL, type = c("Cov", "M"), |
17 | 18 |
\item{type}{This returns either coverage or the total |
18 | 19 |
evidence for methylation at the loci.} |
19 | 20 |
\item{what}{The type of return object, see details.} |
21 |
+ \item{withDimnames}{A \code{logical(1)}, indicating whether dimnames should |
|
22 |
+ be applied to extracted coverage elements. Setting |
|
23 |
+ \code{withDimnames = FALSE} increases the speed and memory efficiency with |
|
24 |
+ which coverage is extracted.} |
|
20 | 25 |
} |
21 | 26 |
\value{ |
22 | 27 |
\strong{NOTE:} The return type of \code{getCoverage} varies depending on its |
... | ... |
@@ -8,7 +8,8 @@ |
8 | 8 |
} |
9 | 9 |
\usage{ |
10 | 10 |
getMeth(BSseq, regions = NULL, type = c("smooth", "raw"), |
11 |
- what = c("perBase", "perRegion"), confint = FALSE, alpha = 0.95) |
|
11 |
+ what = c("perBase", "perRegion"), confint = FALSE, alpha = 0.95, |
|
12 |
+ withDimnames = TRUE) |
|
12 | 13 |
} |
13 | 14 |
\arguments{ |
14 | 15 |
\item{BSseq}{An object of class \code{BSseq}.} |
... | ... |
@@ -20,6 +21,10 @@ getMeth(BSseq, regions = NULL, type = c("smooth", "raw"), |
20 | 21 |
methylation estimates (see below). This is only supported if |
21 | 22 |
\code{what} is equal to \code{perBase}.} |
22 | 23 |
\item{alpha}{alpha value for the confidence interval.} |
24 |
+ \item{withDimnames}{A \code{logical(1)}, indicating whether dimnames should |
|
25 |
+ be applied to extracted coverage elements. Setting |
|
26 |
+ \code{withDimnames = FALSE} increases the speed and memory efficiency with |
|
27 |
+ which coverage is extracted.} |
|
23 | 28 |
} |
24 | 29 |
\note{ |
25 | 30 |
A \code{BSseq} object needs to be smoothed by the function |
... | ... |
@@ -136,7 +136,7 @@ |
136 | 136 |
\section{Realization backends}{ |
137 | 137 |
The \code{read.bismark()} function creates a \linkS4class{BSseq} object with two assays, \code{M} and \code{Cov}. |
138 | 138 |
The choice of \emph{realization backend} controls whether these assays are stored in-memory as an ordinary \link[base]{matrix} or on-disk as a \linkS4class{HDF5Array}, for example. |
139 |
- The choice of realization backend is controlled by the \code{BACKEND} argument, which defaults to the current value of \code{DelayedArray::\link[DelayedArray]{getRealizationBackend()}}. |
|
139 |
+ The choice of realization backend is controlled by the \code{BACKEND} argument, which defaults to the current value of \code{DelayedArray::\link[DelayedArray]{getRealizationBackend}()}. |
|
140 | 140 |
|
141 | 141 |
\code{read.bismark()} supports the following realization backends: |
142 | 142 |
|
... | ... |
@@ -1,114 +1,5 @@ |
1 | 1 |
context("combine()") |
2 | 2 |
|
3 |
-# TODO: .subassignRowsDelayedMatrix() is no longer needed in bsseq; test can be |
|
4 |
-# removed. |
|
5 |
-# test_that(".subassignRowsDelayedMatrix()", { |
|
6 |
-# nrow <- 1000L |
|
7 |
-# ncol <- 10L |
|
8 |
-# x <- realize(matrix(seq_len(nrow * ncol), ncol = ncol), "HDF5Array") |
|
9 |
-# x_i <- seq(1L, 2L * nrow, 2L) |
|
10 |
-# y <- realize(matrix(seq(-1L, -nrow * ncol, -1L), ncol = 10), "HDF5Array") |
|
11 |
-# y_i <- seq(2L, nrow, 2L) |
|
12 |
-# |
|
13 |
-# z1 <- bsseq:::.subassignRowsDelayedMatrix(x = x, |
|
14 |
-# i = x_i, |
|
15 |
-# nrow = 2L * nrow, |
|
16 |
-# fill = NA_integer_, |
|
17 |
-# BACKEND = NULL) |
|
18 |
-# z2 <- bsseq:::.subassignRowsDelayedMatrix(x = x, |
|
19 |
-# i = x_i, |
|
20 |
-# nrow = 2L * nrow, |
|
21 |
-# fill = NA_integer_, |
|
22 |
-# BACKEND = "HDF5Array", |
|
23 |
-# by_row = FALSE) |
|
24 |
-# z3 <- bsseq:::.subassignRowsDelayedMatrix(x = x, |
|
25 |
-# i = x_i, |
|
26 |
-# nrow = 2L * nrow, |
|
27 |
-# fill = NA_integer_, |
|
28 |
-# BACKEND = "HDF5Array", |
|
29 |
-# by_row = TRUE) |
|
30 |
-# expect_identical(as.array(z1), as.array(z2)) |
|
31 |
-# expect_identical(as.array(z1), as.array(z3)) |
|
32 |
-# }) |
|
33 |
- |
|
34 |
-# TODO: .combineListOfDelayedMatrixObjects() is no longer needed in bsseq; test |
|
35 |
-# can be removed. |
|
36 |
-# test_that(".combineListOfDelayedMatrixObjects()", { |
|
37 |
-# nrow <- 10 |
|
38 |
-# ncol <- 4 |
|
39 |
-# x <- matrix(seq_len(nrow), |
|
40 |
-# ncol = ncol / 2, |
|
41 |
-# dimnames = list(NULL, letters[1:2])) |
|
42 |
-# y <- matrix(100L + seq_len(nrow), |
|
43 |
-# ncol = ncol / 2, |
|
44 |
-# dimnames = list(NULL, letters[3:4])) |
|
45 |
-# x_i <- seq(1, nrow, ncol / 2) |
|
46 |
-# y_i <- seq(2, nrow, ncol / 2) |
|
47 |
-# fill <- NA_integer_ |
|
48 |
-# |
|
49 |
-# # The expected output |
|
50 |
-# z <- matrix(fill, |
|
51 |
-# nrow = nrow, |
|
52 |
-# ncol = ncol, |
|
53 |
-# dimnames = list(NULL, letters[seq_len(ncol)])) |
|
54 |
-# # NOTE: as.array(x) is a no-op if x is a matrix and realises a |
|
55 |
-# # DelayedMtrix in memory |
|
56 |
-# z[x_i, seq(1, ncol(x))] <- x |
|
57 |
-# z[y_i, seq(ncol(x) + 1, ncol(x) + ncol(y))] <- y |
|
58 |
-# |
|
59 |
-# # # Test with in-memory DelayedMatrix objects |
|
60 |
-# X <- bsseq:::.DelayedMatrix(x) |
|
61 |
-# Y <- bsseq:::.DelayedMatrix(y) |
|
62 |
-# |
|
63 |
-# Z <- bsseq:::.combineListOfDelayedMatrixObjects( |
|
64 |
-# X = list(X, Y), |
|
65 |
-# I = list(x_i, y_i), |
|
66 |
-# nrow = nrow, |
|
67 |
-# ncol = ncol, |
|
68 |
-# dimnames = list(NULL, c(colnames(X), colnames(Y))), |
|
69 |
-# fill = fill, |
|
70 |
-# BACKEND = NULL) |
|
71 |
-# expect_identical(z, as.array(Z)) |
|
72 |
-# expect_true(!bsseq:::.isHDF5ArrayBacked(Z)) |
|
73 |
-# |
|
74 |
-# |
|
75 |
-# # Test with HDF5Array-backed DelayedMatrix objects |
|
76 |
-# hdf5_X <- realize(X, BACKEND = "HDF5Array") |
|
77 |
-# hdf5_Y <- realize(Y, BACKEND = "HDF5Array") |
|
78 |
-# |
|
79 |
-# hdf5_Z <- bsseq:::.combineListOfDelayedMatrixObjects( |
|
80 |
-# X = list(hdf5_X, hdf5_Y), |
|
81 |
-# I = list(x_i, y_i), |
|
82 |
-# nrow = nrow, |
|
83 |
-# ncol = ncol, |
|
84 |
-# dimnames = list(NULL, c(colnames(hdf5_X), colnames(hdf5_Y))), |
|
85 |
-# fill = fill, |
|
86 |
-# BACKEND = "HDF5Array") |
|
87 |
-# expect_identical(z, as.array(hdf5_Z)) |
|
88 |
-# expect_true(bsseq:::.isHDF5ArrayBacked(hdf5_Z)) |
|
89 |
-# }) |
|
90 |
- |
|
91 |
-checkBSseqAssaysIdentical <- function(x, y) { |
|
92 |
- stopifnot(is(x, "BSseq") && is(y, "BSseq")) |
|
93 |
- assay_names <- c("M", "Cov", "coef", "se.coef") |
|
94 |
- check_identical <- vapply(assay_names, function(an) { |
|
95 |
- if (!is.null(getBSseq(x, an))) { |
|
96 |
- identical(as.array(getBSseq(x, an)), as.array(getBSseq(y, an))) |
|
97 |
- } else { |
|
98 |
- identical(getBSseq(x, an), getBSseq(y, an)) |
|
99 |
- } |
|
100 |
- }, logical(1L)) |
|
101 |
- checkTrue(all(check_identical)) |
|
102 |
-} |
|
103 |
- |
|
104 |
-checkBSseqIdentical <- function(x, y) { |
|
105 |
- checkTrue(identical(rowRanges(x), rowRanges(y)) && |
|
106 |
- identical(getBSseq(x, "trans"), getBSseq(y, "trans")) && |
|
107 |
- identical(getBSseq(x, "parameters"), |
|
108 |
- getBSseq(y, "parameters")) && |
|
109 |
- checkBSseqAssaysIdentical(x, y)) |
|
110 |
-} |
|
111 |
- |
|
112 | 3 |
test_that("combine()", { |
113 | 4 |
bsseq_fit <- BSmooth(bsseq_test) |
114 | 5 |
BSSEQ_TEST <- realize(bsseq_test, "HDF5Array") |
... | ... |
@@ -168,6 +59,7 @@ test_that("combineList()", { |
168 | 59 |
Z <- combineList(BSSEQ_FIT[, 1], BSSEQ_FIT[, 2]) |
169 | 60 |
expect_equivalent_SE(Z, BSSEQ_FIT) |
170 | 61 |
}) |
62 |
+ |
|
171 | 63 |
test_that( |
172 | 64 |
"Test bug fix reported in https://github.com/hansenlab/bsseq/pull/54/", { |
173 | 65 |
M <- matrix(0:8, 3, 3) |