interval_overlap {intervals}R Documentation

Assess which query intervals overlap which targets

Description

Given two objects, a query and a target, assess which query intervals overlap which targets.

Usage

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

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

Arguments

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 intervals of target.
target An "Intervals" or "Intervals_full" object. The target object must have the same type as query.
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 interval 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.

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 intervals.

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(q, t)

# 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( u, v )

# Querying points

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

[Package intervals version 0.9.5 Index]