Browse code

oncoPrint(): column barplots are now controlled by 'top_annotation' argument

Zuguang Gu authored on 11/11/2015 08:57:00
Showing 3 changed files

... ...
@@ -3,6 +3,7 @@ CHANGES in VERSION 1.7.1
3 3
 * `x` and `y` are `unit` object now in `cell_fun`
4 4
 * add an example to visualize GO game
5 5
 * transparency is kept when making discreate color mappings
6
+* `oncoPrint()`: barplots on top now are controlled by `top_annotation` argument
6 7
 
7 8
 ================================
8 9
 
... ...
@@ -20,11 +20,10 @@
20 20
 # -axis_gp graphic paramters for axes
21 21
 # -show_row_barplot whether show barplot annotation on rows
22 22
 # -row_barplot_width width of barplot annotation on rows. It should be a `grid::unit` object
23
-# -show_column_barplot whether show barplot annotation on columns
24
-# -column_barplot_height height of barplot annotatioin on columns. it should be a `grid::unit` object.
25 23
 # -remove_empty_columns if there is no alteration in that sample, whether remove it on the heatmap
26 24
 # -heatmap_legend_param pass to `Heatmap`
27
-# -... pass to `Heatmap`
25
+# -top_annotation by default the top annotation contains barplots representing frequency of mutations in every sample.
26
+# -... pass to `Heatmap`, so can set ``bottom_annotation`` here.
28 27
 #
29 28
 # == details
30 29
 # The function returns a normal heatmap list and you can add more heatmaps/row annotations to it.
... ...
@@ -47,16 +46,20 @@ oncoPrint = function(mat, get_type = function(x) x,
47 46
 	alter_fun_list, col, 
48 47
 	row_order = oncoprint_row_order(),
49 48
 	column_order = oncoprint_column_order(),
50
-	show_column_names = FALSE, 
49
+	show_column_names = FALSE,
51 50
 	pct_gp = gpar(), 
52 51
 	axis_gp = gpar(fontsize = 8), 
53 52
 	show_row_barplot = TRUE, 
54 53
 	row_barplot_width = unit(2, "cm"),
55
-	show_column_barplot = TRUE, 
56
-	column_barplot_height = unit(2, "cm"),
57 54
 	remove_empty_columns = FALSE,
58 55
 	heatmap_legend_param = list(title = "Alterations"),
56
+	top_annotation = HeatmapAnnotation(column_bar = anno_column_bar, 
57
+		annotation_height = unit(2, "cm")),
59 58
 	...) {
59
+
60
+	if(names(list(...)) %in% c("show_column_barplot", "column_barplot_height")) {
61
+		stop("`show_column_barplot` and `column_barplot_height` is deprecated, please configure `top_annotation` directly.")
62
+	}
60 63
 	
61 64
 	# convert mat to mat_list
62 65
 	if(inherits(mat, "matrix")) {
... ...
@@ -221,7 +224,7 @@ oncoPrint = function(mat, get_type = function(x) x,
221 224
 		upViewport()
222 225
 	}
223 226
 
224
-	ha_column_bar = HeatmapAnnotation(column_bar = anno_column_bar, which = "column", height = column_barplot_height)
227
+	top_annotation = top_annotation
225 228
 
226 229
 	#####################################################################
227 230
 	# the main matrix
... ...
@@ -229,30 +232,17 @@ oncoPrint = function(mat, get_type = function(x) x,
229 232
 	dim(pheudo) = dim(arr)[1:2]
230 233
 	dimnames(pheudo) = dimnames(arr)[1:2]
231 234
 	
232
-	if(show_column_barplot) {
233
-		ht = Heatmap(pheudo, col = col, rect_gp = gpar(type = "none"), 
234
-			cluster_rows = FALSE, cluster_columns = FALSE, row_order = row_order, column_order = column_order,
235
-			cell_fun = function(j, i, x, y, width, height, fill) {
236
-				z = arr[i, j, ]
237
-				add_oncoprint("background", x, y, width, height)
238
-				for(type in all_type[z]) {
239
-					add_oncoprint(type, x, y, width, height)
240
-				}
241
-			}, show_column_names = show_column_names,
242
-			top_annotation = ha_column_bar, 
243
-			heatmap_legend_param = heatmap_legend_param, ...)
244
-	} else {
245
-		ht = Heatmap(pheudo, col = col, rect_gp = gpar(type = "none"), 
246
-			cluster_rows = FALSE, cluster_columns = FALSE, row_order = row_order, column_order = column_order,
247
-			cell_fun = function(j, i, x, y, width, height, fill) {
248
-				z = arr[i, j, ]
249
-				add_oncoprint("background", x, y, width, height)
250
-				for(type in all_type[z]) {
251
-					add_oncoprint(type, x, y, width, height)
252
-				}
253
-			}, show_column_names = show_column_names, 
254
-			heatmap_legend_param = heatmap_legend_param, ...)
255
-	}
235
+	ht = Heatmap(pheudo, col = col, rect_gp = gpar(type = "none"), 
236
+		cluster_rows = FALSE, cluster_columns = FALSE, row_order = row_order, column_order = column_order,
237
+		cell_fun = function(j, i, x, y, width, height, fill) {
238
+			z = arr[i, j, ]
239
+			add_oncoprint("background", x, y, width, height)
240
+			for(type in all_type[z]) {
241
+				add_oncoprint(type, x, y, width, height)
242
+			}
243
+		}, show_column_names = show_column_names,
244
+		top_annotation = top_annotation, 
245
+		heatmap_legend_param = heatmap_legend_param, ...)
256 246
 
257 247
 	if(show_row_barplot) {
258 248
 		ht_list = ha_pct + ht + ha_row_bar
... ...
@@ -16,10 +16,10 @@ oncoPrint(mat, get_type = function(x) x,
16 16
     axis_gp = gpar(fontsize = 8),
17 17
     show_row_barplot = TRUE,
18 18
     row_barplot_width = unit(2, "cm"),
19
-    show_column_barplot = TRUE,
20
-    column_barplot_height = unit(2, "cm"),
21 19
     remove_empty_columns = FALSE,
22 20
     heatmap_legend_param = list(title = "Alterations"),
21
+    top_annotation = HeatmapAnnotation(column_bar = anno_column_bar,
22
+    annotation_height = unit(2, "cm")),
23 23
     ...)
24 24
 }
25 25
 \arguments{
... ...
@@ -35,11 +35,10 @@ oncoPrint(mat, get_type = function(x) x,
35 35
   \item{axis_gp}{graphic paramters for axes}
36 36
   \item{show_row_barplot}{whether show barplot annotation on rows}
37 37
   \item{row_barplot_width}{width of barplot annotation on rows. It should be a \code{\link[grid]{unit}} object}
38
-  \item{show_column_barplot}{whether show barplot annotation on columns}
39
-  \item{column_barplot_height}{height of barplot annotatioin on columns. it should be a \code{\link[grid]{unit}} object.}
40 38
   \item{remove_empty_columns}{if there is no alteration in that sample, whether remove it on the heatmap}
41 39
   \item{heatmap_legend_param}{pass to \code{\link{Heatmap}}}
42
-  \item{...}{pass to \code{\link{Heatmap}}}
40
+  \item{top_annotation}{by default the top annotation contains barplots representing frequency of mutations in every sample.}
41
+  \item{...}{pass to \code{\link{Heatmap}}, so can set \code{bottom_annotation} here.}
43 42
 
44 43
 }
45 44
 \details{