... | ... |
@@ -58,7 +58,7 @@ oncoPrint = function(mat, get_type = function(x) x, |
58 | 58 |
row_barplot_width = unit(2, "cm"), |
59 | 59 |
remove_empty_columns = FALSE, |
60 | 60 |
heatmap_legend_param = list(title = "Alterations"), |
61 |
- top_annotation = HeatmapAnnotation(column_bar = anno_column_bar, |
|
61 |
+ top_annotation = HeatmapAnnotation(column_bar = anno_oncoprint_barplot(), |
|
62 | 62 |
annotation_height = unit(2, "cm")), |
63 | 63 |
barplot_ignore = NULL, |
64 | 64 |
...) { |
... | ... |
@@ -286,6 +286,13 @@ oncoPrint = function(mat, get_type = function(x) x, |
286 | 286 |
top_annotation = top_annotation, |
287 | 287 |
heatmap_legend_param = heatmap_legend_param, ...) |
288 | 288 |
|
289 |
+ ht@matrix_param$oncoprint = list() |
|
290 |
+ ht@matrix_param$oncoprint$arr = arr |
|
291 |
+ ht@matrix_param$oncoprint$barplot_ignore = barplot_ignore |
|
292 |
+ ht@matrix_param$oncoprint$all_type = all_type |
|
293 |
+ ht@matrix_param$oncoprint$axis_gp = axis_gp |
|
294 |
+ ht@matrix_param$oncoprint$col = col |
|
295 |
+ |
|
289 | 296 |
if(show_pct) { |
290 | 297 |
ht_list = ha_pct + ht |
291 | 298 |
} else { |
... | ... |
@@ -331,3 +338,45 @@ unify_mat_list = function(mat_list, default = 0) { |
331 | 338 |
} |
332 | 339 |
|
333 | 340 |
|
341 |
+ |
|
342 |
+# == title |
|
343 |
+# Column barplot annotaiton for oncoPrint |
|
344 |
+# |
|
345 |
+# == details |
|
346 |
+# This function is only used for column annotation |
|
347 |
+# |
|
348 |
+# == author |
|
349 |
+# Zuguang Gu <z.gu@dkfz.de> |
|
350 |
+# |
|
351 |
+anno_oncoprint_barplot = function() { |
|
352 |
+ |
|
353 |
+ function(index) { |
|
354 |
+ object = get("object", envir = parent.frame(n = 5)) |
|
355 |
+ arr = object@matrix_param$oncoprint$arr |
|
356 |
+ barplot_ignore = object@matrix_param$oncoprint$barplot_ignore |
|
357 |
+ all_type = object@matrix_param$oncoprint$all_type |
|
358 |
+ axis_gp = object@matrix_param$oncoprint$axis_gp |
|
359 |
+ col = object@matrix_param$oncoprint$col |
|
360 |
+ |
|
361 |
+ n = length(index) |
|
362 |
+ count = apply(arr, c(2, 3), sum)[index, , drop = FALSE] |
|
363 |
+ all_type = all_type[!(colnames(count) %in% barplot_ignore)] |
|
364 |
+ count = count[, setdiff(colnames(count), barplot_ignore), drop = FALSE] |
|
365 |
+ max_count = max(rowSums(count)) |
|
366 |
+ pushViewport(viewport(yscale = c(0, max_count*1.1), xscale = c(0.5, n + 0.5))) |
|
367 |
+ for(i in seq_len(nrow(count))) { |
|
368 |
+ if(any(count[i, ] > 0)) { |
|
369 |
+ y = count[i, ] |
|
370 |
+ y = y[y > 0] |
|
371 |
+ y2 = cumsum(y) |
|
372 |
+ type = all_type[count[i, ] > 0] |
|
373 |
+ grid.rect(i, y2, height = y, width = 0.8, default.units = "native", just = "top", gp = gpar(col = NA, fill = col[type])) |
|
374 |
+ } |
|
375 |
+ } |
|
376 |
+ breaks = grid.pretty(c(0, max_count)) |
|
377 |
+ grid.yaxis(at = breaks, label = breaks, gp = axis_gp) |
|
378 |
+ upViewport() |
|
379 |
+ } |
|
380 |
+} |
|
381 |
+ |
|
382 |
+ |
334 | 383 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+\name{anno_oncoprint_barplot} |
|
2 |
+\alias{anno_oncoprint_barplot} |
|
3 |
+\title{ |
|
4 |
+Column barplot annotaiton for oncoPrint |
|
5 |
+} |
|
6 |
+\description{ |
|
7 |
+Column barplot annotaiton for oncoPrint |
|
8 |
+} |
|
9 |
+\usage{ |
|
10 |
+anno_oncoprint_barplot() |
|
11 |
+} |
|
12 |
+\details{ |
|
13 |
+This function is only used for column annotation |
|
14 |
+} |
|
15 |
+\author{ |
|
16 |
+Zuguang Gu <z.gu@dkfz.de> |
|
17 |
+} |
|
18 |
+\examples{ |
|
19 |
+# There is no example |
|
20 |
+NULL |
|
21 |
+} |
... | ... |
@@ -18,7 +18,7 @@ oncoPrint(mat, get_type = function(x) x, |
18 | 18 |
row_barplot_width = unit(2, "cm"), |
19 | 19 |
remove_empty_columns = FALSE, |
20 | 20 |
heatmap_legend_param = list(title = "Alterations"), |
21 |
- top_annotation = HeatmapAnnotation(column_bar = anno_column_bar, |
|
21 |
+ top_annotation = HeatmapAnnotation(column_bar = anno_oncoprint_barplot(), |
|
22 | 22 |
annotation_height = unit(2, "cm")), |
23 | 23 |
barplot_ignore = NULL, |
24 | 24 |
...) |
... | ... |
@@ -45,10 +45,10 @@ element would include multiple alterations in a form of a complex string. In fol |
45 | 45 |
|
46 | 46 |
```{r} |
47 | 47 |
mat = read.table(textConnection( |
48 |
-" s1 s2 s3 |
|
49 |
-g1 snv;indel snv indel |
|
50 |
-g2 snv;indel snv |
|
51 |
-g3 snv indel;snv"), row.names = 1, header = TRUE, sep = "\t", stringsAsFactors = FALSE) |
|
48 |
+",s1,s2,s3 |
|
49 |
+g1,snv;indel,snv,indel |
|
50 |
+g2,,snv;indel,snv |
|
51 |
+g3,snv,,indel;snv"), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE) |
|
52 | 52 |
mat = as.matrix(mat) |
53 | 53 |
mat |
54 | 54 |
``` |
... | ... |
@@ -99,10 +99,11 @@ mat_list |
99 | 99 |
to adjust the matrix list. |
100 | 100 |
|
101 | 101 |
```{r} |
102 |
-mat_list$indel = mat_list$indel[1:2, 1:2] |
|
103 |
-mat_list |
|
104 |
-mat_list = unify_mat_list(mat_list) |
|
105 |
-mat_list |
|
102 |
+mat_list2 = mat_list |
|
103 |
+mat_list2$indel = mat_list2$indel[1:2, 1:2] |
|
104 |
+mat_list2 |
|
105 |
+mat_list2 = unify_mat_list(mat_list2) |
|
106 |
+mat_list2 |
|
106 | 107 |
``` |
107 | 108 |
|
108 | 109 |
Pass `mat_list` to `oncoPrint()`: |