| Title: | Fast, Memory-Efficient Interval Operations for Genomics |
|---|---|
| Description: | Provides a fast, memory-efficient data structure for interval intersection queries using a novel superset-index approach. SuperIntervals maintains intervals in position-sorted order, enabling cache-friendly searches and SIMD-optimized counting operations. Chromosome- and strand-aware indexes support repeated genomic queries while retaining GRanges metadata. |
| Authors: | Kez Cleal [aut, cre] (ORCID: <https://orcid.org/0000-0002-9775-3476>) |
| Maintainer: | Kez Cleal <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.7 |
| Built: | 2026-10-14 18:54:12 UTC |
| Source: | https://github.com/BiocStaging/superintervalsr |
Access interval at specific index
## S3 method for class 'IntervalMap' x[i]## S3 method for class 'IntervalMap' x[i]
x |
IntervalMap object |
i |
Index (1-based in R) |
List with start, end, and value components
Add an interval to the map
add(x, start, end, value = NULL)add(x, start, end, value = NULL)
x |
IntervalMap object |
start |
Start position (inclusive) |
end |
End position (inclusive) |
value |
Associated value (optional) |
The IntervalMap object (invisibly)
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 15, 25, "gene2")im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 15, 25, "gene2")
Helper function to convert search_items results back to Bioconductor objects.
as_granges(items_result, seqname = "chr1", valuename = "value")as_granges(items_result, seqname = "chr1", valuename = "value")
items_result |
Result from search_items(), or a SuperIntervalMap. For an indexed genomic map, return its original GRanges with all metadata. |
seqname |
Chromosome name to assign (default: "chr1") |
valuename |
Value name to assign (default: "value") |
GRanges object
# Create an IntervalMap and search for items im <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("gene1", "gene2")) items <- search_items(im, 3, 12) # Convert result back to GRanges gr <- as_granges(items, seqname = "chr1", valuename = "gene_id") print(gr)# Create an IntervalMap and search for items im <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("gene1", "gene2")) items <- search_items(im, 3, 12) # Convert result back to GRanges gr <- as_granges(items, seqname = "chr1", valuename = "gene_id") print(gr)
Get interval at specific index
at(x, idx)at(x, idx)
x |
IntervalMap object |
idx |
Index position (1-based) |
List with start, end, and value components
im <- IntervalMap() add(im, 1, 10, "gene1") build(im) at(im, 1)im <- IntervalMap() add(im, 1, 10, "gene1") build(im) at(im, 1)
Must be called after adding intervals and before performing queries. Sorts by start ascending and end descending within tied starts. Accessor and search indices refer to this order.
build(x)build(x)
x |
IntervalMap object |
The IntervalMap object (invisibly)
im <- IntervalMap() add(im, 1, 10, "gene1") build(im)im <- IntervalMap() add(im, 1, 10, "gene1") build(im)
Clear all intervals
clear(x)clear(x)
x |
IntervalMap object |
The IntervalMap object (invisibly)
The IntervalMap object (invisibly)
im <- IntervalMap() add(im, 1, 10, "gene1") clear(im)im <- IntervalMap() add(im, 1, 10, "gene1") clear(im)
Count overlapping intervals
count(x, start, end)count(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
Number of overlapping intervals
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) count(im, 7, 12) # 2im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) count(im, 7, 12) # 2
Count overlaps for multiple ranges
count.batch(x, starts, ends)count.batch(x, starts, ends)
x |
IntervalMap object |
starts |
Vector of query start positions |
ends |
Vector of query end positions |
Integer vector of overlap counts, one per query
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") add(im, 20, 30, "gene3") build(im) count.batch(im, c(7, 25), c(12, 35)) # c(2, 1)im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") add(im, 20, 30, "gene3") build(im) count.batch(im, c(7, 25), c(12, 35)) # c(2, 1)
Get coverage statistics for a range
coverage(x, start, end)coverage(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
total_coverage sums the inclusive widths of each intersection
with the query. Overlapping stored intervals are counted independently;
this is not the width of their union or an IRanges coverage Rle.
List with integer count and numeric total_coverage
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) coverage(im, 1, 20) # Returns list with coverage statisticsim <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) coverage(im, 1, 20) # Returns list with coverage statistics
Get data at specific index
data_at(x, idx)data_at(x, idx)
x |
IntervalMap object |
idx |
Index position (1-based) |
Associated data value
Associated data value at the specified index
im <- IntervalMap() add(im, 1, 10, "gene1") build(im) data_at(im, 1) # Returns "gene1"im <- IntervalMap() add(im, 1, 10, "gene1") build(im) data_at(im, 1) # Returns "gene1"
Returns a new IntervalMap of regions in x that are not covered by y.
difference(x, y)difference(x, y)
x |
IntervalMap object (A) |
y |
IntervalMap object (B) |
A new IntervalMap representing A \ B
a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) d <- difference(a, b)a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) d <- difference(a, b)
Get end position at specific index
ends_at(x, idx)ends_at(x, idx)
x |
IntervalMap object |
idx |
Index position (1-based) |
End position
Integer end position of the interval
im <- IntervalMap() add(im, 1, 10, "gene1") build(im) ends_at(im, 1) # Returns 10im <- IntervalMap() add(im, 1, 10, "gene1") build(im) ends_at(im, 1) # Returns 10
Grows (or shrinks) every interval by a fixed amount. Results are clamped
to [lo, hi]. Intervals shrunk past themselves are dropped.
expand(x, left, right, lo = 0L, hi = 2147483647L)expand(x, left, right, lo = 0L, hi = 2147483647L)
x |
IntervalMap object |
left |
Amount to subtract from each start (extends to the left). May be negative. |
right |
Amount to add to each end (extends to the right). May be negative. |
lo |
Lower clamp (default is 0) |
hi |
Upper clamp (default is the maximum 32-bit integer) |
A new IntervalMap with expanded intervals
im <- IntervalMap(c(10, 50), ends = c(20, 60), values = c("A", "B")) expanded <- expand(im, 5, 5)im <- IntervalMap(c(10, 50), ends = c(20, 60), values = c("A", "B")) expanded <- expand(im, 5, 5)
Query an indexed genomic subject
## S4 method for signature 'GRanges,SuperIntervalMap' findOverlaps( query, subject, maxgap = -1L, minoverlap = 0L, type = c("any", "start", "end", "within", "equal"), select = c("all", "first", "last", "arbitrary"), ignore.strand = FALSE ) ## S4 method for signature 'GRanges,SuperIntervalMap' countOverlaps( query, subject, maxgap = -1L, minoverlap = 0L, type = c("any", "start", "end", "within", "equal"), ignore.strand = FALSE )## S4 method for signature 'GRanges,SuperIntervalMap' findOverlaps( query, subject, maxgap = -1L, minoverlap = 0L, type = c("any", "start", "end", "within", "equal"), select = c("all", "first", "last", "arbitrary"), ignore.strand = FALSE ) ## S4 method for signature 'GRanges,SuperIntervalMap' countOverlaps( query, subject, maxgap = -1L, minoverlap = 0L, type = c("any", "start", "end", "within", "equal"), ignore.strand = FALSE )
query |
A GRanges of query features. |
subject |
A SuperIntervalMap constructed once from the subject GRanges. |
maxgap, minoverlap, type, select
|
Overlap options, as in
|
ignore.strand |
Whether to ignore strand (default FALSE). |
findOverlaps() returns a Hits object with indices in the original
input order, or a subject-index vector when select is not "all".
countOverlaps() returns one integer count per query feature.
library(GenomicRanges) subject <- GRanges(c("chr1", "chr2"), IRanges(c(1, 10), c(5, 20))) query <- GRanges(c("chr1", "chr2"), IRanges(c(3, 15), c(8, 18))) index <- SuperIntervalMap(subject) hits <- findOverlaps(query, index) as_granges(index)[subjectHits(hits)] countOverlaps(query, index)library(GenomicRanges) subject <- GRanges(c("chr1", "chr2"), IRanges(c(1, 10), c(5, 20))) query <- GRanges(c("chr1", "chr2"), IRanges(c(3, 15), c(8, 18))) index <- SuperIntervalMap(subject) hits <- findOverlaps(query, index) as_granges(index)[subjectHits(hits)] countOverlaps(query, index)
Returns a new IntervalMap containing only the flanking intervals, not the
originals. Left flanks are [start - left, start - 1] and right flanks
are [end + 1, end + right]. Zero-width or out-of-range flanks are
skipped.
flank(x, left, right, lo = 0L, hi = 2147483647L)flank(x, left, right, lo = 0L, hi = 2147483647L)
x |
IntervalMap object |
left |
Width of the left flank (0 = none) |
right |
Width of the right flank (0 = none) |
lo |
Lower clamp (default is 0) |
hi |
Upper clamp (default is the maximum 32-bit integer) |
A new IntervalMap containing the flank intervals
im <- IntervalMap(c(10, 50), ends = c(20, 60), values = c("A", "B")) f <- flank(im, 5, 5)im <- IntervalMap(c(10, 50), ends = c(20, 60), values = c("A", "B")) f <- flank(im, 5, 5)
Returns uncovered regions within the supplied range as a new IntervalMap.
Gap intervals are assigned the value given by fill (default NULL).
gaps(x, lo, hi, fill = NULL)gaps(x, lo, hi, fill = NULL)
x |
IntervalMap object |
lo |
Lower bound of the span to examine (inclusive) |
hi |
Upper bound of the span to examine (inclusive) |
fill |
Value to assign to gap intervals |
A new IntervalMap of gap intervals
im <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("A", "B")) g <- gaps(im, 0, 20)im <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("A", "B")) g <- gaps(im, 0, 20)
Check if any intervals overlap with a range
has_overlaps(x, start, end)has_overlaps(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
TRUE if any intervals overlap, FALSE otherwise
im <- IntervalMap() add(im, 1, 10, "gene1") build(im) has_overlaps(im, 5, 15) # TRUEim <- IntervalMap() add(im, 1, 10, "gene1") build(im) has_overlaps(im, 5, 15) # TRUE
Returns a new IntervalMap of regions covered by both inputs.
Output pieces are not coalesced; call merge_overlaps() on the result
if a disjoint set is required. Each piece keeps the value from x.
intersection(x, y)intersection(x, y)
x |
IntervalMap object |
y |
IntervalMap object |
A new IntervalMap representing the intersection
a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) i <- intersection(a, b)a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) i <- intersection(a, b)
Creates a new IntervalMap object for storing and querying intervals efficiently. This function uses method dispatch to automatically handle different input types.
IntervalMap(x, ...) ## Default S3 method: IntervalMap(x = NULL, ...) ## S3 method for class 'integer' IntervalMap(x, ends, values = NULL, ...) ## S3 method for class 'numeric' IntervalMap(x, ends, values = NULL, ...) ## S3 method for class 'GRanges' IntervalMap(x, value_column = NULL, seqname = NULL, ...) ## S3 method for class 'data.frame' IntervalMap( x, start_column = "start", end_column = "end", value_column = NULL, ... )IntervalMap(x, ...) ## Default S3 method: IntervalMap(x = NULL, ...) ## S3 method for class 'integer' IntervalMap(x, ends, values = NULL, ...) ## S3 method for class 'numeric' IntervalMap(x, ends, values = NULL, ...) ## S3 method for class 'GRanges' IntervalMap(x, value_column = NULL, seqname = NULL, ...) ## S3 method for class 'data.frame' IntervalMap( x, start_column = "start", end_column = "end", value_column = NULL, ... )
x |
Input object. Can be missing (creates empty map), GRanges, data.frame, or integer vector of starts |
... |
Additional arguments passed to specific methods |
ends |
Integer vector of end positions (when x is numeric vector of starts) |
values |
Optional list of values to associate with each interval |
value_column |
Name of column to use as values (default: use all other columns as named list) |
seqname |
Optional chromosome name to filter to (e.g., "chr1") |
start_column |
Name of start column (default: "start") |
end_column |
Name of end column (default: "end") |
Coordinates are closed (both endpoints inclusive) whole numbers in
the R integer range, excluding NA. A map stores one coordinate space and
ignores strand. Multi-sequence GRanges require an explicit seqname filter.
Constructors build the index automatically. After add(), call build()
before querying; queries do not check index state or validate coordinates.
Query inputs must be valid whole-number ranges. Build sorts by start
ascending, then end descending;
indices refer to this internal order, not the original input row order.
Query result order is unspecified. Store original row IDs as values when
mapping hits back to input data. Mutation operates by reference, so
assignment
does not copy a map. External pointers cannot be restored with
saveRDS/readRDS;
save coordinates and values and recreate the map instead.
An IntervalMap object
# Create empty IntervalMap im1 <- IntervalMap() # Create from GRanges library(GenomicRanges) gr <- GRanges("chr1", IRanges(c(1, 10), c(5, 15)), gene_id = c("A", "B")) im2 <- IntervalMap(gr, value_column = "gene_id") # Create from data.frame df <- data.frame(start = c(1, 10), end = c(5, 15), gene = c("A", "B")) im3 <- IntervalMap(df, value_column = "gene") # Create from vectors im4 <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("gene1", "gene2"))# Create empty IntervalMap im1 <- IntervalMap() # Create from GRanges library(GenomicRanges) gr <- GRanges("chr1", IRanges(c(1, 10), c(5, 15)), gene_id = c("A", "B")) im2 <- IntervalMap(gr, value_column = "gene_id") # Create from data.frame df <- data.frame(start = c(1, 10), end = c(5, 15), gene = c("A", "B")) im3 <- IntervalMap(df, value_column = "gene") # Create from vectors im4 <- IntervalMap(c(1, 10), ends = c(5, 15), values = c("gene1", "gene2"))
Get the length of an IntervalMap
## S3 method for class 'IntervalMap' length(x)## S3 method for class 'IntervalMap' length(x)
x |
IntervalMap object |
Number of intervals in the map
Returns a new IntervalMap where overlapping intervals are coalesced. The data value of the first interval in coordinate order is kept. Adjacent intervals that do not overlap are not merged. Ties are unspecified.
merge_overlaps(x)merge_overlaps(x)
x |
IntervalMap object |
A new IntervalMap with merged intervals
im <- IntervalMap(c(1, 5), ends = c(10, 15), values = c("A", "B")) merged <- merge_overlaps(im) length(merged) # 1im <- IntervalMap(c(1, 5), ends = c(10, 15), values = c("A", "B")) merged <- merge_overlaps(im) length(merged) # 1
Print method for IntervalMap
## S3 method for class 'IntervalMap' print(x, ...)## S3 method for class 'IntervalMap' print(x, ...)
x |
IntervalMap object |
... |
Additional arguments (ignored) |
Invisibly returns the IntervalMap object
Reserve space for intervals
reserve(x, n)reserve(x, n)
x |
IntervalMap object |
n |
Number of intervals to reserve space for |
The IntervalMap object (invisibly)
The IntervalMap object (invisibly)
im <- IntervalMap() reserve(im, 1000) # Pre-allocate space for 1000 intervalsim <- IntervalMap() reserve(im, 1000) # Pre-allocate space for 1000 intervals
Search for indices of overlapping intervals
search_idxs(x, start, end)search_idxs(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
Integer vector of 1-based indices
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_idxs(im, 7, 12) # c(1, 2)im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_idxs(im, 7, 12) # c(1, 2)
Search for indices of overlapping intervals for multiple query ranges simultaneously. This is more efficient than calling search_idxs multiple times.
search_idxs.batch(x, starts, ends)search_idxs.batch(x, starts, ends)
x |
IntervalMap object |
starts |
Integer vector of query start positions (inclusive) |
ends |
Integer vector of query end positions (inclusive) |
List of integer vectors, where each element contains the 1-based indices of intervals that overlap with the corresponding query range
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") add(im, 20, 30, "gene3") build(im) # Search multiple ranges at once result <- search_idxs.batch(im, c(7, 25), c(12, 35)) # Returns list(c(1, 2), c(3))im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") add(im, 20, 30, "gene3") build(im) # Search multiple ranges at once result <- search_idxs.batch(im, c(7, 25), c(12, 35)) # Returns list(c(1, 2), c(3))
Search for complete items (start, end, value) of overlapping intervals
search_items(x, start, end)search_items(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
List with start, end, and value vectors
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_items(im, 7, 12)im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_items(im, 7, 12)
Search for keys (start, end pairs) of overlapping intervals
search_keys(x, start, end)search_keys(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
List with start and end vectors
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_keys(im, 7, 12) # list(start=c(1,5), end=c(10,15))im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_keys(im, 7, 12) # list(start=c(1,5), end=c(10,15))
Returns all values associated with intervals that contain the given point.
search_point(x, point)search_point(x, point)
x |
IntervalMap object |
point |
Position to query (inclusive) |
List of values from intervals containing point
im <- IntervalMap() add(im, 1, 10, "A") add(im, 5, 15, "B") build(im) search_point(im, 5) # list("A", "B")im <- IntervalMap() add(im, 1, 10, "A") add(im, 5, 15, "B") build(im) search_point(im, 5) # list("A", "B")
Search for values in overlapping intervals
search_values(x, start, end)search_values(x, start, end)
x |
IntervalMap object |
start |
Start of query range (inclusive) |
end |
End of query range (inclusive) |
List of values from overlapping intervals
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_values(im, 7, 12) # list("gene1", "gene2")im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 5, 15, "gene2") build(im) search_values(im, 7, 12) # list("gene1", "gene2")
Get number of intervals
size(x)size(x)
x |
IntervalMap object |
Number of intervals
Integer number of intervals in the map
im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 20, 30, "gene2") size(im) # Returns 2im <- IntervalMap() add(im, 1, 10, "gene1") add(im, 20, 30, "gene2") size(im) # Returns 2
Returns the smallest interval enclosing every stored interval.
span(x)span(x)
x |
IntervalMap object |
A list with start and end, or NULL if the map is empty
im <- IntervalMap(c(1, 10), ends = c(5, 20), values = c("A", "B")) span(im) # list(start = 1, end = 20)im <- IntervalMap(c(1, 10), ends = c(5, 20), values = c("A", "B")) span(im) # list(start = 1, end = 20)
Get start position at specific index
starts_at(x, idx)starts_at(x, idx)
x |
IntervalMap object |
idx |
Index position (1-based) |
Start position
Integer start position of the interval
im <- IntervalMap() add(im, 1, 10, "gene1") build(im) starts_at(im, 1) # Returns 1im <- IntervalMap() add(im, 1, 10, "gene1") build(im) starts_at(im, 1) # Returns 1
Create an indexed genomic subject
SuperIntervalMap(x)SuperIntervalMap(x)
x |
A GRanges containing subject features, possibly on multiple sequences and strands. Coordinates, names, seqinfo and metadata are preserved. |
Hits refer to the original subject row order. Strand matching
follows
GenomicRanges: "*" matches either strand, and ignore.strand = TRUE
ignores strand entirely. Ordinary positive-width overlaps use
SuperIntervals.
Queries involving zero-width ranges, a non-default gap or overlap
threshold,
or a type other than "any" delegate to GenomicRanges to preserve its
semantics. The object stores one index per sequence, with strand filtering
performed in C++. Query functions assume the indexes are
current; do not alter the slots after construction.
Like IntervalMap, the indexes contain external pointers. Save
as_granges(x) and reconstruct the index after loading serialized data.
A SuperIntervalMap S4 object for use as the subject of
findOverlaps() and countOverlaps(). as_granges() retrieves the
original
GRanges, and length() returns its number of features.
library(GenomicRanges) genes <- GRanges(c("chr1", "chr2", "chr1"), IRanges(c(20, 1, 1), c(30, 10, 10)), strand = c("+", "-", "*"), gene_id = c("C", "B", "A")) index <- SuperIntervalMap(genes) query <- GRanges(c("chr1", "chr2"), IRanges(c(5, 5), c(25, 8)), strand = c("+", "+")) findOverlaps(query, index) countOverlaps(query, index, ignore.strand = TRUE) as_granges(index)library(GenomicRanges) genes <- GRanges(c("chr1", "chr2", "chr1"), IRanges(c(20, 1, 1), c(30, 10, 10)), strand = c("+", "-", "*"), gene_id = c("C", "B", "A")) index <- SuperIntervalMap(genes) query <- GRanges(c("chr1", "chr2"), IRanges(c(5, 5), c(25, 8)), strand = c("+", "+")) findOverlaps(query, index) countOverlaps(query, index, ignore.strand = TRUE) as_granges(index)
Index a GRanges once for repeated chromosome- and strand-aware overlap queries. The original ranges, sequence information, names and metadata are retained.
## S4 method for signature 'SuperIntervalMap' length(x) ## S4 method for signature 'SuperIntervalMap' show(object)## S4 method for signature 'SuperIntervalMap' length(x) ## S4 method for signature 'SuperIntervalMap' show(object)
x, object
|
An indexed genomic map. |
The S4 class stores indexed GRanges. Its length method returns an integer feature count; show prints a summary and returns invisible NULL.
rangesThe original GRanges, in input order.
indexInternal per-sequence indexes. Do not edit slots; construct a new object when the subject ranges change.
Returns a new IntervalMap of regions covered by exactly one of the inputs.
symmetric_difference(x, y)symmetric_difference(x, y)
x |
IntervalMap object |
y |
IntervalMap object |
A new IntervalMap representing the symmetric difference
a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) sd <- symmetric_difference(a, b)a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) sd <- symmetric_difference(a, b)
Returns a new IntervalMap covering all regions covered by either input. The data value of the first interval in coordinate order is kept. Adjacent intervals that do not overlap are not merged. Ties are unspecified.
union_with(x, y)union_with(x, y)
x |
IntervalMap object |
y |
IntervalMap object |
A new IntervalMap representing the union
a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) u <- union_with(a, b)a <- IntervalMap(c(1, 20), ends = c(10, 30), values = c("A", "B")) b <- IntervalMap(c(5, 25), ends = c(15, 35), values = c("C", "D")) u <- union_with(a, b)
Returns a new IntervalMap keeping only one interval per distinct
(start, end) coordinate pair. One duplicate's data value is kept;
the choice among tied duplicates is unspecified.
unique_intervals(x)unique_intervals(x)
x |
IntervalMap object |
A new IntervalMap with duplicates removed
im <- IntervalMap(c(1, 1, 10), ends = c(5, 5, 15), values = c("A", "B", "C")) u <- unique_intervals(im) length(u) # 2im <- IntervalMap(c(1, 1, 10), ends = c(5, 5, 15), values = c("A", "B", "C")) u <- unique_intervals(im) length(u) # 2