Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tile() and slidingWindows() now preserve names #3

Merged
merged 2 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
}