Browse code

Changed y-axis label to be more generic

shians authored on 17/01/2025 00:04:32
Showing 1 changed files
... ...
@@ -69,7 +69,7 @@ plot_region_impl <- function(
69 69
             mod_scale = mod_scale
70 70
         ) +
71 71
         ggplot2::coord_cartesian(xlim = xlim, expand = FALSE) +
72
-        ggplot2::labs(x = "Position", y = "Mean Methylation Probability")
72
+        ggplot2::labs(x = "Position", y = "Mean Modification Probability")
73 73
 
74 74
     p_out <- p1
75 75
 
Browse code

Updated documentation

shians authored on 15/01/2025 06:28:24
Showing 1 changed files
... ...
@@ -126,13 +126,16 @@ plot_region_impl <- function(
126 126
 #' @param span DEPRECATED, use smoothing_window instead. Will be removed in next version.
127 127
 #'
128 128
 #' @details
129
-#' This function plots the methylation data for a given region. The region is specified by
130
-#' chromosome, start and end positions. The basic plot contains a smoothed line plot of
131
-#' the methylation of each experimental group. Since V3.0.0 NanoMethViz has changed the
132
-#' smoothing strategy from a loess smoothing to a weighted moving average. This is because
133
-#' the loess smoothing was too computationally expensive for large datasets and had a
134
-#' span parameter that was difficult to tune. The new smoothing strategy is controlled
135
-#' by the smoothing_window argument.
129
+#' This function plots the methylation data for a given region. The main trendline plot shows the average methylation
130
+#' probability across the region. The heatmap plot shows the methylation probability for each read across the region.
131
+#' The gene annotation plot shows the exons of the region. In the heatmap, each row represents one or more
132
+#' non-overlapping reads where the coloured segments represent the methylation probability at each position. Data along
133
+#' a read is connected by a grey line. The gene annotation plot shows the isoforms and exons of genes within the region,
134
+#' with arrows indicating the direction of transcription.
135
+#'
136
+#' Since V3.0.0 NanoMethViz has changed the smoothing strategy from a loess smoothing to a weighted moving average. This
137
+#' is because the loess smoothing was too computationally expensive for large datasets and had a span parameter that was
138
+#' difficult to tune. The new smoothing strategy is controlled by the smoothing_window argument.
136 139
 #'
137 140
 #' @examples
138 141
 #' nmr <- load_example_nanomethresult()
Browse code

Updated region plot x and y axis labels

shians authored on 15/01/2025 04:10:26
Showing 1 changed files
... ...
@@ -53,25 +53,23 @@ plot_region_impl <- function(
53 53
     title <- glue::glue("{chr}:{start}-{end}")
54 54
     xlim <- round(c(start - window_left, end + window_right))
55 55
     p1 <- plot_methylation_data(
56
-        methy_data = methy_data,
57
-        start = start,
58
-        end = end,
59
-        chr = chr,
60
-        title = title,
61
-        anno_regions = anno_regions,
62
-        binary_threshold = binary_threshold,
63
-        avg_method = avg_method,
64
-        spaghetti = spaghetti,
65
-        sample_anno = sample_anno,
66
-        smoothing_window = smoothing_window,
67
-        palette_col = palette,
68
-        line_size = line_size,
69
-        mod_scale = mod_scale
70
-    ) +
71
-        ggplot2::coord_cartesian(
72
-            xlim = xlim,
73
-            expand = FALSE
74
-        )
56
+            methy_data = methy_data,
57
+            start = start,
58
+            end = end,
59
+            chr = chr,
60
+            title = title,
61
+            anno_regions = anno_regions,
62
+            binary_threshold = binary_threshold,
63
+            avg_method = avg_method,
64
+            spaghetti = spaghetti,
65
+            sample_anno = sample_anno,
66
+            smoothing_window = smoothing_window,
67
+            palette_col = palette,
68
+            line_size = line_size,
69
+            mod_scale = mod_scale
70
+        ) +
71
+        ggplot2::coord_cartesian(xlim = xlim, expand = FALSE) +
72
+        ggplot2::labs(x = "Position", y = "Mean Methylation Probability")
75 73
 
76 74
     p_out <- p1
77 75
 
Browse code

Changed heatmap default to TRUE and refactored implementation function for methods

shians authored on 26/03/2024 00:00:43
Showing 1 changed files
... ...
@@ -1,211 +1,4 @@
1
-#' @rdname plot_region
2
-#'
3
-#' @param anno_regions the data.frame of regions to be annotated.
4
-#' @param binary_threshold the modification probability such that calls with
5
-#'   modification probability above the threshold are set to 1 and probabilities
6
-#'   equal to or below the threshold are set to 0.
7
-#' @param avg_method the average method for pre-smoothing at each genomic position.
8
-#'   Data is pre-smoothed at each genomic position before the smoothed aggregate line
9
-#'   is generated for performance reasons. The default is "mean" which corresponds
10
-#'   to the average methylation fraction. The alternative "median" option is
11
-#'   closer to an average within the more common methylation state.
12
-#' @param spaghetti whether or not individual reads should be shown.
13
-#' @param heatmap whether or not read-methylation heatmap should be shown.
14
-#' @param heatmap_subsample how many packed rows of reads to subsample to.
15
-#' @param smoothing_window the window size for smoothing the trend line.
16
-#' @param window_prop the size of flanking region to plot. Can be a vector of two
17
-#'   values for left and right window size. Values indicate proportion of gene
18
-#'   length.
19
-#' @param palette the ggplot colour palette used for groups.
20
-#' @param line_size the size of the lines.
21
-#' @param mod_scale the scale range for modification probabilities. Default c(0, 1), set to "auto" for automatic
22
-#'   limits.
23
-#' @param span DEPRECATED, use smoothing_window instead. Will be removed in next version.
24
-#'
25
-#' @details
26
-#' This function plots the methylation data for a given region. The region is specified by
27
-#' chromosome, start and end positions. The basic plot contains a smoothed line plot of
28
-#' the methylation of each experimental group. Since V3.0.0 NanoMethViz has changed the
29
-#' smoothing strategy from a loess smoothing to a weighted moving average. This is because
30
-#' the loess smoothing was too computationally expensive for large datasets and had a
31
-#' span parameter that was difficult to tune. The new smoothing strategy is controlled
32
-#' by the smoothing_window argument.
33
-#'
34
-#' @examples
35
-#' nmr <- load_example_nanomethresult()
36
-#' plot_region(nmr, "chr7", 6703892, 6730431)
37
-#'
38
-#' @export
39
-setMethod("plot_region",
40
-    signature(
41
-        x = "NanoMethResult",
42
-        chr = "character",
43
-        start = "numeric",
44
-        end = "numeric"),
45
-
46
-    function(
47
-        x,
48
-        chr,
49
-        start,
50
-        end,
51
-        anno_regions = NULL,
52
-        binary_threshold = NULL,
53
-        avg_method = c("mean", "median"),
54
-        spaghetti = FALSE,
55
-        heatmap = FALSE,
56
-        heatmap_subsample = 50,
57
-        smoothing_window = 2000,
58
-        gene_anno = TRUE,
59
-        window_prop = 0,
60
-        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
61
-        line_size = 1,
62
-        mod_scale = c(0, 1),
63
-        span = NULL
64
-    ) {
65
-        if (!missing("span")) {
66
-            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
67
-        }
68
-        avg_method <- match.arg(avg_method)
69
-
70
-        plot_region_impl(
71
-            x = x,
72
-            chr = chr,
73
-            start = start,
74
-            end = end,
75
-            anno_regions = anno_regions,
76
-            binary_threshold = binary_threshold,
77
-            avg_method = avg_method,
78
-            spaghetti = spaghetti,
79
-            heatmap = heatmap,
80
-            heatmap_subsample = heatmap_subsample,
81
-            smoothing_window = smoothing_window,
82
-            gene_anno = gene_anno,
83
-            window_prop = window_prop,
84
-            palette = palette,
85
-            line_size = line_size,
86
-            mod_scale = mod_scale
87
-        )
88
-    }
89
-)
90
-
91
-#' @rdname plot_region
92
-#' @export
93
-setMethod("plot_region",
94
-    signature(
95
-        x = "ModBamResult",
96
-        chr = "character",
97
-        start = "numeric",
98
-        end = "numeric"),
99
-
100
-    function(
101
-        x,
102
-        chr,
103
-        start,
104
-        end,
105
-        anno_regions = NULL,
106
-        binary_threshold = NULL,
107
-        avg_method = c("mean", "median"),
108
-        spaghetti = FALSE,
109
-        heatmap = FALSE,
110
-        heatmap_subsample = 50,
111
-        smoothing_window = 2000,
112
-        gene_anno = TRUE,
113
-        window_prop = 0,
114
-        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
115
-        line_size = 1,
116
-        mod_scale = c(0, 1),
117
-        span = NULL
118
-    ) {
119
-        if (!missing("span")) {
120
-            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
121
-        }
122
-        avg_method <- match.arg(avg_method)
123
-
124
-        plot_region_impl(
125
-            x = x,
126
-            chr = chr,
127
-            start = start,
128
-            end = end,
129
-            anno_regions = anno_regions,
130
-            binary_threshold = binary_threshold,
131
-            avg_method = avg_method,
132
-            spaghetti = spaghetti,
133
-            heatmap = heatmap,
134
-            heatmap_subsample = heatmap_subsample,
135
-            smoothing_window = smoothing_window,
136
-            gene_anno = gene_anno,
137
-            window_prop = window_prop,
138
-            palette = palette,
139
-            line_size = line_size,
140
-            mod_scale = mod_scale
141
-        )
142
-    }
143
-)
144
-
145
-#' @rdname plot_region
146
-#' @export
147
-setMethod("plot_region",
148
-    signature(
149
-        x = "NanoMethResult",
150
-        chr = "factor",
151
-        start = "numeric",
152
-        end = "numeric"),
153
-
154
-    function(
155
-        x,
156
-        chr,
157
-        start,
158
-        end,
159
-        anno_regions = NULL,
160
-        binary_threshold = NULL,
161
-        avg_method = c("mean", "median"),
162
-        spaghetti = FALSE,
163
-        heatmap = FALSE,
164
-        heatmap_subsample = 50,
165
-        smoothing_window = 2000,
166
-        gene_anno = TRUE,
167
-        window_prop = 0,
168
-        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
169
-        line_size = 1,
170
-        mod_scale = c(0, 1),
171
-        span = NULL
172
-    ) {
173
-        if (!missing("span")) {
174
-            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
175
-        }
176
-        avg_method <- match.arg(avg_method)
177
-
178
-        plot_region_impl(
179
-            x = x,
180
-            chr = chr,
181
-            start = start,
182
-            end = end,
183
-            anno_regions = anno_regions,
184
-            binary_threshold = binary_threshold,
185
-            avg_method = avg_method,
186
-            spaghetti = spaghetti,
187
-            heatmap = heatmap,
188
-            heatmap_subsample = heatmap_subsample,
189
-            smoothing_window = smoothing_window,
190
-            gene_anno = gene_anno,
191
-            window_prop = window_prop,
192
-            palette = palette,
193
-            line_size = line_size,
194
-            mod_scale = mod_scale
195
-        )
196
-    }
197
-)
198
-
199
-#' @rdname plot_region
200
-#' @export
201
-setMethod("plot_region",
202
-    signature(
203
-        x = "ModBamResult",
204
-        chr = "factor",
205
-        start = "numeric",
206
-        end = "numeric"),
207
-
208
-    function(
1
+plot_region_impl <- function(
209 2
         x,
210 3
         chr,
211 4
         start,
... ...
@@ -214,7 +7,7 @@ setMethod("plot_region",
214 7
         binary_threshold = NULL,
215 8
         avg_method = c("mean", "median"),
216 9
         spaghetti = FALSE,
217
-        heatmap = FALSE,
10
+        heatmap = TRUE,
218 11
         heatmap_subsample = 50,
219 12
         smoothing_window = 2000,
220 13
         gene_anno = TRUE,
... ...
@@ -223,50 +16,6 @@ setMethod("plot_region",
223 16
         line_size = 1,
224 17
         mod_scale = c(0, 1),
225 18
         span = NULL
226
-    ) {
227
-        if (!missing("span")) {
228
-            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
229
-        }
230
-        avg_method <- match.arg(avg_method)
231
-
232
-        plot_region_impl(
233
-            x = x,
234
-            chr = chr,
235
-            start = start,
236
-            end = end,
237
-            anno_regions = anno_regions,
238
-            binary_threshold = binary_threshold,
239
-            avg_method = avg_method,
240
-            spaghetti = spaghetti,
241
-            heatmap = heatmap,
242
-            heatmap_subsample = heatmap_subsample,
243
-            smoothing_window = smoothing_window,
244
-            gene_anno = gene_anno,
245
-            window_prop = window_prop,
246
-            palette = palette,
247
-            line_size = line_size,
248
-            mod_scale = mod_scale
249
-        )
250
-    }
251
-)
252
-
253
-plot_region_impl <- function(
254
-    x,
255
-    chr,
256
-    start,
257
-    end,
258
-    anno_regions,
259
-    binary_threshold,
260
-    avg_method,
261
-    spaghetti,
262
-    heatmap,
263
-    heatmap_subsample,
264
-    smoothing_window,
265
-    gene_anno,
266
-    window_prop,
267
-    palette,
268
-    line_size,
269
-    mod_scale
270 19
 ) {
271 20
     sample_anno <- samples(x)
272 21
     chr <- as.character(chr)
... ...
@@ -352,3 +101,68 @@ plot_region_impl <- function(
352 101
 
353 102
     p_out
354 103
 }
104
+
105
+#' @rdname plot_region
106
+#'
107
+#' @param anno_regions the data.frame of regions to be annotated.
108
+#' @param binary_threshold the modification probability such that calls with
109
+#'   modification probability above the threshold are set to 1 and probabilities
110
+#'   equal to or below the threshold are set to 0.
111
+#' @param avg_method the average method for pre-smoothing at each genomic position.
112
+#'   Data is pre-smoothed at each genomic position before the smoothed aggregate line
113
+#'   is generated for performance reasons. The default is "mean" which corresponds
114
+#'   to the average methylation fraction. The alternative "median" option is
115
+#'   closer to an average within the more common methylation state.
116
+#' @param spaghetti whether or not individual reads should be shown.
117
+#' @param heatmap whether or not read-methylation heatmap should be shown.
118
+#' @param heatmap_subsample how many packed rows of reads to subsample to.
119
+#' @param smoothing_window the window size for smoothing the trend line.
120
+#' @param gene_anno whether to show gene annotation.
121
+#' @param window_prop the size of flanking region to plot. Can be a vector of two
122
+#'   values for left and right window size. Values indicate proportion of gene
123
+#'   length.
124
+#' @param palette the ggplot colour palette used for groups.
125
+#' @param line_size the size of the lines.
126
+#' @param mod_scale the scale range for modification probabilities. Default c(0, 1), set to "auto" for automatic
127
+#'   limits.
128
+#' @param span DEPRECATED, use smoothing_window instead. Will be removed in next version.
129
+#'
130
+#' @details
131
+#' This function plots the methylation data for a given region. The region is specified by
132
+#' chromosome, start and end positions. The basic plot contains a smoothed line plot of
133
+#' the methylation of each experimental group. Since V3.0.0 NanoMethViz has changed the
134
+#' smoothing strategy from a loess smoothing to a weighted moving average. This is because
135
+#' the loess smoothing was too computationally expensive for large datasets and had a
136
+#' span parameter that was difficult to tune. The new smoothing strategy is controlled
137
+#' by the smoothing_window argument.
138
+#'
139
+#' @examples
140
+#' nmr <- load_example_nanomethresult()
141
+#' plot_region(nmr, "chr7", 6703892, 6730431)
142
+#'
143
+#' @export
144
+setMethod("plot_region",
145
+    signature(x = "NanoMethResult", chr = "character", start = "numeric", end = "numeric"),
146
+    plot_region_impl
147
+)
148
+
149
+#' @rdname plot_region
150
+#' @export
151
+setMethod("plot_region",
152
+    signature(x = "ModBamResult", chr = "character", start = "numeric", end = "numeric"),
153
+    plot_region_impl
154
+)
155
+
156
+#' @rdname plot_region
157
+#' @export
158
+setMethod("plot_region",
159
+    signature(x = "NanoMethResult", chr = "factor", start = "numeric", end = "numeric"),
160
+    plot_region_impl
161
+)
162
+
163
+#' @rdname plot_region
164
+#' @export
165
+setMethod("plot_region",
166
+    signature(x = "ModBamResult", chr = "factor", start = "numeric", end = "numeric"),
167
+    plot_region_impl
168
+)
Browse code

Refactored plot_gene to use plot_region

shians authored on 13/03/2024 06:21:02
Showing 1 changed files
... ...
@@ -42,6 +42,7 @@ setMethod("plot_region",
42 42
         chr = "character",
43 43
         start = "numeric",
44 44
         end = "numeric"),
45
+
45 46
     function(
46 47
         x,
47 48
         chr,
... ...
@@ -54,6 +55,7 @@ setMethod("plot_region",
54 55
         heatmap = FALSE,
55 56
         heatmap_subsample = 50,
56 57
         smoothing_window = 2000,
58
+        gene_anno = TRUE,
57 59
         window_prop = 0,
58 60
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
59 61
         line_size = 1,
... ...
@@ -72,11 +74,12 @@ setMethod("plot_region",
72 74
             end = end,
73 75
             anno_regions = anno_regions,
74 76
             binary_threshold = binary_threshold,
75
-            spaghetti = spaghetti,
76 77
             avg_method = avg_method,
78
+            spaghetti = spaghetti,
77 79
             heatmap = heatmap,
78 80
             heatmap_subsample = heatmap_subsample,
79 81
             smoothing_window = smoothing_window,
82
+            gene_anno = gene_anno,
80 83
             window_prop = window_prop,
81 84
             palette = palette,
82 85
             line_size = line_size,
... ...
@@ -93,6 +96,7 @@ setMethod("plot_region",
93 96
         chr = "character",
94 97
         start = "numeric",
95 98
         end = "numeric"),
99
+
96 100
     function(
97 101
         x,
98 102
         chr,
... ...
@@ -105,6 +109,7 @@ setMethod("plot_region",
105 109
         heatmap = FALSE,
106 110
         heatmap_subsample = 50,
107 111
         smoothing_window = 2000,
112
+        gene_anno = TRUE,
108 113
         window_prop = 0,
109 114
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
110 115
         line_size = 1,
... ...
@@ -123,11 +128,12 @@ setMethod("plot_region",
123 128
             end = end,
124 129
             anno_regions = anno_regions,
125 130
             binary_threshold = binary_threshold,
126
-            spaghetti = spaghetti,
127 131
             avg_method = avg_method,
132
+            spaghetti = spaghetti,
128 133
             heatmap = heatmap,
129 134
             heatmap_subsample = heatmap_subsample,
130 135
             smoothing_window = smoothing_window,
136
+            gene_anno = gene_anno,
131 137
             window_prop = window_prop,
132 138
             palette = palette,
133 139
             line_size = line_size,
... ...
@@ -157,6 +163,7 @@ setMethod("plot_region",
157 163
         heatmap = FALSE,
158 164
         heatmap_subsample = 50,
159 165
         smoothing_window = 2000,
166
+        gene_anno = TRUE,
160 167
         window_prop = 0,
161 168
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
162 169
         line_size = 1,
... ...
@@ -166,9 +173,9 @@ setMethod("plot_region",
166 173
         if (!missing("span")) {
167 174
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
168 175
         }
169
-        chr <- as.character(chr)
170 176
         avg_method <- match.arg(avg_method)
171
-        plot_region(
177
+
178
+        plot_region_impl(
172 179
             x = x,
173 180
             chr = chr,
174 181
             start = start,
... ...
@@ -180,6 +187,7 @@ setMethod("plot_region",
180 187
             heatmap = heatmap,
181 188
             heatmap_subsample = heatmap_subsample,
182 189
             smoothing_window = smoothing_window,
190
+            gene_anno = gene_anno,
183 191
             window_prop = window_prop,
184 192
             palette = palette,
185 193
             line_size = line_size,
... ...
@@ -209,6 +217,7 @@ setMethod("plot_region",
209 217
         heatmap = FALSE,
210 218
         heatmap_subsample = 50,
211 219
         smoothing_window = 2000,
220
+        gene_anno = TRUE,
212 221
         window_prop = 0,
213 222
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
214 223
         line_size = 1,
... ...
@@ -218,9 +227,9 @@ setMethod("plot_region",
218 227
         if (!missing("span")) {
219 228
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
220 229
         }
221
-        chr <- as.character(chr)
222 230
         avg_method <- match.arg(avg_method)
223
-        plot_region(
231
+
232
+        plot_region_impl(
224 233
             x = x,
225 234
             chr = chr,
226 235
             start = start,
... ...
@@ -232,6 +241,7 @@ setMethod("plot_region",
232 241
             heatmap = heatmap,
233 242
             heatmap_subsample = heatmap_subsample,
234 243
             smoothing_window = smoothing_window,
244
+            gene_anno = gene_anno,
235 245
             window_prop = window_prop,
236 246
             palette = palette,
237 247
             line_size = line_size,
... ...
@@ -252,12 +262,16 @@ plot_region_impl <- function(
252 262
     heatmap,
253 263
     heatmap_subsample,
254 264
     smoothing_window,
265
+    gene_anno,
255 266
     window_prop,
256 267
     palette,
257 268
     line_size,
258 269
     mod_scale
259 270
 ) {
260 271
     sample_anno <- samples(x)
272
+    chr <- as.character(chr)
273
+    start <- as.numeric(start)
274
+    end <- as.numeric(end)
261 275
 
262 276
     if (length(window_prop) == 1) {
263 277
         window_prop <- c(window_prop, window_prop)
... ...
@@ -313,8 +327,8 @@ plot_region_impl <- function(
313 327
     p_out <- p1
314 328
 
315 329
     # if exon anno exists, append it to plot
316
-    if (nrow(exons(x)) != 0) {
317
-        exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
330
+    if (gene_anno && nrow(exons(x)) != 0) {
331
+        exons_anno <- query_exons_region(x, chr = chr, start = start, end = end)
318 332
 
319 333
         p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
320 334
             ggplot2::coord_cartesian(xlim = xlim, expand = FALSE) +
Browse code

Changed default smoothing window to 2kb

shians authored on 26/02/2024 06:23:26
Showing 1 changed files
... ...
@@ -53,7 +53,7 @@ setMethod("plot_region",
53 53
         spaghetti = FALSE,
54 54
         heatmap = FALSE,
55 55
         heatmap_subsample = 50,
56
-        smoothing_window = 500,
56
+        smoothing_window = 2000,
57 57
         window_prop = 0,
58 58
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
59 59
         line_size = 1,
... ...
@@ -104,7 +104,7 @@ setMethod("plot_region",
104 104
         spaghetti = FALSE,
105 105
         heatmap = FALSE,
106 106
         heatmap_subsample = 50,
107
-        smoothing_window = 500,
107
+        smoothing_window = 2000,
108 108
         window_prop = 0,
109 109
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
110 110
         line_size = 1,
... ...
@@ -156,7 +156,7 @@ setMethod("plot_region",
156 156
         spaghetti = FALSE,
157 157
         heatmap = FALSE,
158 158
         heatmap_subsample = 50,
159
-        smoothing_window = 500,
159
+        smoothing_window = 2000,
160 160
         window_prop = 0,
161 161
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
162 162
         line_size = 1,
... ...
@@ -208,7 +208,7 @@ setMethod("plot_region",
208 208
         spaghetti = FALSE,
209 209
         heatmap = FALSE,
210 210
         heatmap_subsample = 50,
211
-        smoothing_window = 500,
211
+        smoothing_window = 2000,
212 212
         window_prop = 0,
213 213
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
214 214
         line_size = 1,
Browse code

Reformat code

shians authored on 25/02/2024 23:45:06
Showing 1 changed files
... ...
@@ -267,16 +267,17 @@ plot_region_impl <- function(
267 267
     window_left <- feature_width * window_prop[1]
268 268
     window_right <- feature_width * window_prop[2]
269 269
 
270
-    methy_data <-
271
-        query_methy(
272
-            x,
273
-            chr,
274
-            floor(start - window_left * 1.1),
275
-            ceiling(end + window_right * 1.1),
276
-            simplify = TRUE)
270
+    # query data
271
+    methy_data <- query_methy(
272
+        x,
273
+        chr,
274
+        floor(start - window_left * 1.1),
275
+        ceiling(end + window_right * 1.1),
276
+        simplify = TRUE
277
+    )
277 278
 
278 279
     if (nrow(methy_data) == 0) {
279
-        warning("no methylation data in region")
280
+        warning("no methylation data in region, returning empty plot")
280 281
         return(ggplot() + theme_void())
281 282
     }
282 283
 
... ...
@@ -284,6 +285,8 @@ plot_region_impl <- function(
284 285
         dplyr::select(-"strand") %>%
285 286
         tibble::as_tibble()
286 287
 
288
+
289
+    # setup base plot
287 290
     title <- glue::glue("{chr}:{start}-{end}")
288 291
     xlim <- round(c(start - window_left, end + window_right))
289 292
     p1 <- plot_methylation_data(
... ...
@@ -309,35 +312,27 @@ plot_region_impl <- function(
309 312
 
310 313
     p_out <- p1
311 314
 
312
-    # if exon anno exists
315
+    # if exon anno exists, append it to plot
313 316
     if (nrow(exons(x)) != 0) {
314
-        exons_anno <- query_exons_region(
315
-            exons(x),
316
-            chr = chr,
317
-            start = start,
318
-            end = end
319
-        )
317
+        exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
320 318
 
321 319
         p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
322
-            ggplot2::coord_cartesian(
323
-                xlim = xlim,
324
-                expand = FALSE
325
-            ) +
326
-                ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
327
-        anno_height <- attr(p2, "plot_height")
320
+            ggplot2::coord_cartesian(xlim = xlim, expand = FALSE) +
321
+            ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
328 322
 
323
+        anno_height <- attr(p2, "plot_height")
329 324
         heights <- c(1, 0.075 * anno_height)
325
+
330 326
         p_out <- p1 / p2 + patchwork::plot_layout(heights = heights)
331 327
     }
332 328
 
333
-    # if heatmap requested
329
+    # if heatmap requested, append it to plot
334 330
     if (heatmap) {
335 331
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop, subsample = heatmap_subsample) +
336 332
             ggplot2::coord_cartesian(
337 333
                 xlim = xlim
338 334
             )
339 335
 
340
-
341 336
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
342 337
     }
343 338
 
Browse code

Updated docs

Shians authored on 09/01/2024 07:21:53
Showing 1 changed files
... ...
@@ -85,6 +85,7 @@ setMethod("plot_region",
85 85
     }
86 86
 )
87 87
 
88
+#' @rdname plot_region
88 89
 #' @export
89 90
 setMethod("plot_region",
90 91
     signature(
... ...
@@ -135,6 +136,7 @@ setMethod("plot_region",
135 136
     }
136 137
 )
137 138
 
139
+#' @rdname plot_region
138 140
 #' @export
139 141
 setMethod("plot_region",
140 142
     signature(
... ...
@@ -186,6 +188,7 @@ setMethod("plot_region",
186 188
     }
187 189
 )
188 190
 
191
+#' @rdname plot_region
189 192
 #' @export
190 193
 setMethod("plot_region",
191 194
     signature(
Browse code

Fixed deprecation of span

Shians authored on 13/12/2023 05:50:31
Showing 1 changed files
... ...
@@ -20,6 +20,7 @@
20 20
 #' @param line_size the size of the lines.
21 21
 #' @param mod_scale the scale range for modification probabilities. Default c(0, 1), set to "auto" for automatic
22 22
 #'   limits.
23
+#' @param span DEPRECATED, use smoothing_window instead. Will be removed in next version.
23 24
 #'
24 25
 #' @details
25 26
 #' This function plots the methylation data for a given region. The region is specified by
... ...
@@ -56,7 +57,8 @@ setMethod("plot_region",
56 57
         window_prop = 0,
57 58
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
58 59
         line_size = 1,
59
-        mod_scale = c(0, 1)
60
+        mod_scale = c(0, 1),
61
+        span = NULL
60 62
     ) {
61 63
         if (!missing("span")) {
62 64
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
... ...
@@ -105,7 +107,8 @@ setMethod("plot_region",
105 107
         window_prop = 0,
106 108
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
107 109
         line_size = 1,
108
-        mod_scale = c(0, 1)
110
+        mod_scale = c(0, 1),
111
+        span = NULL
109 112
     ) {
110 113
         if (!missing("span")) {
111 114
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
... ...
@@ -155,7 +158,8 @@ setMethod("plot_region",
155 158
         window_prop = 0,
156 159
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
157 160
         line_size = 1,
158
-        mod_scale = c(0, 1)
161
+        mod_scale = c(0, 1),
162
+        span = NULL
159 163
     ) {
160 164
         if (!missing("span")) {
161 165
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
... ...
@@ -205,7 +209,8 @@ setMethod("plot_region",
205 209
         window_prop = 0,
206 210
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
207 211
         line_size = 1,
208
-        mod_scale = c(0, 1)
212
+        mod_scale = c(0, 1),
213
+        span = NULL
209 214
     ) {
210 215
         if (!missing("span")) {
211 216
             warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
Browse code

Deprecated span argument

Shians authored on 13/12/2023 05:31:07
Showing 1 changed files
... ...
@@ -12,7 +12,7 @@
12 12
 #' @param spaghetti whether or not individual reads should be shown.
13 13
 #' @param heatmap whether or not read-methylation heatmap should be shown.
14 14
 #' @param heatmap_subsample how many packed rows of reads to subsample to.
15
-#' @param span the span for loess smoothing.
15
+#' @param smoothing_window the window size for smoothing the trend line.
16 16
 #' @param window_prop the size of flanking region to plot. Can be a vector of two
17 17
 #'   values for left and right window size. Values indicate proportion of gene
18 18
 #'   length.
... ...
@@ -21,6 +21,15 @@
21 21
 #' @param mod_scale the scale range for modification probabilities. Default c(0, 1), set to "auto" for automatic
22 22
 #'   limits.
23 23
 #'
24
+#' @details
25
+#' This function plots the methylation data for a given region. The region is specified by
26
+#' chromosome, start and end positions. The basic plot contains a smoothed line plot of
27
+#' the methylation of each experimental group. Since V3.0.0 NanoMethViz has changed the
28
+#' smoothing strategy from a loess smoothing to a weighted moving average. This is because
29
+#' the loess smoothing was too computationally expensive for large datasets and had a
30
+#' span parameter that was difficult to tune. The new smoothing strategy is controlled
31
+#' by the smoothing_window argument.
32
+#'
24 33
 #' @examples
25 34
 #' nmr <- load_example_nanomethresult()
26 35
 #' plot_region(nmr, "chr7", 6703892, 6730431)
... ...
@@ -43,12 +52,15 @@ setMethod("plot_region",
43 52
         spaghetti = FALSE,
44 53
         heatmap = FALSE,
45 54
         heatmap_subsample = 50,
46
-        span = NULL,
55
+        smoothing_window = 500,
47 56
         window_prop = 0,
48 57
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
49 58
         line_size = 1,
50 59
         mod_scale = c(0, 1)
51 60
     ) {
61
+        if (!missing("span")) {
62
+            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
63
+        }
52 64
         avg_method <- match.arg(avg_method)
53 65
 
54 66
         plot_region_impl(
... ...
@@ -71,8 +83,6 @@ setMethod("plot_region",
71 83
     }
72 84
 )
73 85
 
74
-#' @rdname plot_region
75
-#'
76 86
 #' @export
77 87
 setMethod("plot_region",
78 88
     signature(
... ...
@@ -97,6 +107,9 @@ setMethod("plot_region",
97 107
         line_size = 1,
98 108
         mod_scale = c(0, 1)
99 109
     ) {
110
+        if (!missing("span")) {
111
+            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
112
+        }
100 113
         avg_method <- match.arg(avg_method)
101 114
 
102 115
         plot_region_impl(
... ...
@@ -119,8 +132,6 @@ setMethod("plot_region",
119 132
     }
120 133
 )
121 134
 
122
-#' @rdname plot_region
123
-#'
124 135
 #' @export
125 136
 setMethod("plot_region",
126 137
     signature(
... ...
@@ -146,6 +157,9 @@ setMethod("plot_region",
146 157
         line_size = 1,
147 158
         mod_scale = c(0, 1)
148 159
     ) {
160
+        if (!missing("span")) {
161
+            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
162
+        }
149 163
         chr <- as.character(chr)
150 164
         avg_method <- match.arg(avg_method)
151 165
         plot_region(
... ...
@@ -159,7 +173,7 @@ setMethod("plot_region",
159 173
             spaghetti = spaghetti,
160 174
             heatmap = heatmap,
161 175
             heatmap_subsample = heatmap_subsample,
162
-            span = span,
176
+            smoothing_window = smoothing_window,
163 177
             window_prop = window_prop,
164 178
             palette = palette,
165 179
             line_size = line_size,
... ...
@@ -168,8 +182,6 @@ setMethod("plot_region",
168 182
     }
169 183
 )
170 184
 
171
-#' @rdname plot_region
172
-#'
173 185
 #' @export
174 186
 setMethod("plot_region",
175 187
     signature(
... ...
@@ -195,6 +207,9 @@ setMethod("plot_region",
195 207
         line_size = 1,
196 208
         mod_scale = c(0, 1)
197 209
     ) {
210
+        if (!missing("span")) {
211
+            warning("the 'span' argument has been deprecated, please use 'smoothing_window' instead")
212
+        }
198 213
         chr <- as.character(chr)
199 214
         avg_method <- match.arg(avg_method)
200 215
         plot_region(
... ...
@@ -208,7 +223,7 @@ setMethod("plot_region",
208 223
             spaghetti = spaghetti,
209 224
             heatmap = heatmap,
210 225
             heatmap_subsample = heatmap_subsample,
211
-            span = span,
226
+            smoothing_window = smoothing_window,
212 227
             window_prop = window_prop,
213 228
             palette = palette,
214 229
             line_size = line_size,
Browse code

Replaced span with smoothing_window

Shians authored on 13/12/2023 04:44:21
Showing 1 changed files
... ...
@@ -51,7 +51,7 @@ setMethod("plot_region",
51 51
     ) {
52 52
         avg_method <- match.arg(avg_method)
53 53
 
54
-        .plot_region(
54
+        plot_region_impl(
55 55
             x = x,
56 56
             chr = chr,
57 57
             start = start,
... ...
@@ -61,8 +61,8 @@ setMethod("plot_region",
61 61
             spaghetti = spaghetti,
62 62
             avg_method = avg_method,
63 63
             heatmap = heatmap,
64
-            heatmap_subsample,
65
-            span = span,
64
+            heatmap_subsample = heatmap_subsample,
65
+            smoothing_window = smoothing_window,
66 66
             window_prop = window_prop,
67 67
             palette = palette,
68 68
             line_size = line_size,
... ...
@@ -91,7 +91,7 @@ setMethod("plot_region",
91 91
         spaghetti = FALSE,
92 92
         heatmap = FALSE,
93 93
         heatmap_subsample = 50,
94
-        span = NULL,
94
+        smoothing_window = 500,
95 95
         window_prop = 0,
96 96
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
97 97
         line_size = 1,
... ...
@@ -99,7 +99,7 @@ setMethod("plot_region",
99 99
     ) {
100 100
         avg_method <- match.arg(avg_method)
101 101
 
102
-        .plot_region(
102
+        plot_region_impl(
103 103
             x = x,
104 104
             chr = chr,
105 105
             start = start,
... ...
@@ -110,7 +110,7 @@ setMethod("plot_region",
110 110
             avg_method = avg_method,
111 111
             heatmap = heatmap,
112 112
             heatmap_subsample = heatmap_subsample,
113
-            span = span,
113
+            smoothing_window = smoothing_window,
114 114
             window_prop = window_prop,
115 115
             palette = palette,
116 116
             line_size = line_size,
... ...
@@ -140,7 +140,7 @@ setMethod("plot_region",
140 140
         spaghetti = FALSE,
141 141
         heatmap = FALSE,
142 142
         heatmap_subsample = 50,
143
-        span = NULL,
143
+        smoothing_window = 500,
144 144
         window_prop = 0,
145 145
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
146 146
         line_size = 1,
... ...
@@ -189,7 +189,7 @@ setMethod("plot_region",
189 189
         spaghetti = FALSE,
190 190
         heatmap = FALSE,
191 191
         heatmap_subsample = 50,
192
-        span = NULL,
192
+        smoothing_window = 500,
193 193
         window_prop = 0,
194 194
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
195 195
         line_size = 1,
... ...
@@ -217,7 +217,7 @@ setMethod("plot_region",
217 217
     }
218 218
 )
219 219
 
220
-.plot_region <- function(
220
+plot_region_impl <- function(
221 221
     x,
222 222
     chr,
223 223
     start,
... ...
@@ -228,7 +228,7 @@ setMethod("plot_region",
228 228
     spaghetti,
229 229
     heatmap,
230 230
     heatmap_subsample,
231
-    span,
231
+    smoothing_window,
232 232
     window_prop,
233 233
     palette,
234 234
     line_size,
... ...
@@ -274,7 +274,7 @@ setMethod("plot_region",
274 274
         avg_method = avg_method,
275 275
         spaghetti = spaghetti,
276 276
         sample_anno = sample_anno,
277
-        span = span,
277
+        smoothing_window = smoothing_window,
278 278
         palette_col = palette,
279 279
         line_size = line_size,
280 280
         mod_scale = mod_scale
Browse code

Changed default line_size to 1

Shians authored on 28/08/2023 05:46:31
Showing 1 changed files
... ...
@@ -46,7 +46,7 @@ setMethod("plot_region",
46 46
         span = NULL,
47 47
         window_prop = 0,
48 48
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
49
-        line_size = 2,
49
+        line_size = 1,
50 50
         mod_scale = c(0, 1)
51 51
     ) {
52 52
         avg_method <- match.arg(avg_method)
... ...
@@ -94,7 +94,7 @@ setMethod("plot_region",
94 94
         span = NULL,
95 95
         window_prop = 0,
96 96
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
97
-        line_size = 2,
97
+        line_size = 1,
98 98
         mod_scale = c(0, 1)
99 99
     ) {
100 100
         avg_method <- match.arg(avg_method)
... ...
@@ -143,7 +143,7 @@ setMethod("plot_region",
143 143
         span = NULL,
144 144
         window_prop = 0,
145 145
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
146
-        line_size = 2,
146
+        line_size = 1,
147 147
         mod_scale = c(0, 1)
148 148
     ) {
149 149
         chr <- as.character(chr)
... ...
@@ -192,7 +192,7 @@ setMethod("plot_region",
192 192
         span = NULL,
193 193
         window_prop = 0,
194 194
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
195
-        line_size = 2,
195
+        line_size = 1,
196 196
         mod_scale = c(0, 1)
197 197
     ) {
198 198
         chr <- as.character(chr)
Browse code

Fixed handling of regions without reads

Shians authored on 18/07/2023 00:43:25
Showing 1 changed files
... ...
@@ -250,15 +250,17 @@ setMethod("plot_region",
250 250
             chr,
251 251
             floor(start - window_left * 1.1),
252 252
             ceiling(end + window_right * 1.1),
253
-            simplify = TRUE) %>%
254
-        dplyr::select(-"strand") %>%
255
-        tibble::as_tibble()
253
+            simplify = TRUE)
256 254
 
257 255
     if (nrow(methy_data) == 0) {
258 256
         warning("no methylation data in region")
259 257
         return(ggplot() + theme_void())
260 258
     }
261 259
 
260
+    methy_data <- methy_data %>%
261
+        dplyr::select(-"strand") %>%
262
+        tibble::as_tibble()
263
+
262 264
     title <- glue::glue("{chr}:{start}-{end}")
263 265
     xlim <- round(c(start - window_left, end + window_right))
264 266
     p1 <- plot_methylation_data(
Browse code

Allowed expansion on heatmap

Shians authored on 14/07/2023 06:00:10
Showing 1 changed files
... ...
@@ -309,8 +309,7 @@ setMethod("plot_region",
309 309
     if (heatmap) {
310 310
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop, subsample = heatmap_subsample) +
311 311
             ggplot2::coord_cartesian(
312
-                xlim = xlim,
313
-                expand = FALSE
312
+                xlim = xlim
314 313
             )
315 314
 
316 315
 
Browse code

Added missing arguments

Shians authored on 13/07/2023 03:35:42
Showing 1 changed files
... ...
@@ -65,7 +65,8 @@ setMethod("plot_region",
65 65
             span = span,
66 66
             window_prop = window_prop,
67 67
             palette = palette,
68
-            line_size = line_size
68
+            line_size = line_size,
69
+            mod_scale = mod_scale
69 70
         )
70 71
     }
71 72
 )
... ...
@@ -112,7 +113,8 @@ setMethod("plot_region",
112 113
             span = span,
113 114
             window_prop = window_prop,
114 115
             palette = palette,
115
-            line_size = line_size
116
+            line_size = line_size,
117
+            mod_scale = mod_scale
116 118
         )
117 119
     }
118 120
 )
Browse code

Refactored internal plotting code

Shians authored on 12/07/2023 14:16:52
Showing 1 changed files
... ...
@@ -18,6 +18,8 @@
18 18
 #'   length.
19 19
 #' @param palette the ggplot colour palette used for groups.
20 20
 #' @param line_size the size of the lines.
21
+#' @param mod_scale the scale range for modification probabilities. Default c(0, 1), set to "auto" for automatic
22
+#'   limits.
21 23
 #'
22 24
 #' @examples
23 25
 #' nmr <- load_example_nanomethresult()
... ...
@@ -44,7 +46,8 @@ setMethod("plot_region",
44 46
         span = NULL,
45 47
         window_prop = 0,
46 48
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
47
-        line_size = 2
49
+        line_size = 2,
50
+        mod_scale = c(0, 1)
48 51
     ) {
49 52
         avg_method <- match.arg(avg_method)
50 53
 
... ...
@@ -90,7 +93,8 @@ setMethod("plot_region",
90 93
         span = NULL,
91 94
         window_prop = 0,
92 95
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
93
-        line_size = 2
96
+        line_size = 2,
97
+        mod_scale = c(0, 1)
94 98
     ) {
95 99
         avg_method <- match.arg(avg_method)
96 100
 
... ...
@@ -137,7 +141,8 @@ setMethod("plot_region",
137 141
         span = NULL,
138 142
         window_prop = 0,
139 143
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
140
-        line_size = 2
144
+        line_size = 2,
145
+        mod_scale = c(0, 1)
141 146
     ) {
142 147
         chr <- as.character(chr)
143 148
         avg_method <- match.arg(avg_method)
... ...
@@ -155,7 +160,8 @@ setMethod("plot_region",
155 160
             span = span,
156 161
             window_prop = window_prop,
157 162
             palette = palette,
158
-            line_size = line_size
163
+            line_size = line_size,
164
+            mod_scale = mod_scale
159 165
         )
160 166
     }
161 167
 )
... ...
@@ -184,7 +190,8 @@ setMethod("plot_region",
184 190
         span = NULL,
185 191
         window_prop = 0,
186 192
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
187
-        line_size = 2
193
+        line_size = 2,
194
+        mod_scale = c(0, 1)
188 195
     ) {
189 196
         chr <- as.character(chr)
190 197
         avg_method <- match.arg(avg_method)
... ...
@@ -202,7 +209,8 @@ setMethod("plot_region",
202 209
             span = span,
203 210
             window_prop = window_prop,
204 211
             palette = palette,
205
-            line_size = line_size
212
+            line_size = line_size,
213
+            mod_scale = mod_scale
206 214
         )
207 215
     }
208 216
 )
... ...
@@ -221,7 +229,8 @@ setMethod("plot_region",
221 229
     span,
222 230
     window_prop,
223 231
     palette,
224
-    line_size
232
+    line_size,
233
+    mod_scale
225 234
 ) {
226 235
     sample_anno <- samples(x)
227 236
 
... ...
@@ -263,13 +272,13 @@ setMethod("plot_region",
263 272
         sample_anno = sample_anno,
264 273
         span = span,
265 274
         palette_col = palette,
266
-        line_size = line_size
275
+        line_size = line_size,
276
+        mod_scale = mod_scale
267 277
     ) +
268 278
         ggplot2::coord_cartesian(
269 279
             xlim = xlim,
270 280
             expand = FALSE
271
-        ) +
272
-            ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
281
+        )
273 282
 
274 283
     p_out <- p1
275 284
 
... ...
@@ -300,8 +309,8 @@ setMethod("plot_region",
300 309
             ggplot2::coord_cartesian(
301 310
                 xlim = xlim,
302 311
                 expand = FALSE
303
-            ) +
304
-                ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
312
+            )
313
+
305 314
 
306 315
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
307 316
     }
Browse code

Refactored gene plotting internals

Shians authored on 11/07/2023 13:58:47
Showing 1 changed files
... ...
@@ -250,7 +250,7 @@ setMethod("plot_region",
250 250
 
251 251
     title <- glue::glue("{chr}:{start}-{end}")
252 252
     xlim <- round(c(start - window_left, end + window_right))
253
-    p1 <- plot_methylation_internal(
253
+    p1 <- plot_methylation_data(
254 254
         methy_data = methy_data,
255 255
         start = start,
256 256
         end = end,
Browse code

Added heatmap_subsample argument to plot_gene and plot_region

Shians authored on 30/06/2023 01:53:54
Showing 1 changed files
... ...
@@ -11,6 +11,7 @@
11 11
 #'   closer to an average within the more common methylation state.
12 12
 #' @param spaghetti whether or not individual reads should be shown.
13 13
 #' @param heatmap whether or not read-methylation heatmap should be shown.
14
+#' @param heatmap_subsample how many packed rows of reads to subsample to.
14 15
 #' @param span the span for loess smoothing.
15 16
 #' @param window_prop the size of flanking region to plot. Can be a vector of two
16 17
 #'   values for left and right window size. Values indicate proportion of gene
... ...
@@ -39,6 +40,7 @@ setMethod("plot_region",
39 40
         avg_method = c("mean", "median"),
40 41
         spaghetti = FALSE,
41 42
         heatmap = FALSE,
43
+        heatmap_subsample = 50,
42 44
         span = NULL,
43 45
         window_prop = 0,
44 46
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
... ...
@@ -56,6 +58,7 @@ setMethod("plot_region",
56 58
             spaghetti = spaghetti,
57 59
             avg_method = avg_method,
58 60
             heatmap = heatmap,
61
+            heatmap_subsample,
59 62
             span = span,
60 63
             window_prop = window_prop,
61 64
             palette = palette,
... ...
@@ -83,6 +86,7 @@ setMethod("plot_region",
83 86
         avg_method = c("mean", "median"),
84 87
         spaghetti = FALSE,
85 88
         heatmap = FALSE,
89
+        heatmap_subsample = 50,
86 90
         span = NULL,
87 91
         window_prop = 0,
88 92
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
... ...
@@ -100,6 +104,7 @@ setMethod("plot_region",
100 104
             spaghetti = spaghetti,
101 105
             avg_method = avg_method,
102 106
             heatmap = heatmap,
107
+            heatmap_subsample = heatmap_subsample,
103 108
             span = span,
104 109
             window_prop = window_prop,
105 110
             palette = palette,
... ...
@@ -128,6 +133,7 @@ setMethod("plot_region",
128 133
         avg_method = c("mean", "median"),
129 134
         spaghetti = FALSE,
130 135
         heatmap = FALSE,
136
+        heatmap_subsample = 50,
131 137
         span = NULL,
132 138
         window_prop = 0,
133 139
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
... ...
@@ -145,6 +151,7 @@ setMethod("plot_region",
145 151
             avg_method = avg_method,
146 152
             spaghetti = spaghetti,
147 153
             heatmap = heatmap,
154
+            heatmap_subsample = heatmap_subsample,
148 155
             span = span,
149 156
             window_prop = window_prop,
150 157
             palette = palette,
... ...
@@ -173,6 +180,7 @@ setMethod("plot_region",
173 180
         avg_method = c("mean", "median"),
174 181
         spaghetti = FALSE,
175 182
         heatmap = FALSE,
183
+        heatmap_subsample = 50,
176 184
         span = NULL,
177 185
         window_prop = 0,
178 186
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
... ...
@@ -190,6 +198,7 @@ setMethod("plot_region",
190 198
             avg_method = avg_method,
191 199
             spaghetti = spaghetti,
192 200
             heatmap = heatmap,
201
+            heatmap_subsample = heatmap_subsample,
193 202
             span = span,
194 203
             window_prop = window_prop,
195 204
             palette = palette,
... ...
@@ -208,6 +217,7 @@ setMethod("plot_region",
208 217
     avg_method,
209 218
     spaghetti,
210 219
     heatmap,
220
+    heatmap_subsample,
211 221
     span,
212 222
     window_prop,
213 223
     palette,
... ...
@@ -286,7 +296,7 @@ setMethod("plot_region",
286 296
 
287 297
     # if heatmap requested
288 298
     if (heatmap) {
289
-        p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
299
+        p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop, subsample = heatmap_subsample) +
290 300
             ggplot2::coord_cartesian(
291 301
                 xlim = xlim,
292 302
                 expand = FALSE
Browse code

Fixed plotting when exon annotations are not available

Shians authored on 23/05/2023 07:31:25
Showing 1 changed files
... ...
@@ -214,12 +214,6 @@ setMethod("plot_region",
214 214
     line_size
215 215
 ) {
216 216
     sample_anno <- samples(x)
217
-    exons_anno <- query_exons_region(
218
-        exons(x),
219
-        chr = chr,
220
-        start = start,
221
-        end = end
222
-    )
223 217
 
224 218
     if (length(window_prop) == 1) {
225 219
         window_prop <- c(window_prop, window_prop)
... ...
@@ -267,18 +261,30 @@ setMethod("plot_region",
267 261
         ) +
268 262
             ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
269 263
 
270
-    p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
271
-        ggplot2::coord_cartesian(
272
-            xlim = xlim,
273
-            expand = FALSE
274
-        ) +
275
-            ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
264
+    p_out <- p1
276 265
 
277
-    anno_height <- attr(p2, "plot_height")
266
+    # if exon anno exists
267
+    if (nrow(exons(x)) != 0) {
268
+        exons_anno <- query_exons_region(
269
+            exons(x),
270
+            chr = chr,
271
+            start = start,
272
+            end = end
273
+        )
274
+
275
+        p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
276
+            ggplot2::coord_cartesian(
277
+                xlim = xlim,
278
+                expand = FALSE
279
+            ) +
280
+                ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
281
+        anno_height <- attr(p2, "plot_height")
278 282
 
279
-    heights <- c(1, 0.075 * anno_height)
280
-    p_out <- p1 / p2 + patchwork::plot_layout(heights = heights)
283
+        heights <- c(1, 0.075 * anno_height)
284
+        p_out <- p1 / p2 + patchwork::plot_layout(heights = heights)
285
+    }
281 286
 
287
+    # if heatmap requested
282 288
     if (heatmap) {
283 289
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
284 290
             ggplot2::coord_cartesian(
Browse code

Removed redundant xlim argument

Shians authored on 11/05/2023 02:19:46
Showing 1 changed files
... ...
@@ -251,7 +251,6 @@ setMethod("plot_region",
251 251
         start = start,
252 252
         end = end,
253 253
         chr = chr,
254
-        xlim = xlim,
255 254
         title = title,
256 255
         anno_regions = anno_regions,
257 256
         binary_threshold = binary_threshold,
Browse code

Added missing namespacing

Shians authored on 14/04/2023 07:36:04
Showing 1 changed files
... ...
@@ -266,14 +266,14 @@ setMethod("plot_region",
266 266
             xlim = xlim,
267 267
             expand = FALSE
268 268
         ) +
269
-            scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
269
+            ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
270 270
 
271 271
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
272 272
         ggplot2::coord_cartesian(
273 273
             xlim = xlim,
274 274
             expand = FALSE
275 275
         ) +
276
-            scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
276
+            ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
277 277
 
278 278
     anno_height <- attr(p2, "plot_height")
279 279
 
... ...
@@ -286,7 +286,7 @@ setMethod("plot_region",
286 286
                 xlim = xlim,
287 287
                 expand = FALSE
288 288
             ) +
289
-                scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
289
+                ggplot2::scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
290 290
 
291 291
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
292 292
     }
Browse code

Updated scales

Shians authored on 14/04/2023 07:16:53
Showing 1 changed files
... ...
@@ -64,6 +64,9 @@ setMethod("plot_region",
64 64
     }
65 65
 )
66 66
 
67
+#' @rdname plot_region
68
+#'
69
+#' @export
67 70
 setMethod("plot_region",
68 71
     signature(
69 72
         x = "ModBamResult",
... ...
@@ -225,7 +228,6 @@ setMethod("plot_region",
225 228
     feature_width <- end - start
226 229
     window_left <- feature_width * window_prop[1]
227 230
     window_right <- feature_width * window_prop[2]
228
-    xlim <- round(c(start - window_left, end + window_right))
229 231
 
230 232
     methy_data <-
231 233
         query_methy(
... ...
@@ -243,6 +245,7 @@ setMethod("plot_region",
243 245
     }
244 246
 
245 247
     title <- glue::glue("{chr}:{start}-{end}")
248
+    xlim <- round(c(start - window_left, end + window_right))
246 249
     p1 <- plot_methylation_internal(
247 250
         methy_data = methy_data,
248 251
         start = start,
... ...
@@ -259,18 +262,18 @@ setMethod("plot_region",
259 262
         palette_col = palette,
260 263
         line_size = line_size
261 264
     ) +
262
-        ggplot2::scale_x_continuous(
263
-            limits = xlim,
264
-            expand = ggplot2::expansion(),
265
-            labels = scales::label_number(scale_cut = scales::cut_si("b"))
266
-        )
265
+        ggplot2::coord_cartesian(
266
+            xlim = xlim,
267
+            expand = FALSE
268
+        ) +
269
+            scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
267 270
 
268 271
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
269
-        ggplot2::scale_x_continuous(
270
-            limits = xlim,
271
-            expand = ggplot2::expansion(),
272
-            labels = scales::label_number(scale_cut = scales::cut_si("b"))
273
-        )
272
+        ggplot2::coord_cartesian(
273
+            xlim = xlim,
274
+            expand = FALSE
275
+        ) +
276
+            scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
274 277
 
275 278
     anno_height <- attr(p2, "plot_height")
276 279
 
... ...
@@ -279,11 +282,11 @@ setMethod("plot_region",
279 282
 
280 283
     if (heatmap) {
281 284
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
282
-            ggplot2::scale_x_continuous(
283
-                limits = xlim,
284
-                expand = ggplot2::expansion(),
285
-                labels = scales::label_number(scale_cut = scales::cut_si("b"))
286
-            )
285
+            ggplot2::coord_cartesian(
286
+                xlim = xlim,
287
+                expand = FALSE
288
+            ) +
289
+                scale_x_continuous(labels = scales::label_number(scale_cut = scales::cut_si("b")))
287 290
 
288 291
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
289 292
     }
Browse code

Updated docs

Shians authored on 14/04/2023 01:59:58
Showing 1 changed files
... ...
@@ -18,9 +18,6 @@
18 18
 #' @param palette the ggplot colour palette used for groups.
19 19
 #' @param line_size the size of the lines.
20 20
 #'
21
-#' @return a patchwork plot containing the methylation profile in the specified
22
-#'   region.
23
-#'
24 21
 #' @examples
25 22
 #' nmr <- load_example_nanomethresult()
26 23
 #' plot_region(nmr, "chr7", 6703892, 6730431)
... ...
@@ -153,6 +150,9 @@ setMethod("plot_region",
153 150
     }
154 151
 )
155 152
 
153
+#' @rdname plot_region
154
+#'
155
+#' @export
156 156
 setMethod("plot_region",
157 157
     signature(
158 158
         x = "ModBamResult",
Browse code

Initial implementation of modbam handling

Shians authored on 11/04/2023 06:07:03
Showing 1 changed files
... ...
@@ -67,6 +67,47 @@ setMethod("plot_region",
67 67
     }
68 68
 )
69 69
 
70
+setMethod("plot_region",
71
+    signature(
72
+        x = "ModBamResult",
73
+        chr = "character",
74
+        start = "numeric",
75
+        end = "numeric"),
76
+    function(
77
+        x,
78
+        chr,
79
+        start,
80
+        end,
81
+        anno_regions = NULL,
82
+        binary_threshold = NULL,
83
+        avg_method = c("mean", "median"),
84
+        spaghetti = FALSE,
85
+        heatmap = FALSE,
86
+        span = NULL,
87
+        window_prop = 0,
88
+        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
89
+        line_size = 2
90
+    ) {
91
+        avg_method <- match.arg(avg_method)
92
+
93
+        .plot_region(
94
+            x = x,
95
+            chr = chr,
96
+            start = start,
97
+            end = end,
98
+            anno_regions = anno_regions,
99
+            binary_threshold = binary_threshold,
100
+            spaghetti = spaghetti,
101
+            avg_method = avg_method,
102
+            heatmap = heatmap,
103
+            span = span,
104
+            window_prop = window_prop,
105
+            palette = palette,
106
+            line_size = line_size
107
+        )
108
+    }
109
+)
110
+
70 111
 #' @rdname plot_region
71 112
 #'
72 113
 #' @export
... ...
@@ -112,6 +153,48 @@ setMethod("plot_region",
112 153
     }
113 154
 )
114 155
 
156
+setMethod("plot_region",
157
+    signature(
158
+        x = "ModBamResult",
159
+        chr = "factor",
160
+        start = "numeric",
161
+        end = "numeric"),
162
+
163
+    function(
164
+        x,
165
+        chr,
166
+        start,
167
+        end,
168
+        anno_regions = NULL,
169
+        binary_threshold = NULL,
170
+        avg_method = c("mean", "median"),
171
+        spaghetti = FALSE,
172
+        heatmap = FALSE,
173
+        span = NULL,
174
+        window_prop = 0,
175
+        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
176
+        line_size = 2
177
+    ) {
178
+        chr <- as.character(chr)
179
+        avg_method <- match.arg(avg_method)
180
+        plot_region(
181
+            x = x,
182
+            chr = chr,
183
+            start = start,
184
+            end = end,
185
+            anno_regions = anno_regions,
186
+            binary_threshold = binary_threshold,
187
+            avg_method = avg_method,
188
+            spaghetti = spaghetti,
189
+            heatmap = heatmap,
190
+            span = span,
191
+            window_prop = window_prop,
192
+            palette = palette,
193
+            line_size = line_size
194
+        )
195
+    }
196
+)
197
+
115 198
 .plot_region <- function(
116 199
     x,
117 200
     chr,
Browse code

Moved generics into dedicated file

Shians authored on 11/04/2023 01:16:58
Showing 1 changed files
... ...
@@ -1,24 +1,3 @@
1
-#' Plot region
2
-#'
3
-#' @param x the NanoMethResult object.
4
-#' @param chr the chromosome to plot.
5
-#' @param start the start of the plotting region.
6
-#' @param end the end of the plotting region.
7
-#' @param ... additional arguments.
8
-#'
9
-#' @return a patchwork plot containing the methylation profile in the specified
10
-#'   region.
11
-#'
12
-#' @examples
13
-#' nmr <- load_example_nanomethresult()
14
-#' plot_region(nmr, "chr7", 6703892, 6730431)
15
-#'
16
-#' @importFrom ggrastr rasterise
17
-#' @export
18
-setGeneric("plot_region", function(x, chr, start, end, ...) {
19
-    standardGeneric("plot_region")
20
-})
21
-
22 1
 #' @rdname plot_region
23 2
 #'
24 3
 #' @param anno_regions the data.frame of regions to be annotated.
Browse code

Changed = to <-

Shians authored on 10/10/2022 22:57:29
Showing 1 changed files
... ...
@@ -68,7 +68,7 @@ setMethod("plot_region",
68 68
         palette = ggplot2::scale_colour_brewer(palette = "Set1"),
69 69
         line_size = 2
70 70
     ) {
71
-        avg_method = match.arg(avg_method)
71
+        avg_method <- match.arg(avg_method)
72 72
 
73 73
         .plot_region(
74 74
             x = x,
Browse code

Changed genomic coordinates to automatic scale with units.

Shians authored on 18/07/2022 06:29:56
Showing 1 changed files
... ...
@@ -199,13 +199,15 @@ setMethod("plot_region",
199 199
     ) +
200 200
         ggplot2::scale_x_continuous(
201 201
             limits = xlim,
202
-            expand = ggplot2::expansion()
202
+            expand = ggplot2::expansion(),
203
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))
203 204
         )
204 205
 
205 206
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
206 207
         ggplot2::scale_x_continuous(
207 208
             limits = xlim,
208
-            expand = ggplot2::expansion()
209
+            expand = ggplot2::expansion(),
210
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))
209 211
         )
210 212
 
211 213
     anno_height <- attr(p2, "plot_height")
... ...
@@ -217,7 +219,8 @@ setMethod("plot_region",
217 219
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
218 220
             ggplot2::scale_x_continuous(
219 221
                 limits = xlim,
220
-                expand = ggplot2::expansion()
222
+                expand = ggplot2::expansion(),
223
+                labels = scales::label_number(scale_cut = scales::cut_si("b"))
221 224
             )
222 225
 
223 226
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
Browse code

Updated raster dpi

Shians authored on 22/06/2022 01:09:45
Showing 1 changed files
... ...
@@ -220,7 +220,7 @@ setMethod("plot_region",
220 220
                 expand = ggplot2::expansion()
221 221
             )
222 222
 
223
-        p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap))
223
+        p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
224 224
     }
225 225
 
226 226
     p_out
Browse code

Added rasterisation to plot_regions()

Shians authored on 21/06/2022 07:17:35
Showing 1 changed files
... ...
@@ -13,6 +13,7 @@
13 13
 #' nmr <- load_example_nanomethresult()
14 14
 #' plot_region(nmr, "chr7", 6703892, 6730431)
15 15
 #'
16
+#' @importFrom ggrastr rasterise
16 17
 #' @export
17 18
 setGeneric("plot_region", function(x, chr, start, end, ...) {
18 19
     standardGeneric("plot_region")
... ...
@@ -219,7 +220,7 @@ setMethod("plot_region",
219 220
                 expand = ggplot2::expansion()
220 221
             )
221 222
 
222
-        p_out <- stack_plots(p_out, p_heatmap)
223
+        p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap))
223 224
     }
224 225
 
225 226
     p_out
Browse code

Added `line_size` argument to methylation plots to control line size.

Shians authored on 01/06/2022 02:19:24
Showing 1 changed files
... ...
@@ -36,6 +36,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
36 36
 #'   values for left and right window size. Values indicate proportion of gene
37 37
 #'   length.
38 38
 #' @param palette the ggplot colour palette used for groups.
39
+#' @param line_size the size of the lines.
39 40
 #'
40 41
 #' @return a patchwork plot containing the methylation profile in the specified
41 42
 #'   region.
... ...
@@ -63,7 +64,8 @@ setMethod("plot_region",
63 64
         heatmap = FALSE,
64 65
         span = NULL,
65 66
         window_prop = 0,
66
-        palette = ggplot2::scale_colour_brewer(palette = "Set1")
67
+        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
68
+        line_size = 2
67 69
     ) {
68 70
         avg_method = match.arg(avg_method)
69 71
 
... ...
@@ -79,7 +81,8 @@ setMethod("plot_region",
79 81
             heatmap = heatmap,
80 82
             span = span,
81 83
             window_prop = window_prop,
82
-            palette = palette
84
+            palette = palette,
85
+            line_size = line_size
83 86
         )
84 87
     }
85 88
 )
... ...
@@ -106,7 +109,8 @@ setMethod("plot_region",
106 109
         heatmap = FALSE,
107 110
         span = NULL,
108 111
         window_prop = 0,
109
-        palette = ggplot2::scale_colour_brewer(palette = "Set1")
112
+        palette = ggplot2::scale_colour_brewer(palette = "Set1"),
113
+        line_size = 2
110 114
     ) {
111 115
         chr <- as.character(chr)
112 116
         avg_method <- match.arg(avg_method)
... ...
@@ -122,7 +126,8 @@ setMethod("plot_region",
122 126
             heatmap = heatmap,
123 127
             span = span,
124 128
             window_prop = window_prop,
125
-            palette = palette
129
+            palette = palette,
130
+            line_size = line_size
126 131
         )
127 132
     }
128 133
 )
... ...
@@ -139,7 +144,8 @@ setMethod("plot_region",
139 144
     heatmap,
140 145
     span,
141 146
     window_prop,
142
-    palette
147
+    palette,
148
+    line_size
143 149
 ) {
144 150
     sample_anno <- samples(x)
145 151
     exons_anno <- query_exons_region(
... ...
@@ -187,7 +193,8 @@ setMethod("plot_region",
187 193
         spaghetti = spaghetti,
188 194
         sample_anno = sample_anno,
189 195
         span = span,
190
-        palette_col = palette
196
+        palette_col = palette,
197
+        line_size = line_size
191 198
     ) +
192 199
         ggplot2::scale_x_continuous(
193 200
             limits = xlim,
Browse code

Added palettes argument

Shians authored on 14/04/2022 05:45:40
Showing 1 changed files
... ...
@@ -35,6 +35,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
35 35
 #' @param window_prop the size of flanking region to plot. Can be a vector of two
36 36
 #'   values for left and right window size. Values indicate proportion of gene
37 37
 #'   length.
38
+#' @param palette the ggplot colour palette used for groups.
38 39
 #'
39 40
 #' @return a patchwork plot containing the methylation profile in the specified
40 41
 #'   region.
... ...
@@ -61,7 +62,8 @@ setMethod("plot_region",
61 62
         spaghetti = FALSE,
62 63
         heatmap = FALSE,
63 64
         span = NULL,
64
-        window_prop = 0
65
+        window_prop = 0,
66
+        palette = ggplot2::scale_colour_brewer(palette = "Set1")
65 67
     ) {
66 68
         avg_method = match.arg(avg_method)
67 69
 
... ...
@@ -76,7 +78,8 @@ setMethod("plot_region",
76 78
             avg_method = avg_method,
77 79
             heatmap = heatmap,
78 80
             span = span,
79
-            window_prop = window_prop
81
+            window_prop = window_prop,
82
+            palette = palette
80 83
         )
81 84
     }
82 85
 )
... ...
@@ -102,7 +105,8 @@ setMethod("plot_region",
102 105
         spaghetti = FALSE,
103 106
         heatmap = FALSE,
104 107
         span = NULL,
105
-        window_prop = 0
108
+        window_prop = 0,
109
+        palette = ggplot2::scale_colour_brewer(palette = "Set1")
106 110
     ) {
107 111
         chr <- as.character(chr)
108 112
         avg_method <- match.arg(avg_method)
... ...
@@ -117,7 +121,8 @@ setMethod("plot_region",
117 121
             spaghetti = spaghetti,
118 122
             heatmap = heatmap,
119 123
             span = span,
120
-            window_prop = window_prop
124
+            window_prop = window_prop,
125
+            palette = palette
121 126
         )
122 127
     }
123 128
 )
... ...
@@ -133,7 +138,8 @@ setMethod("plot_region",
133 138
     spaghetti,
134 139
     heatmap,
135 140
     span,
136
-    window_prop
141
+    window_prop,
142
+    palette
137 143
 ) {
138 144
     sample_anno <- samples(x)
139 145
     exons_anno <- query_exons_region(
... ...
@@ -180,7 +186,8 @@ setMethod("plot_region",
180 186
         avg_method = avg_method,
181 187
         spaghetti = spaghetti,
182 188
         sample_anno = sample_anno,
183
-        span = span
189
+        span = span,
190
+        palette_col = palette
184 191
     ) +
185 192
         ggplot2::scale_x_continuous(
186 193
             limits = xlim,
Browse code

Changed `avg_method` of gene and region plots to `mean` instead of `median`

Shians authored on 24/02/2022 01:00:19
Showing 1 changed files
... ...
@@ -26,9 +26,9 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
26 26
 #'   equal to or below the threshold are set to 0.
27 27
 #' @param avg_method the average method for pre-smoothing at each genomic position.
28 28
 #'   Data is pre-smoothed at each genomic position before the smoothed aggregate line
29
-#'   is generated for performance reasons. The default is "median" which produces
30
-#'   a smoothed line more robust to outliers, "mean" is the old default and tends
31
-#'   to produce lines with values dampened towards 0.5.
29
+#'   is generated for performance reasons. The default is "mean" which corresponds
30
+#'   to the average methylation fraction. The alternative "median" option is
31
+#'   closer to an average within the more common methylation state.
32 32
 #' @param spaghetti whether or not individual reads should be shown.
33 33
 #' @param heatmap whether or not read-methylation heatmap should be shown.
34 34
 #' @param span the span for loess smoothing.
... ...
@@ -57,7 +57,7 @@ setMethod("plot_region",
57 57
         end,
58 58
         anno_regions = NULL,
59 59
         binary_threshold = NULL,
60
-        avg_method = c("median", "mean"),
60
+        avg_method = c("mean", "median"),
61 61
         spaghetti = FALSE,
62 62
         heatmap = FALSE,
63 63
         span = NULL,
... ...
@@ -98,7 +98,7 @@ setMethod("plot_region",
98 98
         end,
99 99
         anno_regions = NULL,
100 100
         binary_threshold = NULL,
101
-        avg_method = c("median", "mean"),
101
+        avg_method = c("mean", "median"),
102 102
         spaghetti = FALSE,
103 103
         heatmap = FALSE,
104 104
         span = NULL,
Browse code

Fixed typo

Shians authored on 17/12/2021 03:22:08
Showing 1 changed files
... ...
@@ -23,7 +23,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
23 23
 #' @param anno_regions the data.frame of regions to be annotated.
24 24
 #' @param binary_threshold the modification probability such that calls with
25 25
 #'   modification probability above the threshold are set to 1 and probabilities
26
-#'   equalt to or below the threshold are set to 0.
26
+#'   equal to or below the threshold are set to 0.
27 27
 #' @param avg_method the average method for pre-smoothing at each genomic position.
28 28
 #'   Data is pre-smoothed at each genomic position before the smoothed aggregate line
29 29
 #'   is generated for performance reasons. The default is "median" which produces
Browse code

Documented `avg_method` argument

Shians authored on 07/12/2021 06:06:18
Showing 1 changed files
... ...
@@ -24,6 +24,11 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
24 24
 #' @param binary_threshold the modification probability such that calls with
25 25
 #'   modification probability above the threshold are set to 1 and probabilities
26 26
 #'   equalt to or below the threshold are set to 0.
27
+#' @param avg_method the average method for pre-smoothing at each genomic position.
28
+#'   Data is pre-smoothed at each genomic position before the smoothed aggregate line
29
+#'   is generated for performance reasons. The default is "median" which produces
30
+#'   a smoothed line more robust to outliers, "mean" is the old default and tends
31
+#'   to produce lines with values dampened towards 0.5.
27 32
 #' @param spaghetti whether or not individual reads should be shown.
28 33
 #' @param heatmap whether or not read-methylation heatmap should be shown.
29 34
 #' @param span the span for loess smoothing.
Browse code

Changed default average method to median

Shians authored on 07/12/2021 03:28:15
Showing 1 changed files
... ...
@@ -52,11 +52,14 @@ setMethod("plot_region",
52 52
         end,
53 53
         anno_regions = NULL,
54 54
         binary_threshold = NULL,
55
+        avg_method = c("median", "mean"),
55 56
         spaghetti = FALSE,
56 57
         heatmap = FALSE,
57 58
         span = NULL,
58 59
         window_prop = 0
59 60
     ) {
61
+        avg_method = match.arg(avg_method)
62
+
60 63
         .plot_region(
61 64
             x = x,
62 65
             chr = chr,
... ...
@@ -65,6 +68,7 @@ setMethod("plot_region",
65 68
             anno_regions = anno_regions,
66 69
             binary_threshold = binary_threshold,
67 70
             spaghetti = spaghetti,
71
+            avg_method = avg_method,
68 72
             heatmap = heatmap,
69 73
             span = span,
70 74
             window_prop = window_prop
... ...
@@ -89,12 +93,14 @@ setMethod("plot_region",
89 93
         end,
90 94
         anno_regions = NULL,
91 95
         binary_threshold = NULL,
96
+        avg_method = c("median", "mean"),
92 97
         spaghetti = FALSE,
93 98
         heatmap = FALSE,
94 99
         span = NULL,
95 100
         window_prop = 0
96 101
     ) {
97 102
         chr <- as.character(chr)
103
+        avg_method <- match.arg(avg_method)
98 104
         plot_region(
99 105
             x = x,
100 106
             chr = chr,
... ...
@@ -102,6 +108,7 @@ setMethod("plot_region",
102 108
             end = end,
103 109
             anno_regions = anno_regions,
104 110
             binary_threshold = binary_threshold,
111
+            avg_method = avg_method,
105 112
             spaghetti = spaghetti,
106 113
             heatmap = heatmap,
107 114
             span = span,
... ...
@@ -117,6 +124,7 @@ setMethod("plot_region",
117 124
     end,
118 125
     anno_regions,
119 126
     binary_threshold,
127
+    avg_method,
120 128
     spaghetti,
121 129
     heatmap,
122 130
     span,
... ...
@@ -164,6 +172,7 @@ setMethod("plot_region",
164 172
         title = title,
165 173
         anno_regions = anno_regions,
166 174
         binary_threshold = binary_threshold,
175
+        avg_method = avg_method,
167 176
         spaghetti = spaghetti,
168 177
         sample_anno = sample_anno,
169 178
         span = span
Browse code

Documented heatmap argument

Shians authored on 07/12/2021 01:46:59
Showing 1 changed files
... ...
@@ -25,6 +25,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
25 25
 #'   modification probability above the threshold are set to 1 and probabilities
26 26
 #'   equalt to or below the threshold are set to 0.
27 27
 #' @param spaghetti whether or not individual reads should be shown.
28
+#' @param heatmap whether or not read-methylation heatmap should be shown.
28 29
 #' @param span the span for loess smoothing.
29 30
 #' @param window_prop the size of flanking region to plot. Can be a vector of two
30 31
 #'   values for left and right window size. Values indicate proportion of gene
Browse code

Added heatmap argument to spaghetti plots

Shians authored on 06/12/2021 05:27:30
Showing 1 changed files
... ...
@@ -52,6 +52,7 @@ setMethod("plot_region",
52 52
         anno_regions = NULL,
53 53
         binary_threshold = NULL,
54 54
         spaghetti = FALSE,
55
+        heatmap = FALSE,
55 56
         span = NULL,
56 57
         window_prop = 0
57 58
     ) {
... ...
@@ -63,6 +64,7 @@ setMethod("plot_region",
63 64
             anno_regions = anno_regions,
64 65
             binary_threshold = binary_threshold,
65 66
             spaghetti = spaghetti,
67
+            heatmap = heatmap,
66 68
             span = span,
67 69
             window_prop = window_prop
68 70
         )
... ...
@@ -87,6 +89,7 @@ setMethod("plot_region",
87 89
         anno_regions = NULL,
88 90
         binary_threshold = NULL,
89 91
         spaghetti = FALSE,
92
+        heatmap = FALSE,
90 93
         span = NULL,
91 94
         window_prop = 0
92 95
     ) {
... ...
@@ -99,23 +102,24 @@ setMethod("plot_region",
99 102
             anno_regions = anno_regions,
100 103
             binary_threshold = binary_threshold,
101 104
             spaghetti = spaghetti,
105
+            heatmap = heatmap,
102 106
             span = span,
103 107
             window_prop = window_prop
104 108
         )
105 109
     }
106 110
 )
107 111
 
108
-
109 112
 .plot_region <- function(
110 113
     x,
111 114
     chr,
112 115
     start,
113 116
     end,
114
-    anno_regions = NULL,
115
-    binary_threshold = NULL,
116
-    spaghetti = FALSE,
117
-    span = NULL,
118
-    window_prop = 0
117
+    anno_regions,
118
+    binary_threshold,
119
+    spaghetti,
120
+    heatmap,
121
+    span,
122
+    window_prop
119 123
 ) {
120 124
     sample_anno <- samples(x)
121 125
     exons_anno <- query_exons_region(
... ...
@@ -162,14 +166,32 @@ setMethod("plot_region",
162 166
         spaghetti = spaghetti,
163 167
         sample_anno = sample_anno,
164 168
         span = span
165
-    )
166
-
167
-    xlim <- .get_ggplot_range_x(p1)
169
+    ) +
170
+        ggplot2::scale_x_continuous(
171
+            limits = xlim,
172
+            expand = ggplot2::expansion()
173
+        )
168 174
 
169
-    p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2])
175
+    p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
176
+        ggplot2::scale_x_continuous(
177
+            limits = xlim,
178
+            expand = ggplot2::expansion()
179
+        )
170 180
 
171 181
     anno_height <- attr(p2, "plot_height")
172 182
 
173 183
     heights <- c(1, 0.075 * anno_height)
174
-    p1 / p2 + patchwork::plot_layout(heights = heights)
184
+    p_out <- p1 / p2 + patchwork::plot_layout(heights = heights)
185
+
186
+    if (heatmap) {
187
+        p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
188
+            ggplot2::scale_x_continuous(
189
+                limits = xlim,
190
+                expand = ggplot2::expansion()
191
+            )
192
+
193
+        p_out <- stack_plots(p_out, p_heatmap)
194
+    }
195
+
196
+    p_out
175 197
 }
Browse code

Implemented binary thresholding for plotting functions

Shians authored on 13/08/2021 06:50:42
Showing 1 changed files
... ...
@@ -21,6 +21,9 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
21 21
 #' @rdname plot_region
22 22
 #'
23 23
 #' @param anno_regions the data.frame of regions to be annotated.
24
+#' @param binary_threshold the modification probability such that calls with
25
+#'   modification probability above the threshold are set to 1 and probabilities
26
+#'   equalt to or below the threshold are set to 0.
24 27
 #' @param spaghetti whether or not individual reads should be shown.
25 28
 #' @param span the span for loess smoothing.
26 29
 #' @param window_prop the size of flanking region to plot. Can be a vector of two
... ...
@@ -47,6 +50,7 @@ setMethod("plot_region",
47 50
         start,
48 51
         end,
49 52
         anno_regions = NULL,
53
+        binary_threshold = NULL,
50 54
         spaghetti = FALSE,
51 55
         span = NULL,
52 56
         window_prop = 0
... ...
@@ -57,6 +61,7 @@ setMethod("plot_region",
57 61
             start = start,
58 62
             end = end,
59 63
             anno_regions = anno_regions,
64
+            binary_threshold = binary_threshold,
60 65
             spaghetti = spaghetti,
61 66
             span = span,
62 67
             window_prop = window_prop
... ...
@@ -80,6 +85,7 @@ setMethod("plot_region",
80 85
         start,
81 86
         end,
82 87
         anno_regions = NULL,
88
+        binary_threshold = NULL,
83 89
         spaghetti = FALSE,
84 90
         span = NULL,
85 91
         window_prop = 0
... ...
@@ -91,6 +97,7 @@ setMethod("plot_region",
91 97
             start = start,
92 98
             end = end,
93 99
             anno_regions = anno_regions,
100
+            binary_threshold = binary_threshold,
94 101
             spaghetti = spaghetti,
95 102
             span = span,
96 103
             window_prop = window_prop
... ...
@@ -105,6 +112,7 @@ setMethod("plot_region",
105 112
     start,
106 113
     end,
107 114
     anno_regions = NULL,
115
+    binary_threshold = NULL,
108 116
     spaghetti = FALSE,
109 117
     span = NULL,
110 118
     window_prop = 0
... ...
@@ -150,6 +158,7 @@ setMethod("plot_region",
150 158
         xlim = xlim,
151 159
         title = title,
152 160
         anno_regions = anno_regions,
161
+        binary_threshold = binary_threshold,
153 162
         spaghetti = spaghetti,
154 163
         sample_anno = sample_anno,
155 164
         span = span
Browse code

Fixed missing argument

Shians authored on 12/07/2021 07:44:07
Showing 1 changed files
... ...
@@ -121,15 +121,17 @@ setMethod("plot_region",
121 121
         window_prop <- c(window_prop, window_prop)
122 122
     }
123 123
 
124
-    window_left <- (end - start) * window_prop[1]
125
-    window_right <- (end - start) * window_prop[2]
124
+    feature_width <- end - start
125
+    window_left <- feature_width * window_prop[1]
126
+    window_right <- feature_width * window_prop[2]
127
+    xlim <- round(c(start - window_left, end + window_right))
126 128
 
127 129
     methy_data <-
128 130
         query_methy(
129 131
             x,
130 132
             chr,
131
-            start - window_left,
132
-            end + window_right,
133
+            floor(start - window_left * 1.1),
134
+            ceiling(end + window_right * 1.1),
133 135
             simplify = TRUE) %>%
134 136
         dplyr::select(-"strand") %>%
135 137
         tibble::as_tibble()
... ...
@@ -145,6 +147,7 @@ setMethod("plot_region",
145 147
         start = start,
146 148
         end = end,
147 149
         chr = chr,
150
+        xlim = xlim,
148 151
         title = title,
149 152
         anno_regions = anno_regions,
150 153
         spaghetti = spaghetti,
Browse code

Changed default plot_region window to 0

Shians authored on 12/07/2021 07:21:18
Showing 1 changed files
... ...
@@ -49,7 +49,7 @@ setMethod("plot_region",
49 49
         anno_regions = NULL,
50 50
         spaghetti = FALSE,
51 51
         span = NULL,
52
-        window_prop = 0.3
52
+        window_prop = 0
53 53
     ) {
54 54
         .plot_region(
55 55
             x = x,
... ...
@@ -82,7 +82,7 @@ setMethod("plot_region",
82 82
         anno_regions = NULL,
83 83
         spaghetti = FALSE,
84 84
         span = NULL,
85
-        window_prop = 0.3
85
+        window_prop = 0
86 86
     ) {
87 87
         chr <- as.character(chr)
88 88
         plot_region(
... ...
@@ -107,7 +107,7 @@ setMethod("plot_region",
107 107
     anno_regions = NULL,
108 108
     spaghetti = FALSE,
109 109
     span = NULL,
110
-    window_prop = 0.3
110
+    window_prop = 0
111 111
 ) {
112 112
     sample_anno <- samples(x)
113 113
     exons_anno <- query_exons_region(
Browse code

Updated documentation

Shians authored on 05/03/2021 05:40:07
Showing 1 changed files
... ...
@@ -1,10 +1,10 @@
1 1
 #' Plot region
2 2
 #'
3
-#' @param x the NanoMethResult object
4
-#' @param chr the chromosome to plot
5
-#' @param start the start of the plotting region
6
-#' @param end the end of the plotting region
7
-#' @param ... additional arguments
3
+#' @param x the NanoMethResult object.
4
+#' @param chr the chromosome to plot.
5
+#' @param start the start of the plotting region.
6
+#' @param end the end of the plotting region.
7
+#' @param ... additional arguments.
8 8
 #'
9 9
 #' @return a patchwork plot containing the methylation profile in the specified
10 10
 #'   region.
... ...
@@ -20,9 +20,12 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
20 20
 
21 21
 #' @rdname plot_region
22 22
 #'
23
-#' @param anno_regions the data.frame of regions to be annotated
23
+#' @param anno_regions the data.frame of regions to be annotated.
24 24
 #' @param spaghetti whether or not individual reads should be shown.
25 25
 #' @param span the span for loess smoothing.
26
+#' @param window_prop the size of flanking region to plot. Can be a vector of two
27
+#'   values for left and right window size. Values indicate proportion of gene
28
+#'   length.
26 29
 #'
27 30
 #' @return a patchwork plot containing the methylation profile in the specified
28 31
 #'   region.
... ...
@@ -45,7 +48,8 @@ setMethod("plot_region",
45 48
         end,
46 49
         anno_regions = NULL,
47 50
         spaghetti = FALSE,
48
-        span = NULL
51
+        span = NULL,
52
+        window_prop = 0.3
49 53
     ) {
50 54
         .plot_region(
51 55
             x = x,
... ...
@@ -54,9 +58,11 @@ setMethod("plot_region",
54 58
             end = end,
55 59
             anno_regions = anno_regions,
56 60
             spaghetti = spaghetti,
57
-            span = span
61
+            span = span,
62
+            window_prop = window_prop
58 63
         )
59
-    })
64
+    }
65
+)
60 66
 
61 67
 #' @rdname plot_region
62 68
 #'
... ...
@@ -75,7 +81,8 @@ setMethod("plot_region",
75 81
         end,
76 82
         anno_regions = NULL,
77 83
         spaghetti = FALSE,
78
-        span = NULL
84
+        span = NULL,
85
+        window_prop = 0.3
79 86
     ) {
80 87
         chr <- as.character(chr)
81 88
         plot_region(
... ...
@@ -85,9 +92,11 @@ setMethod("plot_region",
85 92
             end = end,
86 93
             anno_regions = anno_regions,
87 94
             spaghetti = spaghetti,
88
-            span = span
95
+            span = span,
96
+            window_prop = window_prop
89 97
         )
90
-    })
98
+    }
99
+)
91 100
 
92 101
 
93 102
 .plot_region <- function(
... ...
@@ -98,7 +107,7 @@ setMethod("plot_region",
98 107
     anno_regions = NULL,
99 108
     spaghetti = FALSE,
100 109
     span = NULL,
101
-    window_prop = c(0.3, 0.3)
110
+    window_prop = 0.3
102 111
 ) {
103 112
     sample_anno <- samples(x)
104 113
     exons_anno <- query_exons_region(
... ...
@@ -108,12 +117,16 @@ setMethod("plot_region",
108 117
         end = end
109 118
     )
110 119
 
120
+    if (length(window_prop) == 1) {
121
+        window_prop <- c(window_prop, window_prop)
122
+    }
123
+
111 124
     window_left <- (end - start) * window_prop[1]
112 125
     window_right <- (end - start) * window_prop[2]
113 126
 
114 127
     methy_data <-
115 128
         query_methy(
116
-            methy(x),
129
+            x,
117 130
             chr,
118 131
             start - window_left,
119 132
             end + window_right,
Browse code

Added detail to documentation return value

Shians authored on 03/03/2021 00:24:07
Showing 1 changed files
... ...
@@ -6,7 +6,8 @@
6 6
 #' @param end the end of the plotting region
7 7
 #' @param ... additional arguments
8 8
 #'
9
-#' @return a ggplot object.
9
+#' @return a patchwork plot containing the methylation profile in the specified
10
+#'   region.
10 11
 #'
11 12
 #' @examples
12 13
 #' nmr <- load_example_nanomethresult()
... ...
@@ -23,7 +24,8 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
23 24
 #' @param spaghetti whether or not individual reads should be shown.
24 25
 #' @param span the span for loess smoothing.
25 26
 #'
26
-#' @return a ggplot object.
27
+#' @return a patchwork plot containing the methylation profile in the specified
28
+#'   region.
27 29
 #'
28 30
 #' @examples
29 31
 #' nmr <- load_example_nanomethresult()
Browse code

Fixed plot_regions getting start and end from wrong scope

Shians authored on 21/01/2021 00:28:49
Showing 1 changed files
... ...
@@ -65,6 +65,7 @@ setMethod("plot_region",
65 65
         chr = "factor",
66 66
         start = "numeric",
67 67
         end = "numeric"),
68
+
68 69
     function(
69 70
         x,
70 71
         chr,
... ...
@@ -124,19 +125,16 @@ setMethod("plot_region",
124 125
     }
125 126
 
126 127
     title <- glue::glue("{chr}:{start}-{end}")
127
-    p1 <- with(
128
-        exons_anno,
129
-        plot_methylation_internal(
130
-            methy_data = methy_data,
131
-            start = start,
132
-            end = end,
133
-            chr = chr,
134
-            title = title,
135
-            anno_regions = anno_regions,
136
-            spaghetti = spaghetti,
137
-            sample_anno = sample_anno,
138
-            span = span
139
-        )
128
+    p1 <- plot_methylation_internal(
129
+        methy_data = methy_data,
130
+        start = start,
131
+        end = end,
132
+        chr = chr,
133
+        title = title,
134
+        anno_regions = anno_regions,
135
+        spaghetti = spaghetti,
136
+        sample_anno = sample_anno,
137
+        span = span
140 138
     )
141 139
 
142 140
     xlim <- .get_ggplot_range_x(p1)
Browse code

Added return values

shians authored on 28/09/2020 02:04:24
Showing 1 changed files
... ...
@@ -6,7 +6,12 @@
6 6
 #' @param end the end of the plotting region
7 7
 #' @param ... additional arguments
8 8
 #'
9
-#' @return None
9
+#' @return a ggplot object.
10
+#'
11
+#' @examples
12
+#' nmr <- load_example_nanomethresult()
13
+#' plot_region(nmr, "chr7", 6703892, 6730431)
14
+#'
10 15
 #' @export
11 16
 setGeneric("plot_region", function(x, chr, start, end, ...) {
12 17
     standardGeneric("plot_region")
... ...
@@ -18,6 +23,12 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
18 23
 #' @param spaghetti whether or not individual reads should be shown.
19 24
 #' @param span the span for loess smoothing.
20 25
 #'
26
+#' @return a ggplot object.
27
+#'
28
+#' @examples
29
+#' nmr <- load_example_nanomethresult()
30
+#' plot_region(nmr, "chr7", 6703892, 6730431)
31
+#'
21 32
 #' @export
22 33
 setMethod("plot_region",
23 34
     signature(
Browse code

Corrected NanoMethResults to NanoMethResult

shians authored on 31/07/2020 12:33:06
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 #' Plot region
2 2
 #'
3
-#' @param x the NanoMethResults object
3
+#' @param x the NanoMethResult object
4 4
 #' @param chr the chromosome to plot
5 5
 #' @param start the start of the plotting region
6 6
 #' @param end the end of the plotting region
Browse code

Reformatted code

shians authored on 20/07/2020 08:02:41
Showing 1 changed files
... ...
@@ -33,8 +33,7 @@ setMethod("plot_region",
33 33
         anno_regions = NULL,
34 34
         spaghetti = FALSE,
35 35
         span = NULL
36
-        ) {
37
-
36
+    ) {
38 37
         .plot_region(
39 38
             x = x,
40 39
             chr = chr,
... ...
@@ -63,8 +62,7 @@ setMethod("plot_region",
63 62
         anno_regions = NULL,
64 63
         spaghetti = FALSE,
65 64
         span = NULL
66
-        ) {
67
-
65
+    ) {
68 66
         chr <- as.character(chr)
69 67
         plot_region(
70 68
             x = x,
... ...
@@ -87,8 +85,7 @@ setMethod("plot_region",
87 85
     spaghetti = FALSE,
88 86
     span = NULL,
89 87
     window_prop = c(0.3, 0.3)
90
-    ) {
91
-
88
+) {
92 89
     sample_anno <- samples(x)
93 90
     exons_anno <- query_exons_region(
94 91
         exons(x),
Browse code

Exported query_methy and added simplify argument

shians authored on 08/06/2020 01:11:44
Showing 1 changed files
... ...
@@ -101,8 +101,12 @@ setMethod("plot_region",
101 101
     window_right <- (end - start) * window_prop[2]
102 102
 
103 103
     methy_data <-
104
-        query_methy(methy(x), chr, start - window_left, end + window_right) %>%
105
-        dplyr::bind_rows() %>%
104
+        query_methy(
105
+            methy(x),
106
+            chr,
107
+            start - window_left,
108
+            end + window_right,
109
+            simplify = TRUE) %>%
106 110
         dplyr::select(-"strand") %>%
107 111
         tibble::as_tibble()
108 112
 
Browse code

Fixed title in plot_region

Shians authored on 18/05/2020 05:51:49
Showing 1 changed files
... ...
@@ -111,6 +111,7 @@ setMethod("plot_region",
111 111
         return(ggplot() + theme_void())
112 112
     }
113 113
 
114
+    title <- glue::glue("{chr}:{start}-{end}")
114 115
     p1 <- with(
115 116
         exons_anno,
116 117
         plot_methylation_internal(
... ...
@@ -118,7 +119,7 @@ setMethod("plot_region",
118 119
             start = start,
119 120
             end = end,
120 121
             chr = chr,
121
-            title = glue::glue("{chr}:{start}-{end}"),
122
+            title = title,
122 123
             anno_regions = anno_regions,
123 124
             spaghetti = spaghetti,
124 125
             sample_anno = sample_anno,
Browse code

Updated data spec

Shians authored on 15/05/2020 05:48:02
Showing 1 changed files
... ...
@@ -34,6 +34,7 @@ setMethod("plot_region",
34 34
         spaghetti = FALSE,
35 35
         span = NULL
36 36
         ) {
37
+
37 38
         .plot_region(
38 39
             x = x,
39 40
             chr = chr,
... ...
@@ -63,6 +64,7 @@ setMethod("plot_region",
63 64
         spaghetti = FALSE,
64 65
         span = NULL
65 66
         ) {
67
+
66 68
         chr <- as.character(chr)
67 69
         plot_region(
68 70
             x = x,
... ...
@@ -86,6 +88,7 @@ setMethod("plot_region",
86 88
     span = NULL,
87 89
     window_prop = c(0.3, 0.3)
88 90
     ) {
91
+
89 92
     sample_anno <- samples(x)
90 93
     exons_anno <- query_exons_region(
91 94
         exons(x),
... ...
@@ -100,7 +103,7 @@ setMethod("plot_region",
100 103
     methy_data <-
101 104
         query_methy(methy(x), chr, start - window_left, end + window_right) %>%
102 105
         dplyr::bind_rows() %>%
103
-        dplyr::select(-"strand", -"modified") %>%
106
+        dplyr::select(-"strand") %>%
104 107
         tibble::as_tibble()
105 108
 
106 109
     if (nrow(methy_data) == 0) {
Browse code

Fixed empty annotation plot taking up space

shians authored on 12/05/2020 05:40:40
Showing 1 changed files
... ...
@@ -127,10 +127,8 @@ setMethod("plot_region",
127 127
 
128 128
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2])
129 129
 
130
-    n_unique <- function(x) {
131
-        length(unique(x))
132
-    }
130
+    anno_height <- attr(p2, "plot_height")
133 131
 
134
-    heights <- c(1, 0.075 * n_unique(exons_anno$transcript_id))
132
+    heights <- c(1, 0.075 * anno_height)
135 133
     p1 / p2 + patchwork::plot_layout(heights = heights)
136 134
 }
Browse code

Fixed broken tag

shians authored on 12/05/2020 01:17:40
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
18 18
 #' @param spaghetti whether or not individual reads should be shown.
19 19
 #' @param span the span for loess smoothing.
20 20
 #'
21
-#' @expor
21
+#' @export
22 22
 setMethod("plot_region",
23 23
     signature(
24 24
         x = "NanoMethResult",
Browse code

Reformatted code

shians authored on 12/05/2020 01:09:56
Showing 1 changed files
... ...
@@ -9,7 +9,7 @@
9 9
 #' @return None
10 10
 #' @export
11 11
 setGeneric("plot_region", function(x, chr, start, end, ...) {
12
-  standardGeneric("plot_region")
12
+    standardGeneric("plot_region")
13 13
 })
14 14
 
15 15
 #' @rdname plot_region
... ...
@@ -18,20 +18,62 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
18 18
 #' @param spaghetti whether or not individual reads should be shown.
19 19
 #' @param span the span for loess smoothing.
20 20
 #'
21
+#' @expor
22
+setMethod("plot_region",
23
+    signature(
24
+        x = "NanoMethResult",
25
+        chr = "character",
26
+        start = "numeric",
27
+        end = "numeric"),
28
+    function(
29
+        x,
30
+        chr,
31
+        start,
32
+        end,
33
+        anno_regions = NULL,
34
+        spaghetti = FALSE,
35
+        span = NULL
36
+        ) {
37
+        .plot_region(
38
+            x = x,
39
+            chr = chr,
40
+            start = start,
41
+            end = end,
42
+            anno_regions = anno_regions,
43
+            spaghetti = spaghetti,
44
+            span = span
45
+        )
46
+    })
47
+
48
+#' @rdname plot_region
49
+#'
21 50
 #' @export
22
-setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", start = "numeric", end = "numeric"),
23
-    function(x, chr, start, end, anno_regions = NULL, spaghetti = FALSE, span = NULL) {
24
-      .plot_region(
25
-        x = x,
26
-        chr = chr,
27
-        start = start,
28
-        end = end,
29
-        anno_regions = anno_regions,
30
-        spaghetti = spaghetti,
31
-        span = span
32
-      )
33
-    }
34
-)
51
+setMethod("plot_region",
52
+    signature(
53
+        x = "NanoMethResult",
54
+        chr = "factor",
55
+        start = "numeric",
56
+        end = "numeric"),
57
+    function(
58
+        x,
59
+        chr,
60
+        start,
61
+        end,
62
+        anno_regions = NULL,
63
+        spaghetti = FALSE,
64
+        span = NULL
65
+        ) {
66
+        chr <- as.character(chr)
67
+        plot_region(
68
+            x = x,
69
+            chr = chr,
70
+            start = start,
71
+            end = end,
72
+            anno_regions = anno_regions,
73
+            spaghetti = spaghetti,
74
+            span = span
75
+        )
76
+    })
35 77
 
36 78
 
37 79
 .plot_region <- function(
... ...
@@ -41,24 +83,42 @@ setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", star
41 83
     end,
42 84
     anno_regions = NULL,
43 85
     spaghetti = FALSE,
44
-    span = NULL
86
+    span = NULL,
87
+    window_prop = c(0.3, 0.3)
45 88
     ) {
46 89
     sample_anno <- samples(x)
47
-    exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
90
+    exons_anno <- query_exons_region(
91
+        exons(x),
92
+        chr = chr,
93
+        start = start,
94
+        end = end
95
+    )
96
+
97
+    window_left <- (end - start) * window_prop[1]
98
+    window_right <- (end - start) * window_prop[2]
48 99
 
49
-    feature <- list()
50
-    feature$chr <- chr
51
-    feature$start <- start
52
-    feature$end <- end
100
+    methy_data <-
101
+        query_methy(methy(x), chr, start - window_left, end + window_right) %>%
102
+        dplyr::bind_rows() %>%
103
+        dplyr::select(-"strand", -"modified") %>%
104
+        tibble::as_tibble()
53 105
 
54
-    p1 <- with(exons_anno,
55
-         plot_feature(
56
-            feature,
106
+    if (nrow(methy_data) == 0) {
107
+        warning("no methylation data in region")
108
+        return(ggplot() + theme_void())
109
+    }
110
+
111
+    p1 <- with(
112
+        exons_anno,
113
+        plot_methylation_internal(
114
+            methy_data = methy_data,
115
+            start = start,
116
+            end = end,
117
+            chr = chr,
57 118
             title = glue::glue("{chr}:{start}-{end}"),
58
-            methy = methy(x),
59
-            sample_anno = sample_anno,
60 119
             anno_regions = anno_regions,
61 120
             spaghetti = spaghetti,
121
+            sample_anno = sample_anno,
62 122
             span = span
63 123
         )
64 124
     )
... ...
@@ -67,7 +127,9 @@ setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", star
67 127
 
68 128
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2])
69 129
 
70
-    n_unique <- function(x) { length(unique(x)) }
130
+    n_unique <- function(x) {
131
+        length(unique(x))
132
+    }
71 133
 
72 134
     heights <- c(1, 0.075 * n_unique(exons_anno$transcript_id))
73 135
     p1 / p2 + patchwork::plot_layout(heights = heights)
Browse code

Fixed R check warnings

Shians authored on 30/04/2020 06:02:25
Showing 1 changed files
... ...
@@ -13,19 +13,22 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
13 13
 })
14 14
 
15 15
 #' @rdname plot_region
16
+#'
16 17
 #' @param anno_regions the data.frame of regions to be annotated
17 18
 #' @param spaghetti whether or not individual reads should be shown.
19
+#' @param span the span for loess smoothing.
18 20
 #'
19 21
 #' @export
20 22
 setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", start = "numeric", end = "numeric"),
21
-    function(x, chr, start, end, anno_regions = NULL, spaghetti = FALSE) {
23
+    function(x, chr, start, end, anno_regions = NULL, spaghetti = FALSE, span = NULL) {
22 24
       .plot_region(
23 25
         x = x,
24 26
         chr = chr,
25 27
         start = start,
26 28
         end = end,
27 29
         anno_regions = anno_regions,
28
-        spaghetti = spaghetti
30
+        spaghetti = spaghetti,
31
+        span = span
29 32
       )
30 33
     }
31 34
 )
... ...
@@ -37,7 +40,8 @@ setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", star
37 40
     start,
38 41
     end,
39 42
     anno_regions = NULL,
40
-    spaghetti = FALSE
43
+    spaghetti = FALSE,
44
+    span = NULL
41 45
     ) {
42 46
     sample_anno <- samples(x)
43 47
     exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
... ...
@@ -54,7 +58,8 @@ setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", star
54 58
             methy = methy(x),
55 59
             sample_anno = sample_anno,
56 60
             anno_regions = anno_regions,
57
-            spaghetti = spaghetti
61
+            spaghetti = spaghetti,
62
+            span = span
58 63
         )
59 64
     )
60 65
 
Browse code

Fixed plot_region to have specified bounds

Shians authored on 17/04/2020 05:38:14
Showing 1 changed files
... ...
@@ -43,9 +43,9 @@ setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", star
43 43
     exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
44 44
 
45 45
     feature <- list()
46
-    feature$chr <- unique(exons_anno$chr)
47
-    feature$start <- min(exons_anno$start)
48
-    feature$end <- max(exons_anno$end)
46
+    feature$chr <- chr
47
+    feature$start <- start
48
+    feature$end <- end
49 49
 
50 50
     p1 <- with(exons_anno,
51 51
          plot_feature(
Browse code

Added argument defaults

Shians authored on 17/04/2020 04:25:59
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@ setGeneric("plot_region", function(x, chr, start, end, ...) {
18 18
 #'
19 19
 #' @export
20 20
 setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", start = "numeric", end = "numeric"),
21
-    function(x, chr, start, end, anno_regions, spaghetti) {
21
+    function(x, chr, start, end, anno_regions = NULL, spaghetti = FALSE) {
22 22
       .plot_region(
23 23
         x = x,
24 24
         chr = chr,
Browse code

Updated for R check compliance

Shians authored on 16/04/2020 06:35:23
Showing 1 changed files
... ...
@@ -1,25 +1,37 @@
1
-setGeneric("plot_region", function(x, gene, ...) {
2
-  standardGeneric("plot_region")
3
-})
4
-
5
-setMethod("plot_region", signature(x = "NanoMethResult", gene = "character"),
6
-    function(x, gene, ...) {
7
-        plot_region(x, gene, ...)
8
-    }
9
-)
10
-
11 1
 #' Plot region
12 2
 #'
13 3
 #' @param x the NanoMethResults object
14 4
 #' @param chr the chromosome to plot
15 5
 #' @param start the start of the plotting region
16 6
 #' @param end the end of the plotting region
7
+#' @param ... additional arguments
8
+#'
9
+#' @return None
10
+#' @export
11
+setGeneric("plot_region", function(x, chr, start, end, ...) {
12
+  standardGeneric("plot_region")
13
+})
14
+
15
+#' @rdname plot_region
17 16
 #' @param anno_regions the data.frame of regions to be annotated
18
-#' @param spaghetti whether spaghettis should be drawn
17
+#' @param spaghetti whether or not individual reads should be shown.
19 18
 #'
20
-#' @return
21 19
 #' @export
22
-plot_region <- function(
20
+setMethod("plot_region", signature(x = "NanoMethResult", chr = "character", start = "numeric", end = "numeric"),
21
+    function(x, chr, start, end, anno_regions, spaghetti) {
22
+      .plot_region(
23
+        x = x,
24
+        chr = chr,
25
+        start = start,
26
+        end = end,
27
+        anno_regions = anno_regions,
28
+        spaghetti = spaghetti
29
+      )
30
+    }
31
+)
32
+
33
+
34
+.plot_region <- function(
23 35
     x,
24 36
     chr,
25 37
     start,
Browse code

Minimum viable functions to support vignette

Shians authored on 15/04/2020 11:17:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,57 @@
1
+setGeneric("plot_region", function(x, gene, ...) {
2
+  standardGeneric("plot_region")
3
+})
4
+
5
+setMethod("plot_region", signature(x = "NanoMethResult", gene = "character"),
6
+    function(x, gene, ...) {
7
+        plot_region(x, gene, ...)
8
+    }
9
+)
10
+
11
+#' Plot region
12
+#'
13
+#' @param x the NanoMethResults object
14
+#' @param chr the chromosome to plot
15
+#' @param start the start of the plotting region
16
+#' @param end the end of the plotting region
17
+#' @param anno_regions the data.frame of regions to be annotated
18
+#' @param spaghetti whether spaghettis should be drawn
19
+#'
20
+#' @return
21
+#' @export
22
+plot_region <- function(
23
+    x,
24
+    chr,
25
+    start,
26
+    end,
27
+    anno_regions = NULL,
28
+    spaghetti = FALSE
29
+    ) {
30
+    sample_anno <- samples(x)
31
+    exons_anno <- query_exons_region(exons(x), chr = chr, start = start, end = end)
32
+
33
+    feature <- list()
34
+    feature$chr <- unique(exons_anno$chr)
35
+    feature$start <- min(exons_anno$start)
36
+    feature$end <- max(exons_anno$end)
37
+
38
+    p1 <- with(exons_anno,
39
+         plot_feature(
40
+            feature,
41
+            title = glue::glue("{chr}:{start}-{end}"),
42
+            methy = methy(x),
43
+            sample_anno = sample_anno,
44
+            anno_regions = anno_regions,
45
+            spaghetti = spaghetti
46
+        )
47
+    )
48
+
49
+    xlim <- .get_ggplot_range_x(p1)
50
+
51
+    p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2])
52
+
53
+    n_unique <- function(x) { length(unique(x)) }
54
+
55
+    heights <- c(1, 0.075 * n_unique(exons_anno$transcript_id))
56
+    p1 / p2 + patchwork::plot_layout(heights = heights)
57
+}