interval_overlap {intervals}R Documentation

Assess which query intervals overlap which targets

Description

Given two objects, a set of query intervals and a set of targets, assess which query intervals, if any, overlap each target.

Usage

## S4 method for signature 'Intervals_virtual,
##   Intervals_virtual':
interval_overlap(target, query, check_valid = TRUE)

## S4 method for signature 'Intervals_virtual, numeric':
interval_overlap(target, query, check_valid = TRUE)

Arguments

target An "Intervals" or "Intervals_full" object. The target object must have the same type as query, unless query is of type "numeric".
query An "Intervals" or "Intervals_full" object. If a numeric vector is supplied instead, the function checks to see which points are included in the targets.
check_valid Should validObject be called before passing to compiled code? This, among other things, verifies that endpoints are of data type numeric and the closed vector/matrix is appropriately sized and of the correct data type. (Compiled code does no further checking.)

Details

Intervals which meet at endpoints overlap only if both endpoints are closed. Intervals in query with NA endpoints are ignored, with a warning; in target, such intervals produce no matches. Intervals in either query or target which are actually empty have their endpoints set to NA before proceeding, with warning, and so do not generate matches. If query is of type "numeric" and type(target) is "Z", then non-integer entries of query will be set to NA, with warning.

Value

A list, with one element for each row of target. The elements are vectors of indices, indicating which query rows (or query components, for the "numeric" method) overlap each target. A list element of length 0 indicates a target with no overlapping query elements.

Note

If you want real (type = "R") intervals that overlap in a set of positive measure – not just at endpoints – set all endpoints to open (i.e., closed(query) <- FALSE) first.

Examples

# Note that t contains a valid but empty interval.

q <- Intervals(
               matrix(
                      c(
                        2,  8,
                        3,  4,
                        5, 10
                        ),
                      ncol = 2, byrow = TRUE
                      ),
               closed = c( TRUE, FALSE ),
               type = "Z"
               )

t <- Intervals(
               matrix(
                      c(
                         2,  8,
                         8,  9,
                         6,  9,
                        11, 12,
                         3,  3
                        ),
                      ncol = 2, byrow = TRUE
                      ),
               closed = c( TRUE, FALSE ),
               type = "Z"
               )
rownames(t) <- letters[1:nrow(t)]

empty(q)
empty(t)

interval_overlap(t, q)

# Non-empty real intevals of size 0 can overlap other intervals.

u <- q
type(u) <- "R"

v <- Intervals_full( rep(3,4) )
closed(v)[2,] <- FALSE
v
empty(v)
size(v)

interval_overlap(v, u)

# Querying points

interval_overlap( t, c( 2, 3, 6, NA ) )

# Non-integer points dropped for targets over Z

interval_overlap( q, c( 2, 2.5, 3 ) )
interval_overlap( u, c( 2, 2.5, 3 ) )

[Package intervals version 0.10.3 Index]