Skip to content

Commit

Permalink
Merge pull request #3 from PeteHaitch/master
Browse files Browse the repository at this point in the history
tile() and slidingWindows() now preserve names
  • Loading branch information
lawremi authored Mar 23, 2018
2 parents 68b2941 + ec68f1f commit f6e6f4c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Provides efficient low-level and highly reusable S4
neighbors. Defines efficient list-like classes for storing,
transforming and aggregating large grouped data, i.e., collections
of atomic vectors and DataFrames.
Version: 2.13.28
Version: 2.13.29
Encoding: UTF-8
Author: H. Pagès, P. Aboyoun and M. Lawrence
Maintainer: Bioconductor Package Maintainer <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions R/tile-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ setMethod("tile", "IntegerRanges", function(x, n, width, ...) {
rep(width, n))
tile.end.abs <- tile.end + rep(start(x), n) - 1L
tile.width <- S4Vectors:::diffWithInitialZero(as.integer(tile.end.abs))
p <- PartitioningByWidth(n)
p <- PartitioningByWidth(n, names = names(x))
tile.width[start(p)] <- tile.end[start(p)]
relist(IRanges(width=tile.width, end=tile.end.abs), p)
})
Expand Down Expand Up @@ -69,5 +69,5 @@ setMethod("slidingWindows", "IntegerRanges", function(x, width, step = 1L) {
windows <- restrict(IRanges(window.starts, width=width),
end=rep(width(x), n))
windows.abs <- shift(windows, rep(start(x), n) - 1L)
relist(windows.abs, PartitioningByWidth(n))
relist(windows.abs, PartitioningByWidth(n, names = names(x)))
})
5 changes: 5 additions & 0 deletions inst/unitTests/test_tile-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ test_tile <- function() {
checkException(tile(ir, n=4), silent=TRUE)
checkException(tile(ir, width=-1), silent=TRUE)
checkException(tile(ir, n=-1), silent=TRUE)
ir <- setNames(IRanges(1:3, width = 10), letters[1:3])
checkIdentical(names(ir), names(tile(ir, n = 2)))
checkIdentical(names(ir), names(tile(ir, width = 3)))
}

test_slidingWindows <- function() {
Expand All @@ -35,4 +38,6 @@ test_slidingWindows <- function() {
IRangesList(IRanges(c(1, 3), c(3, 5)),
IRanges(c(2, 4), c(4, 5)),
IRanges(3, 5)))
ir <- setNames(IRanges(1:3, width = 10), letters[1:3])
checkIdentical(names(ir), names(slidingWindows(ir, width = 3)))
}

0 comments on commit f6e6f4c

Please sign in to comment.