~ubuntu-branches/ubuntu/wily/r-bioc-genomicranges/wily-proposed

« back to all changes in this revision

Viewing changes to R/GenomicRanges-comparison.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-11-26 19:52:13 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131126195213-1zwbthnie0a7fdns
Tags: 1.14.3-1
* New upstream version
  Closes: #730574
* Build-Depends: r-bioc-xvector

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
### method for Vector objects.
133
133
###
134
134
 
135
 
### Unfortunately, the early version of this method was doing overlaps, not
136
 
### equality. We temporarily add the 'match.if.overlap' argument so the old
137
 
### behavior is still available.
138
 
### TODO: Deprecate 'match.if.overlap' arg in BioC 2.13.
139
 
### TODO: Remove 'match.if.overlap' arg in BioC 2.14.
 
135
### TODO: Defunct 'match.if.overlap' arg in BioC 2.14.
140
136
setMethod("match", c("GenomicRanges", "GenomicRanges"),
141
137
    function(x, table, nomatch=NA_integer_, incomparables=NULL,
142
138
                       method=c("auto", "quick", "hash"),
151
147
                 "only accepts 'incomparables=NULL'")
152
148
        if (!isTRUEorFALSE(ignore.strand))
153
149
            stop("'ignore.strand' must be TRUE or FALSE")
154
 
        if (missing(match.if.overlap))
155
 
            warning(IRanges:::match.if.overlap.warning.msg("GenomicRanges"))
156
150
        if (!isTRUEorFALSE(match.if.overlap))
157
151
            stop("'match.if.overlap' must be TRUE or FALSE")
158
152
        if (match.if.overlap) {
 
153
            msg <- c("  In the near future (starting with BioC 2.14), ",
 
154
                     "match() on GRanges objects\n  won't support ",
 
155
                     "the 'match.if.overlap' argument anymore. Please use\n\n",
 
156
                     "    findOverlaps(x, table, select=\"first\", ",
 
157
                     "ignore.strand=ignore.strand)\n\n",
 
158
                     "  instead of\n\n",
 
159
                     "    match(x, table, ignore.strand=ignore.strand, ",
 
160
                     "match.if.overlap=TRUE)")
 
161
            .Deprecated(msg=msg)
159
162
            ans <- findOverlaps(x, table,
160
163
                                select="first", ignore.strand=ignore.strand)
161
164
            if (!is.na(nomatch) && anyMissing(ans))
165
168
        ## Calling merge() is the way to check that 'x' and 'table' are based
166
169
        ## on the same reference genome.
167
170
        merge(seqinfo(x), seqinfo(table))
 
171
        x_seqnames <- relevelSeqnamesForMatch(x, table)
168
172
        if (ignore.strand) {
169
173
            x_strand <- integer(length(x))
170
174
            table_strand <- integer(length(table))
175
179
        ## Equivalent to (but faster than):
176
180
        ##     findOverlaps(x, table, type="equal", select="first")
177
181
        ## except when 'x' and 'table' both contain empty ranges.
178
 
        IRanges:::matchIntegerQuads(as.factor(seqnames(x)), x_strand,
 
182
        IRanges:::matchIntegerQuads(x_seqnames, x_strand,
179
183
                                    start(x), width(x),
180
184
                                    as.factor(seqnames(table)), table_strand,
181
185
                                    start(table), width(table),
183
187
    }
184
188
)
185
189
 
 
190
relevelSeqnamesForMatch <- function(x, table) {
 
191
  x_seqnames <- as.factor(seqnames(x))
 
192
  if (!hasHead(seqlevels(x), seqlevels(table)) &&
 
193
      !hasHead(seqlevels(table), seqlevels(x))) {
 
194
    x_seqnames <- factor(x_seqnames,
 
195
                         union(seqlevels(table), seqlevels(x)))
 
196
  }
 
197
  x_seqnames
 
198
}
 
199
 
186
200
### The only reason for overriding the method for Vector objects is to issue
187
201
### the warning.
188
202
### TODO: Remove this method in BioC 2.14 when the 'match.if.overlap' arg of
189
 
### match() is gone.
 
203
### match() is defunct.
190
204
setMethod("%in%", c("GenomicRanges", "GenomicRanges"),
191
205
    function(x, table)
192
206
    {
193
207
        warning(IRanges:::`%in%.warning.msg`("GenomicRanges"))
194
 
        !is.na(match(x, table, match.if.overlap=FALSE))
 
208
        !is.na(match(x, table))
195
209
    }
196
210
)
197
211
 
203
217
### that otherwise would be issued when the user calls findMatches() or
204
218
### countMatches() on GenomicRanges objects.
205
219
### TODO: Remove these methods in BioC 2.14 when the 'match.if.overlap' arg
206
 
### of match() is gone.
 
220
### of match() is defunct.
207
221
 
208
222
setMethod("findMatches", c("GenomicRanges", "GenomicRanges"),
209
223
    function(x, table, select=c("all", "first", "last"), ...)