Browse code

Repair subsetByOverlaps() on hasGRanges derivatives

Also add overlapsAny() methods and improve granges() method for
hasGRanges derivatives.

Hervé Pagès authored on 20/05/2020 22:23:58
Showing 4 changed files

... ...
@@ -1,5 +1,5 @@
1 1
 Package: bsseq
2
-Version: 1.25.0
2
+Version: 1.25.1
3 3
 Encoding: UTF-8
4 4
 Title: Analyze, manage and store bisulfite sequencing data
5 5
 Description: A collection of tools for analyzing and visualizing bisulfite
... ...
@@ -14,7 +14,7 @@ Depends:
14 14
     GenomicRanges (>= 1.33.6),
15 15
     SummarizedExperiment (>= 1.17.4)
16 16
 Imports:
17
-    IRanges (>= 2.21.6),
17
+    IRanges (>= 2.23.5),
18 18
     GenomeInfoDb,
19 19
     scales,
20 20
     stats,
... ...
@@ -72,7 +72,7 @@ exportMethods("[", "show",
72 72
               "dim", "nrow", "ncol",
73 73
               "sampleNames", "sampleNames<-",
74 74
               "pData", "pData<-",
75
-              "findOverlaps", "subsetByOverlaps",
75
+              "findOverlaps", "overlapsAny", "subsetByOverlaps",
76 76
               "combine", "updateObject")
77 77
 
78 78
 export("BSseq", "getMeth", "getCoverage", "getBSseq", "getStats",
... ...
@@ -7,9 +7,7 @@ setMethod("seqnames", signature(x = "hasGRanges"), function(x) {
7 7
     seqnames(x@gr)
8 8
 })
9 9
 setReplaceMethod("seqnames", "hasGRanges", function(x, value) {
10
-    gr <- granges(x)
11
-    seqnames(gr) <- value
12
-    x@gr <- gr
10
+    seqnames(x@gr) <- value
13 11
     x
14 12
 })
15 13
 
... ...
@@ -17,9 +15,7 @@ setMethod("seqlevels", signature(x = "hasGRanges"), function(x) {
17 15
     seqlevels(x@gr)
18 16
 })
19 17
 setReplaceMethod("seqlevels", "hasGRanges", function(x, value) {
20
-    gr <- granges(x)
21
-    seqlevels(gr) <- value
22
-    x@gr <- gr
18
+    seqlevels(x@gr) <- value
23 19
     x
24 20
 })
25 21
 
... ...
@@ -27,14 +23,14 @@ setMethod("seqlengths", signature(x = "hasGRanges"), function(x) {
27 23
     seqlengths(x@gr)
28 24
 })
29 25
 setReplaceMethod("seqlengths", "hasGRanges", function(x, value) {
30
-    gr <- granges(x)
31
-    seqlengths(gr) <- value
32
-    x@gr <- gr
26
+    seqlengths(x@gr) <- value
33 27
     x
34 28
 })
35 29
 
36 30
 setMethod("granges", signature(x = "hasGRanges"),
37
-          function(x) x@gr)
31
+    function(x, use.names = TRUE, use.mcols = FALSE, ...)
32
+        granges(x@gr, use.names = use.names, use.mcols = use.mcols, ...)
33
+)
38 34
 
39 35
 ## FIXME: might want a granges replacement function
40 36
 
... ...
@@ -42,9 +38,7 @@ setMethod("start", "hasGRanges", function(x, ...) {
42 38
     start(x@gr, ...)
43 39
 })
44 40
 setReplaceMethod("start", "hasGRanges", function(x, check = TRUE, value) {
45
-    gr <- granges(x)
46
-    start(gr, check = check) <- value
47
-    x@gr <- gr
41
+    start(x@gr, check = check) <- value
48 42
     x
49 43
 })
50 44
 
... ...
@@ -52,9 +46,7 @@ setMethod("end", "hasGRanges", function(x, ...) {
52 46
     end(x@gr, ...)
53 47
 })
54 48
 setReplaceMethod("end", "hasGRanges", function(x, check = TRUE, value) {
55
-    gr <- granges(x)
56
-    end(gr, check = check) <- value
57
-    x@gr <- gr
49
+    end(x@gr, check = check) <- value
58 50
     x
59 51
 })
60 52
 
... ...
@@ -62,9 +54,7 @@ setMethod("width", "hasGRanges", function(x) {
62 54
     width(x@gr)
63 55
 })
64 56
 setReplaceMethod("width", "hasGRanges", function(x, check = TRUE, value) {
65
-    gr <- granges(x)
66
-    width(gr, check = check) <- value
67
-    x@gr <- gr
57
+    width(x@gr, check = check) <- value
68 58
     x
69 59
 })
70 60
 
... ...
@@ -72,49 +62,20 @@ setMethod("strand", "hasGRanges", function(x) {
72 62
     strand(x@gr)
73 63
 })
