Skip to content

Incorrect foverlaps with (1) infinite and (2) same interval limits #1006

@tdhock

Description

@tdhock

First of all thank you very much for the great foverlaps function, which I find very useful in my work in genomics and model selection.

(1) But I noticed some problems with the output. In particular please see the code below which contains a reference interval (-Inf, -0.1) which apparently can never be returned by foverlaps.

(2) Another issue is the fact that when the query/x parameter has the same upper and lower limit, I have to do subset(dt, start < query & query < end) to get the desired result.

These two issues are bugs, right?

works_with_R("3.1.2", data.table="1.9.4")

x <- c(-0.1, 0, 0.1)
n <- length(x)
dt.ref <- data.table(start=x[-n], end=x[-1])
setkey(dt.ref, start, end)
q <- c(-0.2, -0.05, 0.05, 0.15)
## query interval has the same lower and upper limit.
dt.query <- data.table(q1=q, q2=q)
setkey(dt.query, q1, q2)

ov <- foverlaps(dt.query, dt.ref)
## (2) Why do I have to do the subset below to get the expected result?
expected <- subset(ov, start < q1 & q1 < end)

## Same query as above, but a reference that has two more intervals,
## with infinite values.
x <- c(-Inf, -0.1, 0, 0.1, Inf)
n <- length(x)
dt.ref <- data.table(start=x[-n], end=x[-1])
setkey(dt.ref, start, end)
q <- c(-0.2, -0.05, 0.05, 0.15)
dt.query <- data.table(q1=q, q2=q)
setkey(dt.query, q1, q2)

ov <- foverlaps(dt.query, dt.ref)
result <- subset(ov, start < q1 & q1 < end)
stopifnot(nrow(result) == 4)
## (1) There should be a row with (start=-Inf, end=-0.1, q1=q2=-0.2), but
## there is not! Why?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions