Title: | Operating on Integer-Bounded Intervals |
---|---|
Description: | Manipulate integer-bounded intervals including finding overlaps, piling and merging. |
Authors: | Daniel Greene |
Maintainer: | Daniel Greene <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.3 |
Built: | 2025-02-15 02:38:46 UTC |
Source: | https://github.com/cran/IntervalSurgeon |
Manipulate integer-bounded intervals including finding overlaps, piling and merging.
The DESCRIPTION file:
Package: | IntervalSurgeon |
Type: | Package |
Title: | Operating on Integer-Bounded Intervals |
Encoding: | UTF-8 |
Version: | 1.3 |
Date: | 2024-02-20 |
Author: | Daniel Greene |
Maintainer: | Daniel Greene <[email protected]> |
Description: | Manipulate integer-bounded intervals including finding overlaps, piling and merging. |
License: | GPL (>= 2) |
Imports: | Rcpp (>= 0.12.4) |
LinkingTo: | Rcpp |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
RoxygenNote: | 7.3.1 |
NeedsCompilation: | yes |
Packaged: | 2024-02-20 22:08:31 UTC; dg |
Date/Publication: | 2024-02-20 22:30:02 UTC |
Repository: | https://daniel-jg.r-universe.dev |
RemoteUrl: | https://github.com/cran/IntervalSurgeon |
RemoteRef: | HEAD |
RemoteSha: | 97466dba4926f822d886ca2a2c6178ed758339a1 |
Index of help topics:
IntervalSurgeon-package Operating on Integer-Bounded Intervals annotate Annotate one set of intervals with the names of those which intersect with the other breaks Get break points for set of intervals depth Depth of piled intervals detached_sorted_nonempty Check intervals are detached, sorted and non-empty. flatten Flatten a set of intervals intersected Determine whether each interval in a given set are intersected/covered by intervals in another set join Get all overlapping tuples of intervals from multiple sets overlaps Compute overlaps of two sets of detached and sorted intervals pile Get IDs of intervals covering each sub-interval proportion_overlap Calculate proportion overlapping of intersecting intervals sections Get the sections from a set of interval breaks stitch Stich together touching intervals and remove empty intervals
Further information is available in the following vignettes:
intro |
Usage (source, pdf) |
IntervalSurgeon presents functions for manipulating integer-bounded sets of intervals.
Sets of intervals are represented by two-column matrices, where inclusive start points are stored in the first column, and exclusive end points in the second.
A central concept in the package is the ‘sections’ of a set of intervals x
: the non-overlapping, completely-covering set of intervals on the range of x
, formed by making intervals between the consecutive sorted start/end points of the intevals in x
.
The function sections
returns such a set of intervals given an input set.
Daniel Greene
Maintainer: Daniel Greene <[email protected]>
Create a list of vectors of indices/names of intervals/points in annotation
(if annotation
is a two-column matrix/vector respectively) which intersect with each interval/point in x
(if x
is a two-column matrix/vector respectively).
annotate(x, annotation)
annotate(x, annotation)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points, or, an integer vector specifying the location of points. |
annotation |
Matrix specifying intervals or vector specifying points with which to annotate |
List of vectors of indices of overlapping intervals/points.
annotate(rbind(A=c(1, 100), B=c(50, 100)), rbind(a=c(1, 2), b=c(49, 51), c=c(50, 200))) annotate(rbind(A=c(1, 100), B=c(50, 100)), c(a=1, b=49, c=51, d=100))
annotate(rbind(A=c(1, 100), B=c(50, 100)), rbind(a=c(1, 2), b=c(49, 51), c=c(50, 200))) annotate(rbind(A=c(1, 100), B=c(50, 100)), c(a=1, b=49, c=51, d=100))
Get the sorted set start points and end points for a set of intervals specified as an integer matrix.
breaks(x)
breaks(x)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
Ordered integer vector of unique interval start/end points.
breaks(cbind(2*1:5, 3*1:5))
breaks(cbind(2*1:5, 3*1:5))
Get the depth of piled intervals for each section in the sections of x
(see sections
).
depth(x, include_intervals = FALSE)
depth(x, include_intervals = FALSE)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
include_intervals |
Logical value determining whether the function should return a vector of depths at each ‘section’ in the range of |
Integer vector giving depth of piled intervals from x
(within each sub-interval) or list containing a property "intervals"
, a matrix of sections, and property "depths"
, giving the corresponding pile depths.
depth(cbind(1:10, 11:20))
depth(cbind(1:10, 11:20))
Check that x
is an integer matrix specifying intervals, that the specified intervals are detached (i.e. non-overlapping/disjoint and non-touching) and that it is sorted (given that the intervals are detached, sorting by start position gives a unique result), and that the start points are greater than the end points (i.e. that they are non-empty/the lengths of all intervals is greater than zero).
detached_sorted_nonempty(x)
detached_sorted_nonempty(x)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
Boolean value.
detached_sorted_nonempty(cbind(1:2, 2:3)) detached_sorted_nonempty(cbind(c(1, 3), c(2, 4))) detached_sorted_nonempty(cbind(1, 1))
detached_sorted_nonempty(cbind(1:2, 2:3)) detached_sorted_nonempty(cbind(c(1, 3), c(2, 4))) detached_sorted_nonempty(cbind(1, 1))
For a given set of intervals compute the set of intervals where there is overlap with at least one from the given. The resulting intervals are sorted and detached.
flatten(x)
flatten(x)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
Intervals represented by integer matrix of two columns.
flatten(rbind(c(1, 3), c(2, 4), c(5, 6)))
flatten(rbind(c(1, 3), c(2, 4), c(5, 6)))
Compute a logical vector indicating whether corresponding intervals specified by x
overlap (intersected
)/are covered by (covered
) those in by_intervals
.
intersected(x, by_intervals) covered(x, by_intervals)
intersected(x, by_intervals) covered(x, by_intervals)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points, or, an integer vector specifying the location of points. |
by_intervals |
Matrix specifying intervals to test for intersection of. |
Logical vector with elements corresponding to rows of x
.
intersected(rbind(c(1, 2), c(49, 51), c(50, 200)), rbind(c(50, 100))) covered(rbind(c(1, 10), c(49, 51), c(50, 200)), rbind(c(2, 60)))
intersected(rbind(c(1, 2), c(49, 51), c(50, 200)), rbind(c(50, 100))) covered(rbind(c(1, 10), c(49, 51), c(50, 200)), rbind(c(2, 60)))
Get matrix specifying overlapping tuples of intervals from multiple sets. Each row specifies an overlapping tuple. The n
th element in a row contains the row index of the interval in the n
th set of intervals passed to the function. Depending on the value of the output
argument, there may two additional columns giving the start and end coordinates of the overlap (the default: output="intervals"
, no extra columns (output="indices"
) or one additional column giving the row index of the 'section' of the complete set of intervals (output="sections"
, see sections
).
join(..., output = "intervals")
join(..., output = "intervals")
... |
Integer matrices of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
output |
Character value, one of |
Integer matrix.
join(rbind(c(1, 100), c(50, 100)), rbind(c(1, 2), c(49, 51), c(50, 200)))
join(rbind(c(1, 100), c(50, 100)), rbind(c(1, 2), c(49, 51), c(50, 200)))
Find intervals satisfying particular conditions, including corresponding base R functions intersect
(i.e. find intersections of intervals), union
(i.e. unions of intervals) and setdiff
(i.e. finding intervals which are contained in one set of intervals but not another).
overlaps(x, y, check = TRUE, in_x = TRUE, in_y = TRUE, op = "and") intersects(x, y, ...) unions(x, y, ...) setdiffs(x, y, ...)
overlaps(x, y, check = TRUE, in_x = TRUE, in_y = TRUE, op = "and") intersects(x, y, ...) unions(x, y, ...) setdiffs(x, y, ...)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
y |
Same as |
check |
Boolean value determining whether to check that the intervals specified in arguments |
in_x |
Boolean value determining whether to flag |
in_y |
Boolean value determining whether to flag |
op |
Character value specifying operator used to combine flags for each interval, either |
... |
Additional arguments to be passed to |
Intervals represented by integer matrix of two columns.
intersects(cbind(1, 3), cbind(2, 4)) setdiffs(cbind(1, 3), cbind(2, 4)) unions(cbind(1, 3), cbind(2, 4))
intersects(cbind(1, 3), cbind(2, 4)) setdiffs(cbind(1, 3), cbind(2, 4)) unions(cbind(1, 3), cbind(2, 4))
Get the intervals overlapping each section as a list.
pile(x, interval_names = rownames(x), output = "list")
pile(x, interval_names = rownames(x), output = "list")
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
interval_names |
Character vector of names for each interval, not necessarily unique. If they are not unique, one might wish to |
output |
Character value either |
See notes on output
parameter.
pile(cbind(1:10, 11:20))
pile(cbind(1:10, 11:20))
Proportion overlapping is calculated as the size of the intersection of intervals, divided by the size of the union.
proportion_overlap(...)
proportion_overlap(...)
... |
Interval matrices (passed to |
data.frame
containing integer columns corresponding to indices of intervals within the input matrices and a final numeric column called proportion_overlap
containing the fraction of the size of the intersection within the union.
proportion_overlap(rbind(c(1, 2), c(49, 51), c(50, 200)), rbind(c(50, 100)))
proportion_overlap(rbind(c(1, 2), c(49, 51), c(50, 200)), rbind(c(50, 100)))
Given a set of interval breaks (see breaks
), generate a new set of intervals, the ‘sections’, which partitions the full range of the given set, with an interval between every ‘break’ (i.e. start/end point) in the given set.
sections(x)
sections(x)
x |
Sorted integer vector. |
Intervals represented by integer matrix of two columns.
sections(1:10)
sections(1:10)
Given an integer matrix specifying disjoint intervals sorted by start position, merge intervals with matching start and ends, and remove intervals of length zero.
stitch(x)
stitch(x)
x |
Integer matrix of two columns, the first column giving the (inclusive) start points of intervals and the second column giving the corresponding (exclusive) end points. |
Intervals represented by integer matrix of two columns.
stitch(cbind(1:2, 2:3))
stitch(cbind(1:2, 2:3))