74 64
 setReplaceMethod("strand", "hasGRanges", function(x, value) {
75
-    gr <- granges(x)
76
-    strand(gr) <- value
77
-    x@gr <- gr
65
+    strand(x@gr) <- value
78 66
     x
79 67
 })
80 68
 
81 69
 setMethod("length", "hasGRanges", function(x) length(x@gr))
82 70
 
83
-## setMethod("subsetByOverlaps",
84
-##           signature(query = "hasGRanges", subject = "GenomicRanges"),
85
-##           function(query, subject, maxgap = 0L, minoverlap = 1L,
86
-##                    type = c("any", "start", "end", "within", "equal"),
87
-##                    ignore.strand = FALSE, ...) {
88
-##               ov <- findOverlaps(query = granges(query), subject = subject,
89
-##                                  maxgap = maxgap, minoverlap = minoverlap,
90
-##                                  type = match.arg(type), select = "arbitrary",
91
-##                                  ignore.strand = ignore.strand, ... )
92
-##               query[!is.na(ov)]
93
-##           })
94
-
95
-## setMethod("subsetByOverlaps",
96
-##           signature(query = "hasGRanges", subject = "hasGRanges"),
97
-##           function(query, subject, maxgap = 0L, minoverlap = 1L,
98
-##                    type = c("any", "start", "end", "within", "equal"),
99
-##                    ignore.strand = FALSE, ...) {
100
-##               ov <- findOverlaps(query = granges(query), subject = granges(subject),
101
-##                                  maxgap = maxgap, minoverlap = minoverlap,
102
-##                                  type = match.arg(type), select = "arbitrary",
103
-##                                  ignore.strand = ignore.strand, ... )
104
-##               query[!is.na(ov)]
105
-##           })
106
-
107
-## setMethod("subsetByOverlaps",
108
-##           signature(query = "GenomicRanges", subject = "hasGRanges"),
109
-##           function(query, subject, maxgap = 0L, minoverlap = 1L,
110
-##                    type = c("any", "start", "end", "within", "equal"),
111
-##                    ignore.strand = FALSE, ...) {
112
-##               ov <- findOverlaps(query = query, subject = granges(subject),
113
-##                                  maxgap = maxgap, minoverlap = minoverlap,
114
-##                                  type = match.arg(type), select = "arbitrary",
115
-##                                  ignore.strand = ignore.strand, ... )
116
-##               query[!is.na(ov)]
117
-##           })
71
+setMethod("[", "hasGRanges", function(x, i, ...) {
72
+    if(missing(i))
73
+        stop("need [i] for subsetting")
74
+    if(missing(i))
75
+        return(x)
76
+    x@gr <- x@gr[i]
77
+    x
78
+})
118 79
 
