Description Usage Arguments Details Value Author(s) References See Also Examples
Various methods for finding/counting interval overlaps between two "range-based" objects: a query and a subject.
NOTE: This man page describes the methods that operate on
IntegerRanges and IntegerRangesList derivatives. See
?`findOverlaps,GenomicRanges,GenomicRanges-method`
in the GenomicRanges package for methods that operate on
GenomicRanges or GRangesList
objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | findOverlaps(query, subject, maxgap=-1L, minoverlap=0L,
type=c("any", "start", "end", "within", "equal"),
select=c("all", "first", "last", "arbitrary"),
...)
countOverlaps(query, subject, maxgap=-1L, minoverlap=0L,
type=c("any", "start", "end", "within", "equal"),
...)
overlapsAny(query, subject, maxgap=-1L, minoverlap=0L,
type=c("any", "start", "end", "within", "equal"),
...)
query %over% subject
query %within% subject
query %outside% subject
subsetByOverlaps(x, ranges, maxgap=-1L, minoverlap=0L,
type=c("any", "start", "end", "within", "equal"),
invert=FALSE,
...)
overlapsRanges(query, subject, hits=NULL, ...)
poverlaps(query, subject, maxgap = 0L, minoverlap = 1L,
type = c("any", "start", "end", "within", "equal"),
...)
mergeByOverlaps(query, subject, ...)
findOverlapPairs(query, subject, ...)
|
query, subject, x, ranges |
Each of them can be an IntegerRanges (e.g. IRanges,
Views) or IntegerRangesList (e.g. IRangesList,
ViewsList) derivative.
In addition, if If If both arguments are list-like objects with names, each list element from the 2nd argument is paired with the list element from the 1st argument with the matching name, if any. Otherwise, list elements are paired by position. The overlap is then computed between the pairs as described below. If |
maxgap |
A single integer >= -1. If If |
minoverlap |
A single non-negative integer. Only ranges with a minimum of When |
type |
By default, any overlap is accepted. By specifying the The |
select |
If If |
invert |
If |
hits |
The Hits or HitsList object returned
by |
... |
Further arguments to be passed to or from other methods:
|
A common type of query that arises when working with intervals is finding which intervals in one set overlap those in another.
The simplest approach is to call the findOverlaps
function
on a IntegerRanges or other object with range information (aka
"range-based object").
For findOverlaps
: see select
argument above.
For countOverlaps
: the overlap hit count for each range
in query
using the specified findOverlaps
parameters.
For IntegerRangesList objects, it returns an IntegerList
object.
overlapsAny
finds the ranges in query
that overlap any
of the ranges in subject
. For IntegerRanges derivatives,
it returns a logical vector of length equal to the number of
ranges in query
. For IntegerRangesList derivatives,
it returns a LogicalList object where each element of the result
corresponds to a space in query
.
%over%
and %within%
are convenience wrappers for the
2 most common use cases. Currently defined as
`%over%` <- function(query, subject) overlapsAny(query, subject)
and
`%within%` <- function(query, subject)
overlapsAny(query, subject,
type="within")
. %outside%
is simply the inverse of %over%
.
subsetByOverlaps
returns the subset of x
that
has an overlap hit with a range in ranges
using the specified
findOverlaps
parameters.
When hits
is a Hits (or HitsList)
object, overlapsRanges(query, subject, hits)
returns a
IntegerRanges (or IntegerRangesList) object of the same
shape as hits
holding the regions of intersection between the
overlapping ranges in objects query
and subject
, which should
be the same query and subject used in the call to findOverlaps
that
generated hits
.
Same shape means same length when hits
is a
Hits object, and same length and same elementNROWS
when hits
is a HitsList object.
poverlaps
compares query
and subject
in parallel
(like e.g., pmin
) and returns a logical vector indicating
whether each pair of ranges overlaps. Integer vectors are treated as
width-one ranges.
mergeByOverlaps
computes the overlap between query and subject
according to the arguments in ...
. It then extracts the
corresponding hits from each object and returns a DataFrame
containing one column for the query and one for the subject, as well
as any mcols
that were present on either object. The query and
subject columns are named by quoting and deparsing the corresponding
argument.
findOverlapPairs
is like mergeByOverlaps
, except it
returns a formal Pairs
object
that provides useful downstream conveniences, such as finding the
intersection of the overlapping ranges with pintersect
.
Michael Lawrence and Hervé Pagès
Allen's Interval Algebra: James F. Allen: Maintaining knowledge about temporal intervals. In: Communications of the ACM. 26/11/1983. ACM Press. S. 832-843, ISSN 0001-0782
Hits and HitsList objects in the S4Vectors package for representing a set of hits between 2 vector-like or list-like objects.
findOverlaps,GenomicRanges,GenomicRanges-method in the GenomicRanges package for methods that operate on GRanges or GRangesList objects.
The NCList class and constructor.
The IntegerRanges, Views, IntegerRangesList, and ViewsList classes.
The IntegerList and LogicalList classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ## ---------------------------------------------------------------------
## findOverlaps()
## ---------------------------------------------------------------------
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
findOverlaps(query, subject)
## at most one hit per query
findOverlaps(query, subject, select="first")
findOverlaps(query, subject, select="last")
findOverlaps(query, subject, select="arbitrary")
## including adjacent ranges in the result
findOverlaps(query, subject, maxgap=0L)
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2), c(5, 4))
## one IRanges object with itself
findOverlaps(query)
## single points as query
subject <- IRanges(c(1, 6, 13), c(4, 9, 14))
findOverlaps(c(3L, 7L, 10L), subject, select="first")
## special overlap types
query <- IRanges(c(1, 5, 3, 4), width=c(2, 2, 4, 6))
subject <- IRanges(c(1, 3, 5, 6), width=c(4, 4, 5, 4))
findOverlaps(query, subject, type="start")
findOverlaps(query, subject, type="start", maxgap=1L)
findOverlaps(query, subject, type="end", select="first")
ov <- findOverlaps(query, subject, type="within", maxgap=1L)
ov
## Using pairs to find intersection of overlapping ranges
hits <- findOverlaps(query, subject)
p <- Pairs(query, subject, hits=hits)
pintersect(p)
## Shortcut
p <- findOverlapPairs(query, subject)
pintersect(p)
## ---------------------------------------------------------------------
## overlapsAny()
## ---------------------------------------------------------------------
overlapsAny(query, subject, type="start")
overlapsAny(query, subject, type="end")
query %over% subject # same as overlapsAny(query, subject)
query %within% subject # same as overlapsAny(query, subject,
# type="within")
## ---------------------------------------------------------------------
## overlapsRanges()
## ---------------------------------------------------------------------
## Extract the regions of intersection between the overlapping ranges:
overlapsRanges(query, subject, ov)
## ---------------------------------------------------------------------
## Using IntegerRangesList objects
## ---------------------------------------------------------------------
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
qpartition <- factor(c("a","a","b"))
qlist <- split(query, qpartition)
subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
spartition <- factor(c("a","a","b"))
slist <- split(subject, spartition)
## at most one hit per query
findOverlaps(qlist, slist, select="first")
findOverlaps(qlist, slist, select="last")
findOverlaps(qlist, slist, select="arbitrary")
query <- IRanges(c(1, 5, 3, 4), width=c(2, 2, 4, 6))
qpartition <- factor(c("a","a","b","b"))
qlist <- split(query, qpartition)
subject <- IRanges(c(1, 3, 5, 6), width=c(4, 4, 5, 4))
spartition <- factor(c("a","a","b","b"))
slist <- split(subject, spartition)
overlapsAny(qlist, slist, type="start")
overlapsAny(qlist, slist, type="end")
qlist
subsetByOverlaps(qlist, slist)
countOverlaps(qlist, slist)
|
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, basename, cbind, colMeans, colSums, colnames,
dirname, do.call, duplicated, eval, evalq, get, grep, grepl,
intersect, is.unsorted, lapply, lengths, mapply, match, mget,
order, paste, pmax, pmax.int, pmin, pmin.int, rank, rbind,
rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
union, unique, unsplit, which, which.max, which.min
Loading required package: S4Vectors
Loading required package: stats4
Attaching package: 'S4Vectors'
The following object is masked from 'package:base':
expand.grid
Hits object with 3 hits and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 1 2
[2] 1 1
[3] 3 3
-------
queryLength: 3 / subjectLength: 3
[1] 1 NA 3
[1] 2 NA 3
[1] 2 NA 3
Hits object with 4 hits and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 1 2
[2] 1 1
[3] 2 2
[4] 3 3
-------
queryLength: 3 / subjectLength: 3
SelfHits object with 5 hits and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 1 1
[2] 1 2
[3] 2 1
[4] 2 2
[5] 3 3
-------
queryLength: 3 / subjectLength: 3
[1] 1 2 NA
Hits object with 3 hits and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 1 1
[2] 2 3
[3] 3 2
-------
queryLength: 4 / subjectLength: 4
Hits object with 6 hits and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 1 1
[2] 2 3
[3] 2 4
[4] 3 2
[5] 4 2
[6] 4 3
-------
queryLength: 4 / subjectLength: 4
[1] NA 2 2 3
Hits object with 1 hit and 0 metadata columns:
queryHits subjectHits
<integer> <integer>
[1] 3 2
-------
queryLength: 4 / subjectLength: 4
IRanges object with 12 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 1 2 2
[2] 5 6 2
[3] 5 6 2
[4] 6 6 1
[5] 3 4 2
... ... ... ...
[8] 6 6 1
[9] 4 4 1
[10] 4 6 3
[11] 5 9 5
[12] 6 9 4
IRanges object with 12 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 1 2 2
[2] 5 6 2
[3] 5 6 2
[4] 6 6 1
[5] 3 4 2
... ... ... ...
[8] 6 6 1
[9] 4 4 1
[10] 4 6 3
[11] 5 9 5
[12] 6 9 4
[1] TRUE TRUE TRUE FALSE
[1] FALSE TRUE TRUE TRUE
[1] TRUE TRUE TRUE TRUE
[1] TRUE TRUE TRUE FALSE
IRanges object with 1 range and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 3 6 4
IntegerList of length 2
[["a"]] 1 <NA>
[["b"]] 1
IntegerList of length 2
[["a"]] 2 <NA>
[["b"]] 1
IntegerList of length 2
[["a"]] 2 <NA>
[["b"]] 1
LogicalList of length 2
[["a"]] TRUE FALSE
[["b"]] FALSE FALSE
LogicalList of length 2
[["a"]] FALSE TRUE
[["b"]] FALSE TRUE
IRangesList of length 2
$a
IRanges object with 2 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 1 2 2
[2] 5 6 2
$b
IRanges object with 2 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 3 6 4
[2] 4 9 6
IRangesList of length 2
$a
IRanges object with 2 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 1 2 2
[2] 5 6 2
$b
IRanges object with 2 ranges and 0 metadata columns:
start end width
<integer> <integer> <integer>
[1] 3 6 4
[2] 4 9 6
IntegerList of length 2
[["a"]] 1 1
[["b"]] 2 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.