4
\alias{union,GRanges,GRanges-method}
5
\alias{intersect,GRanges,GRanges-method}
6
\alias{setdiff,GRanges,GRanges-method}
8
\alias{punion,GRanges,GRanges-method}
9
\alias{punion,GRanges,GRangesList-method}
10
\alias{punion,GRangesList,GRanges-method}
12
\alias{pintersect,GRanges,GRanges-method}
13
\alias{pintersect,GRanges,GRangesList-method}
14
\alias{pintersect,GRangesList,GRanges-method}
15
\alias{pintersect,GRangesList,GRangesList-method}
16
\alias{pintersect,GappedAlignments,GRanges-method}
17
\alias{pintersect,GRanges,GappedAlignments-method}
19
\alias{psetdiff,GRanges,GRanges-method}
20
\alias{psetdiff,GRanges,GRangesList-method}
21
\alias{psetdiff,GRangesList,GRangesList-method}
23
\alias{pgap,GRanges,GRanges-method}
25
\title{Set operations on GRanges/GRangesList/GappedAlignments objects}
28
Performs set operations on GRanges/GRangesList/GappedAlignments objects.
33
\S4method{union}{GRanges,GRanges}(x, y, ignore.strand=FALSE, ...)
34
\S4method{intersect}{GRanges,GRanges}(x, y, ignore.strand=FALSE, ...)
35
\S4method{setdiff}{GRanges,GRanges}(x, y, ignore.strand=FALSE, ...)
37
## Parallel set operations
38
\S4method{punion}{GRanges,GRanges}(x, y, fill.gap=FALSE, ignore.strand=FALSE, ...)
39
\S4method{pintersect}{GRanges,GRanges}(x, y, resolve.empty=c("none", "max.start", "start.x"), ignore.strand=FALSE, ...)
40
\S4method{pintersect}{GappedAlignments,GRanges}(x, y, ...)
41
\S4method{psetdiff}{GRanges,GRanges}(x, y, ignore.strand=FALSE, ...)
46
For \code{union}, \code{intersect}, \code{setdiff}, \code{pgap}:
47
\code{x} and \code{y} must both be \link{GRanges} objects.
49
For \code{punion}: one of \code{x} or \code{y} must be a \link{GRanges}
50
object, the other one can be a \link{GRanges} or \link{GRangesList} object.
52
For \code{pintersect}: one of \code{x} or \code{y} must be a \link{GRanges}
53
object, the other one can be a \link{GRanges}, \link{GRangesList} or
54
\link{GappedAlignments} object.
56
For \code{psetdiff}: \code{x} and \code{y} can be any combination of
57
\link{GRanges} and/or \link{GRangesList} objects, with the exception
58
that if \code{x} is a \link{GRangesList} object then \code{y} must be
59
a \link{GRangesList} too.
61
In addition, for the "parallel" operations, \code{x} and \code{y} must
62
be of equal length (i.e. \code{length(x) == length(y)}).
65
Logical indicating whether or not to force a union by using the rule
66
\code{start = min(start(x), start(y)), end = max(end(x), end(y))}.
69
One of \code{"none"}, \code{"max.start"}, or \code{"start.x"} denoting
70
how to handle ambiguous empty ranges formed by intersections.
71
\code{"none"} - throw an error if an ambiguous empty range is formed,
72
\code{"max.start"} - associate the maximum start value with any
73
ambiguous empty range, and \code{"start.x"} - associate the start value
74
of \code{x} with any ambiguous empty range. (See
75
\code{\link[IRanges]{pintersect}} for the definition of an ambiguous
79
For set operations: If set to TRUE, then the strand of \code{x} and
80
\code{y} is set to \code{"*"} prior to any computation.
82
For parallel set operations: If set to TRUE, the strand information is
83
ignored in the computation and the result has the strand information of
87
Further arguments to be passed to or from other methods.
92
The \code{pintersect} methods involving \link{GRanges}, \link{GRangesList}
93
and/or \link{GappedAlignments} objects use the triplet (sequence name, range,
94
strand) to determine the element by element intersection of features,
95
where a strand value of \code{"*"} is treated as occurring on both the
96
\code{"+"} and \code{"-"} strand.
98
The \code{psetdiff} methods involving \link{GRanges} and/or
99
\link{GRangesList} objects use the triplet (sequence name, range,
100
strand) to determine the element by element set difference of features,
101
where a strand value of \code{"*"} is treated as occurring on both the
102
\code{"+"} and \code{"-"} strand.
106
For \code{union}, \code{intersect}, \code{setdiff}, and \code{pgap}: a
109
For \code{punion} and \code{pintersect}: when \code{x} or \code{y} is
110
not a \link{GRanges} object, an object of the same class as this
111
non-\link{GRanges} object. Otherwise, a \link{GRanges} object.
113
For \code{psetdiff}: either a \link{GRanges} object when both \code{x}
114
and \code{y} are \link{GRanges} objects, or a \link{GRangesList} object
115
when \code{y} is a \link{GRangesList} object.
121
\link[IRanges]{setops-methods},
122
\link{GRanges-class},
123
\link{GRangesList-class},
124
\link{GappedAlignments-class},
125
\link{findOverlaps-methods}
129
## ---------------------------------------------------------------------
131
## ---------------------------------------------------------------------
133
x <- GRanges("chr1", IRanges(c(2, 9) , c(7, 19)), strand=c("+", "-"))
134
y <- GRanges("chr1", IRanges(5, 10), strand="-")
137
union(x, y, ignore.strand=TRUE)
140
intersect(x, y, ignore.strand=TRUE)
143
setdiff(x, y, ignore.strand=TRUE)
145
## ---------------------------------------------------------------------
146
## B. PARALLEL SET OPERATIONS
147
## ---------------------------------------------------------------------
150
punion(x, shift(x, 7)) # will fail
152
punion(x, shift(x, 7), fill.gap=TRUE)
154
pintersect(x, shift(x, 6))
156
pintersect(x, shift(x, 7)) # will fail
158
pintersect(x, shift(x, 7), resolve.empty="max.start")
160
psetdiff(x, shift(x, 7))
162
## ---------------------------------------------------------------------
164
## ---------------------------------------------------------------------
167
gr <- GRanges(seqnames=c("chr2", "chr1", "chr1"),
168
ranges=IRanges(1:3, width = 12),
169
strand=Rle(strand(c("-", "*", "-"))))
171
## GRangesList object
172
gr1 <- GRanges(seqnames="chr2",
173
ranges=IRanges(3, 6))
174
gr2 <- GRanges(seqnames=c("chr1", "chr1"),
175
ranges=IRanges(c(7,13), width = 3),
177
gr3 <- GRanges(seqnames=c("chr1", "chr2"),
178
ranges=IRanges(c(1, 4), c(3, 9)),
180
grlist <- GRangesList(gr1=gr1, gr2=gr2, gr3=gr3)
182
## Parallel intersection of a GRanges and a GRangesList object
183
pintersect(gr, grlist)
184
pintersect(grlist, gr)
186
## Parallel intersection of a GappedAlignments and a GRanges object
187
library(Rsamtools) # because file ex1.bam is in this package
188
galn_file <- system.file("extdata", "ex1.bam", package="Rsamtools")
189
galn <- readGappedAlignments(galn_file)
190
pintersect(galn, shift(as(galn, "GRanges"), 6L))
192
## Parallel set difference of a GRanges and a GRangesList object
195
## Parallel set difference of two GRangesList objects
196
psetdiff(grlist, shift(grlist, 3))