119 80
 setMethod("findOverlaps",
120 81
           signature(query = "hasGRanges", subject = "GenomicRanges"),
... ...
@@ -122,42 +83,53 @@ setMethod("findOverlaps",
122 83
                     type = c("any", "start", "end", "within", "equal"),
123 84
                     select = c("all", "first", "last", "arbitrary"),
124 85
                     ignore.strand = FALSE, ...) {
125
-              findOverlaps(query = granges(query), subject = subject,
86
+              findOverlaps(query = query@gr, subject = subject,
126 87
                            maxgap = maxgap, minoverlap = minoverlap,
127 88
                            type = match.arg(type), select = match.arg(select),
128 89
                            ignore.strand = ignore.strand, ...)
129 90
           })
130 91
 
131 92
 setMethod("findOverlaps",
132
-          signature(query = "hasGRanges", subject = "hasGRanges"),
93
+          signature(query = "GenomicRanges", subject = "hasGRanges"),
133 94
           function (query, subject, maxgap = -1L, minoverlap = 0L,
134 95
                     type = c("any", "start", "end", "within", "equal"),
135 96
                     select = c("all", "first", "last", "arbitrary"),
136 97
                     ignore.strand = FALSE, ...) {
137
-              findOverlaps(query = granges(query), subject = granges(subject),
98
+              findOverlaps(query = query, subject = subject@gr,
138 99
                            maxgap = maxgap, minoverlap = minoverlap,
139 100
                            type = match.arg(type), select = match.arg(select),
140 101
                            ignore.strand = ignore.strand, ...)
141 102
           })
142 103
 
143 104
 setMethod("findOverlaps",
144
-          signature(query = "GenomicRanges", subject = "hasGRanges"),
105
+          signature(query = "hasGRanges", subject = "hasGRanges"),
145 106
           function (query, subject, maxgap = -1L, minoverlap = 0L,
146 107
                     type = c("any", "start", "end", "within", "equal"),
147 108
                     select = c("all", "first", "last", "arbitrary"),
148 109
                     ignore.strand = FALSE, ...) {
149
-              findOverlaps(query = query, subject = granges(subject),
110
+              findOverlaps(query = query@gr, subject = subject@gr,
150 111
                            maxgap = maxgap, minoverlap = minoverlap,
151 112
                            type = match.arg(type), select = match.arg(select),
152 113
                            ignore.strand = ignore.strand, ...)
153 114
           })
154 115
 
155
-setMethod("[", "hasGRanges", function(x, i, ...) {
156
-    if(missing(i))
157
-        stop("need [i] for subsetting")
158
-    if(missing(i))
159
-        return(x)
160
-    x@gr <- x@gr[i]
161
-    x
162
-})
116
+setMethod("overlapsAny", c("hasGRanges", "GenomicRanges"),
117
+    IRanges:::default_overlapsAny
118
+)
119
+setMethod("overlapsAny", c("GenomicRanges", "hasGRanges"),
120
+    IRanges:::default_overlapsAny
121
+)
122
+setMethod("overlapsAny", c("hasGRanges", "hasGRanges"),
123
+    IRanges:::default_overlapsAny
124
+)
125
+
126
+setMethod("subsetByOverlaps", c("hasGRanges", "GenomicRanges"),
127
+    IRanges:::default_subsetByOverlaps
128
+)
129
+setMethod("subsetByOverlaps", c("GenomicRanges", "hasGRanges"),
130
+    IRanges:::default_subsetByOverlaps
131
+)
132
+setMethod("subsetByOverlaps", c("hasGRanges", "hasGRanges"),
133
+    IRanges:::default_subsetByOverlaps
134
+)
163 135
 
... ...
@@ -1,32 +1,37 @@
1 1
 \name{hasGRanges-class}
2 2
 \Rdversion{1.1}
3 3
 \docType{class}
4
+\alias{class:hasGRanges}
4 5
 \alias{hasGRanges-class}
5
-\alias{[,hasGRanges-method}
6
-\alias{[,hasGRanges,ANY,ANY,ANY-method}
7
-\alias{end,hasGRanges-method}
8
-\alias{end<-,hasGRanges-method}
9
-\alias{granges,hasGRanges-method}
10
-\alias{length,hasGRanges-method}
11
-\alias{seqlengths,hasGRanges-method}
12
-\alias{seqlengths<-,hasGRanges-method}
13
-\alias{seqlevels,hasGRanges-method}
14
-\alias{seqlevels<-,hasGRanges-method}
6
+\alias{hasGRanges}
15 7
 \alias{seqnames,hasGRanges-method}
16 8
 \alias{seqnames<-,hasGRanges-method}
9
+\alias{seqlevels,hasGRanges-method}
10
+\alias{seqlevels<-,hasGRanges-method}
11
+\alias{seqlengths,hasGRanges-method}
12
+\alias{seqlengths<-,hasGRanges-method}
13
+\alias{granges,hasGRanges-method}
17 14
 \alias{start,hasGRanges-method}
18 15
 \alias{start<-,hasGRanges-method}
16
+\alias{end,hasGRanges-method}
17
+\alias{end<-,hasGRanges-method}
18
+\alias{width,hasGRanges-method}
19
+\alias{width<-,hasGRanges-method}
19 20
 \alias{strand,hasGRanges-method}
20 21
 \alias{strand<-,hasGRanges-method}
21 22
 \alias{strand<-,hasGRanges,ANY-method}
22
-%\alias{subsetByOverlaps,GenomicRanges,hasGRanges-method}
23
-%\alias{subsetByOverlaps,hasGRanges,GenomicRanges-method}
24
-%\alias{subsetByOverlaps,hasGRanges,hasGRanges-method}
25
-\alias{findOverlaps,GenomicRanges,hasGRanges-method}
23
+\alias{length,hasGRanges-method}
24
+\alias{[,hasGRanges-method}
25
+\alias{[,hasGRanges,ANY,ANY,ANY-method}
26 26
 \alias{findOverlaps,hasGRanges,GenomicRanges-method}
27
+\alias{findOverlaps,GenomicRanges,hasGRanges-method}
27 28
 \alias{findOverlaps,hasGRanges,hasGRanges-method}
28
-\alias{width,hasGRanges-method}
29
-\alias{width<-,hasGRanges-method}
29
+\alias{overlapsAny,hasGRanges,GenomicRanges-method}
30
+\alias{overlapsAny,GenomicRanges,hasGRanges-method}
31
+\alias{overlapsAny,hasGRanges,hasGRanges-method}
32
+\alias{subsetByOverlaps,hasGRanges,GenomicRanges-method}
33
+\alias{subsetByOverlaps,GenomicRanges,hasGRanges-method}
34
+\alias{subsetByOverlaps,hasGRanges,hasGRanges-method}
30 35
 
31 36
 \title{Class hasGRanges}
32 37
 \description{