Browse code

merge by copy paste

Zuguang Gu authored on 17/10/2017 20:55:32
Showing 31 changed files

... ...
@@ -99,6 +99,7 @@ exportMethods(set_component_height)
99 99
 import(grDevices)
100 100
 import(graphics)
101 101
 import(grid)
102
+import(methods)
102 103
 import(stats)
103 104
 importFrom("GetoptLong", qq)
104 105
 importFrom("GetoptLong", qq.options)
... ...
@@ -110,12 +111,5 @@ importFrom("circlize", rand_color)
110 111
 importFrom("circlize", smartAlign)
111 112
 importFrom("colorspace", diverge_hcl)
112 113
 importFrom("colorspace", rainbow_hcl)
113
-importFrom("dendextend", "labels<-")
114
-importFrom("dendextend", get_branches_heights)
115
-importFrom("dendextend", nnodes)
116
-importFrom("methods", "new", "show")
117
-importFrom("methods", setClass)
118
-importFrom("methods", setGeneric)
119
-importFrom("methods", setMethod)
120 114
 importFrom("utils", "getFromNamespace")
121 115
 
... ...
@@ -1,4 +1,3 @@
1
-<<<<<<< HEAD
2 1
 CHANGES in VERSION 1.15.1
3 2
 
4 3
 * random colors are generated by new `rand_color()` function in circlize package.
... ...
@@ -23,12 +22,6 @@ CHANGES in VERSION 1.15.1
23 22
 CHANGES in VERSION 1.13.2
24 23
 
25 24
 * add `packLegend()`
26
-=======
27
-CHANGES in VERSION 1.13.2
28
-
29
-* add `packLegend()`
30
-* Legend() supports to add txt labels on grids
31
->>>>>>> bioc/master
32 25
 
33 26
 ========================
34 27
 
35 28
deleted file mode 100755
... ...
@@ -1,3 +0,0 @@
1
-[Dolphin]
2
-Timestamp=2015,6,15,11,33,52
3
-ViewMode=2
... ...
@@ -1,5 +1,4 @@
1 1
 
2
-<<<<<<< HEAD
3 2
 setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
4 3
 
5 4
 setGeneric('get_color_mapping_param_list', function(object, ...) standardGeneric('get_color_mapping_param_list'))
... ...
@@ -42,49 +41,10 @@ setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_he
42 41
 
43 42
 setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
44 43
 
45
-=======
46
-setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
47
-
48
-setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
49
-
50
-setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
51
-
52
-setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
53
-
54
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
55
-
56
-setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
57
-
58
-setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
59
-
60
-setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
61
-
62
-setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
63
-
64
-setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
65
-
66
-setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
67
-
68
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
69
-
70
-setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
71
-
72
-setGeneric('get_color_mapping_param_list', function(object, ...) standardGeneric('get_color_mapping_param_list'))
73
-
74
-setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
75
-
76
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
77
-
78
-setGeneric('draw', function(object, ...) standardGeneric('draw'))
79
-
80
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
81
-
82
->>>>>>> bioc/master
83 44
 setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
84 45
 
85 46
 setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
86 47
 
87
-<<<<<<< HEAD
88 48
 setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
89 49
 
90 50
 setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
... ...
@@ -92,18 +52,3 @@ setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
92 52
 setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
93 53
 
94 54
 setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
95
-=======
96
-setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
97
-
98
-setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
99
-
100
-setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
101
-
102
-setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
103
-
104
-setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
105
-
106
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
107
-
108
-setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
109
->>>>>>> bioc/master
... ...
@@ -180,10 +180,7 @@ setMethod(f = "map_to_colors",
180 180
 	x2 = vector(length = length(x))
181 181
 
182 182
 	if(object@type == "discrete") {
183
-<<<<<<< HEAD
184 183
 		x[grepl("^\\s*$", x)] = NA
185
-=======
186
->>>>>>> bioc/master
187 184
 		lna = is.na(x)
188 185
 
189 186
 		if(is.numeric(x)) x = as.character(x)
... ...
@@ -215,17 +212,10 @@ setMethod(f = "map_to_colors",
215 212
 # -title title of the legend, by default it is the name of the legend
216 213
 # -title_gp graphical parameters for legend title
217 214
 # -title_position position of the title
218
-<<<<<<< HEAD
219 215
 # -color_bar a string of "continous" or "discrete". If the mapping is continuous, whether show the legend as discrete color bar or continuous color bar
220 216
 # -grid_height height of each legend grid.
221 217
 # -grid_width width of each legend grid.
222 218
 # -border color for legend grid borders.
223
-=======
224
-# -color_bar if the mapping is continuous, whether show the legend as discrete color bar or continuous color bar
225
-# -grid_height height of each legend grid.
226
-# -grid_width width of each legend grid.
227
-# -grid_border color for legend grid borders.
228
->>>>>>> bioc/master
229 219
 # -at break values of the legend
230 220
 # -labels labels corresponding to break values
231 221
 # -labels_gp graphcial parameters for legend labels
... ...
@@ -255,17 +245,10 @@ setMethod(f = "color_mapping_legend",
255 245
 	title = object@name,
256 246
 	title_gp = gpar(fontsize = 10, fontface = "bold"),
257 247
 	title_position = c("topleft", "topcenter", "leftcenter", "lefttop"),
258
-<<<<<<< HEAD
259 248
 	color_bar = object@type,
260 249
 	grid_height = unit(4, "mm"),
261 250
 	grid_width = unit(4, "mm"),
262 251
 	border = NULL,
263
-=======
264
-	color_bar = c("discrete", "continuous"),
265
-	grid_height = unit(4, "mm"),
266
-	grid_width = unit(4, "mm"),
267
-	grid_border = NULL,
268
->>>>>>> bioc/master
269 252
 	at = object@levels,
270 253
 	labels = at,
271 254
 	labels_gp = gpar(fontsize = 10),
... ...
@@ -285,17 +268,10 @@ setMethod(f = "color_mapping_legend",
285 268
 	title_gp = check_gp(title_gp)
286 269
 	labels_gp = check_gp(labels_gp)
287 270
 
288
-<<<<<<< HEAD
289 271
 	# color_bar = match.arg(color_bar)
290 272
 
291 273
 	if(object@type == "discrete" && color_bar == "continuous") {
292 274
 		stop("'color_bar' can only be set to 'discrete' only if the color mapping is discrete")
293
-=======
294
-	color_bar = match.arg(color_bar)
295
-
296
-	if(object@type == "discrete" && color_bar == "continuous") {
297
-		stop("'color_bar' can only be set to 'continuous' only if the color mapping is continuous")
298
->>>>>>> bioc/master
299 275
 	}
300 276
 
301 277
 	# get labels
... ...
@@ -315,21 +291,13 @@ setMethod(f = "color_mapping_legend",
315 291
 			labels = rev(labels)
316 292
 		}
317 293
 		gf = Legend(at = at, labels = labels, title = title, title_gp = title_gp, grid_height = grid_height,
318
-<<<<<<< HEAD
319 294
 			grid_width = grid_width, border = border, labels_gp = labels_gp, nrow = nrow, ncol = ncol,
320
-=======
321
-			grid_width = grid_width, border = grid_border, labels_gp = labels_gp, nrow = nrow, ncol = ncol,
322
->>>>>>> bioc/master
323 295
 			legend_gp = gpar(fill = map_to_colors(object, at)), title_position = title_position)
324 296
 
325 297
 	} else {
326 298
 
327 299
 		gf = Legend(at = at, labels = labels, col_fun = object@col_fun, title = title, title_gp = title_gp, grid_height = grid_height,
328
-<<<<<<< HEAD
329 300
 			grid_width = grid_width, border = border, labels_gp = labels_gp, direction = legend_direction,
330
-=======
331
-			grid_width = grid_width, border = grid_border, labels_gp = labels_gp, direction = legend_direction,
332
->>>>>>> bioc/master
333 301
 			legend_width = legend_width, legend_height = legend_height, title_position = title_position)
334 302
 
335 303
 	}
... ...
@@ -191,11 +191,7 @@ Heatmap = setClass("Heatmap",
191 191
 # -bottom_annotation_height total height of the column annotations on the bottom.
192 192
 # -km do k-means clustering on rows. If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering.
193 193
 #     For each row-clusters, hierarchical clustering is still applied with parameters above.
194
-<<<<<<< HEAD
195 194
 # -km_title row title for each cluster when ``km`` is set. It must a text with format of ".*\%i.*" where "\%i" is replaced by the index of the cluster.
196
-=======
197
-# -km_title row title for each cluster when ``km`` is set. It must a text with format of "*\%i*" where "\%i" is replaced by the index of the cluster.
198
->>>>>>> bioc/master
199 195
 # -split a vector or a data frame by which the rows are split. But if ``cluster_rows`` is a clustering object, ``split`` can be a single number
200 196
 #        indicating rows are to be split according to the split on the tree.
201 197
 # -gap gap between row-slices if the heatmap is split by rows, should be `grid::unit` object. If it is a vector, the order corresponds
... ...
@@ -206,12 +202,8 @@ Heatmap = setClass("Heatmap",
206 202
 #        is appended to a list of heatmaps.
207 203
 # -show_heatmap_legend whether show heatmap legend?
208 204
 # -heatmap_legend_param a list contains parameters for the heatmap legend. See `color_mapping_legend,ColorMapping-method` for all available parameters.
209
-<<<<<<< HEAD
210 205
 # -use_raster whether render the heatmap body as a raster image. It helps to reduce file size when the matrix is huge. Note if ``cell_fun``
211 206
 #       is set, ``use_raster`` is enforced to be ``FALSE``.
212
-=======
213
-# -use_raster whether render the heatmap body as a raster image. It helps to reduce file size when the matrix is huge.
214
->>>>>>> bioc/master
215 207
 # -raster_device graphic device which is used to generate the raster image
216 208
 # -raster_quality a value set to larger than 1 will improve the quality of the raster image.
217 209
 # -raster_device_param a list of further parameters for the selected graphic device
... ...
@@ -239,11 +231,7 @@ Heatmap = function(matrix, col, name,
239 231
     na_col = "grey", 
240 232
     color_space = "LAB",
241 233
     rect_gp = gpar(col = NA), 
242
-<<<<<<< HEAD
243 234
     cell_fun = NULL,
244
-=======
245
-    cell_fun = function(j, i, x, y, width, height, fill) NULL,
246
->>>>>>> bioc/master
247 235
     row_title = character(0), 
248 236
     row_title_side = c("left", "right"), 
249 237
     row_title_gp = gpar(fontsize = 14), 
... ...
@@ -282,19 +270,11 @@ Heatmap = function(matrix, col, name,
282 270
     column_order = NULL,
283 271
     row_names_side = c("right", "left"), 
284 272
     show_row_names = TRUE, 
285
-<<<<<<< HEAD
286 273
     row_names_max_width = default_row_names_max_width(), 
287 274
     row_names_gp = gpar(fontsize = 12), 
288 275
     column_names_side = c("bottom", "top"), 
289 276
     show_column_names = TRUE, 
290 277
     column_names_max_height = default_column_names_max_height(), 
291
-=======
292
-    row_names_max_width = unit(4, "cm"), 
293
-    row_names_gp = gpar(fontsize = 12), 
294
-    column_names_side = c("bottom", "top"), 
295
-    show_column_names = TRUE, 
296
-    column_names_max_height = unit(4, "cm"), 
297
->>>>>>> bioc/master
298 278
     column_names_gp = gpar(fontsize = 12),
299 279
     top_annotation = new("HeatmapAnnotation"),
300 280
     top_annotation_height = top_annotation@size,
... ...
@@ -307,17 +287,10 @@ Heatmap = function(matrix, col, name,
307 287
     combined_name_fun = function(x) paste(x, collapse = "/"),
308 288
     width = NULL, 
309 289
     show_heatmap_legend = TRUE,
310
-<<<<<<< HEAD
311 290
     heatmap_legend_param = list(title = name),
312 291
     use_raster = FALSE, 
313 292
     raster_device = c("png", "jpeg", "tiff", "CairoPNG", "CairoJPEG", "CairoTIFF"),
314 293
     raster_quality = 2,
315
-=======
316
-    heatmap_legend_param = list(title = name, color_bar = "discrete"),
317
-    use_raster = FALSE, 
318
-    raster_device = c("png", "jpeg", "tiff", "CairoPNG", "CairoJPEG", "CairoTIFF"),
319
-    raster_quality = 1,
320
->>>>>>> bioc/master
321 294
     raster_device_param = list()) {
322 295
 
323 296
     # re-define some of the argument values according to global settings
... ...
@@ -528,12 +501,9 @@ Heatmap = function(matrix, col, name,
528 501
     .Object@row_names_param$side = match.arg(row_names_side)[1]
529 502
     .Object@row_names_param$show = show_row_names
530 503
     .Object@row_names_param$gp = check_gp(row_names_gp)
531
-<<<<<<< HEAD
532 504
     default_row_names_max_width = function() {
533 505
         min(unit.c(unit(6, "cm")), max_text_width(rownames(matrix), gp = .Object@row_names_param$gp))
534 506
     }
535
-=======
536
->>>>>>> bioc/master
537 507
     .Object@row_names_param$max_width = row_names_max_width + unit(2, "mm")
538 508
 
539 509
     if(is.null(colnames(matrix))) {
... ...
@@ -542,12 +512,9 @@ Heatmap = function(matrix, col, name,
542 512
     .Object@column_names_param$side = match.arg(column_names_side)[1]
543 513
     .Object@column_names_param$show = show_column_names
544 514
     .Object@column_names_param$gp = check_gp(column_names_gp)
545
-<<<<<<< HEAD
546 515
     default_column_names_max_height = function() {
547 516
         min(unit.c(unit(6, "cm")), max_text_width(colnames(matrix), gp = .Object@column_names_param$gp))
548 517
     }
549
-=======
550
->>>>>>> bioc/master
551 518
     .Object@column_names_param$max_height = column_names_max_height + unit(2, "mm")
552 519
 
553 520
     if(inherits(cluster_rows, "dendrogram") || inherits(cluster_rows, "hclust")) {
... ...
@@ -1329,14 +1296,11 @@ setMethod(f = "draw_heatmap_body",
1329 1296
     y = (rev(seq_len(nr)) - 0.5) / nr
1330 1297
     expand_index = expand.grid(seq_len(nr), seq_len(nc))
1331 1298
     
1332
-<<<<<<< HEAD
1333 1299
     cell_fun = object@matrix_param$cell_fun
1334 1300
     if(!is.null(cell_fun)) {
1335 1301
         use_raster = FALSE
1336 1302
     }
1337 1303
         
1338
-=======
1339
->>>>>>> bioc/master
1340 1304
     if(use_raster) {
1341 1305
         # write the image into a temporary file and read it back
1342 1306
         device_info = switch(raster_device,
... ...
@@ -1359,7 +1323,6 @@ setMethod(f = "draw_heatmap_body",
1359 1323
         if(heatmap_width <= 0 || heatmap_height <= 0) {
1360 1324
             stop("The width or height of the raster image is zero, maybe you forget to turn off the previous graphic device or it was corrupted. Run `dev.off()` to close it.")
1361 1325
         }
1362
-<<<<<<< HEAD
1363 1326
         tmp_dir = "."
1364 1327
         # dir.create(tmp_dir, showWarnings = FALSE)
1365 1328
         temp_image = tempfile(pattern = paste0(".heatmap_body_", object@name, "_", k, "_"), tmpdir = tmp_dir, fileext = paste0(".", device_info[2]))
... ...
@@ -1415,43 +1378,10 @@ setMethod(f = "draw_heatmap_body",
1415 1378
         }
1416 1379
     }
1417 1380
 
1418
-=======
1419
-        temp_image = tempfile(pattern = paste0(".heatmap_body_", object@name, "_", k, "_"), tmpdir = ".", fileext = paste0(".", device_info[2]))
1420
-        #getFromNamespace(raster_device, ns = device_info[1])(temp_image, width = heatmap_width*raster_quality, height = heatmap_height*raster_quality)
1421
-        device_fun = getFromNamespace(raster_device, ns = device_info[1])
1422
-        do.call("device_fun", c(list(filename = temp_image, width = heatmap_width*raster_quality, height = heatmap_height*raster_quality), raster_device_param))
1423
-    }
1424
-
1425
-    if(any(names(gp) %in% c("type"))) {
1426
-        if(gp$type == "none") {
1427
-        } else {
1428
-            grid.rect(x[expand_index[[2]]], y[expand_index[[1]]], width = unit(1/nc, "npc"), height = unit(1/nr, "npc"), gp = do.call("gpar", c(list(fill = col_matrix), gp)))
1429
-        }
1430
-    } else {
1431
-        grid.rect(x[expand_index[[2]]], y[expand_index[[1]]], width = unit(1/nc, "npc"), height = unit(1/nr, "npc"), gp = do.call("gpar", c(list(fill = col_matrix), gp)))
1432
-    }
1433
-
1434
-    cell_fun = object@matrix_param$cell_fun
1435
-    for(i in row_order) {
1436
-        for(j in column_order) {
1437
-            cell_fun(j, i, unit(x[which(column_order == j)], "npc"), unit(y[which(row_order == i)], "npc"), unit(1/nc, "npc"), unit(1/nr, "npc"), col_matrix[which(row_order == i), which(column_order == j)])
1438
-        }
1439
-    }
1440
-
1441
-    if(use_raster) {
1442
-        dev.off()
1443
-        image = getFromNamespace(device_info[3], ns = device_info[2])(temp_image)
1444
-        image = as.raster(image)
1445
-        grid.raster(image, width = unit(1, "npc"), height = unit(1, "npc"))
1446
-        file.remove(temp_image)
1447
-    }
1448
-
1449
->>>>>>> bioc/master
1450 1381
     upViewport()
1451 1382
 
1452 1383
 })
1453 1384
 
1454
-<<<<<<< HEAD
1455 1385
 is_windows = function() {
1456 1386
     tolower(.Platform$OS.type) == "windows"
1457 1387
 }
... ...
@@ -1461,8 +1391,6 @@ R_binary = function() {
1461 1391
     return(file.path(R.home("bin"), R_exe))
1462 1392
 }
1463 1393
 
1464
-=======
1465
->>>>>>> bioc/master
1466 1394
 # == title
1467 1395
 # Draw dendrogram on row or column
1468 1396
 #
... ...
@@ -1517,11 +1445,7 @@ setMethod(f = "draw_dend",
1517 1445
 
1518 1446
     dend = as.dendrogram(hc)
1519 1447
     n = length(labels(dend))
1520
-<<<<<<< HEAD
1521 1448
     if(nobs(dend) <= 1) {
1522
-=======
1523
-    if(nnodes(dend) <= 1) {
1524
->>>>>>> bioc/master
1525 1449
         return(invisible(NULL))
1526 1450
     }
1527 1451
 
... ...
@@ -245,7 +245,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
245 245
 			} else if(is.atomic(anno_arg_list[[ag]])) {
246 246
 
247 247
 			    if(is.null(simple_length)) {
248
-<<<<<<< HEAD
249 248
 			    	if(is.matrix(anno_arg_list[[ag]])) {
250 249
 			    		simple_length = nrow(anno_arg_list[[ag]])
251 250
 			    	} else {
... ...
@@ -261,11 +260,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
261 260
 			    			stop("length of simple annotations differ.")
262 261
 			    		}
263 262
 			    	}
264
-=======
265
-			    	simple_length = length(anno_arg_list[[ag]])
266
-			    } else if(length(anno_arg_list[[ag]]) != simple_length) {
267
-			    	stop("length of simple annotations differ.")
268
->>>>>>> bioc/master
269 263
 			    }
270 264
 				if(missing(col)) {
271 265
 			        anno_list = c(anno_list, list(SingleAnnotation(name = ag, value = anno_arg_list[[ag]], na_col = na_col, which = which, 
... ...
@@ -322,7 +316,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
322 316
 
323 317
 	if(length(anno_size) == 1) {
324 318
 		if(!is.unit(anno_size)) {
325
-<<<<<<< HEAD
326 319
 			anno_size = sapply(anno_list, function(x) {
327 320
 				if(is_simple_annotation(x)) {
328 321
 					return(1)
... ...
@@ -332,9 +325,6 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
332 325
 					return(2)
333 326
 				}
334 327
 			})
335
-=======
336
-			anno_size = rep(anno_size, n_total_anno)
337
->>>>>>> bioc/master
338 328
 		}
339 329
 	}
340 330
 
... ...
@@ -154,22 +154,15 @@ setMethod(f = "add_heatmap",
154 154
     ht_name = names(object@ht_list)
155 155
     which_duplicated = duplicated(ht_name)
156 156
     if(any(which_duplicated)) {
157
-<<<<<<< HEAD
158 157
         warning(paste0("Heatmap/row annotation names are duplicated: ", paste(ht_name[which_duplicated], collapse = ", ")))
159
-=======
160
-        warning(paste0("Heatmap/row annotaiton names are duplicated: ", paste(ht_name[which_duplicated], collapse = ", ")))
161
->>>>>>> bioc/master
162 158
     }
163 159
 
164 160
     l = which(sapply(object@ht_list, inherits, "Heatmap"))
165 161
     nr = sapply(object@ht_list[l], function(ht) nrow(ht@matrix))
166 162
 
167 163
     if(length(unique(nr)) > 1) {
168
-<<<<<<< HEAD
169 164
         cat("`nrow` of all heatmaps:\n")
170 165
         print(nr)
171
-=======
172
->>>>>>> bioc/master
173 166
         stop("`nrow` of all heatmaps should be the same.")
174 167
         for(i in l) {
175 168
             cat(object@ht_list[[i]]@name, ":", nrow(object@ht_list[[i]]@matrix), "\n")
... ...
@@ -192,10 +185,7 @@ setMethod(f = "add_heatmap",
192 185
 # -column_title_side will the title be put on the top or bottom of the heatmap.
193 186
 # -column_title_gp graphic parameters for drawing text.
194 187
 # -heatmap_legend_side side of the heatmap legend.
195
-<<<<<<< HEAD
196 188
 # -merge_legends whether put heatmap legends and annotation legends in a same column
197
-=======
198
->>>>>>> bioc/master
199 189
 # -show_heatmap_legend whether show heatmap legend.
200 190
 # -heatmap_legend_list a list of self-defined legend, should be wrapped into `grid::grob` objects.
201 191
 # -annotation_legend_side side of annotation legend.
... ...
@@ -216,10 +206,7 @@ setMethod(f = "add_heatmap",
216 206
 # -row_order same setting as in `Heatmap`, if it is specified, ``row_order`` in main heatmap is ignored.
217 207
 # -km same setting as in `Heatmap`, if it is specified, ``km`` in main heatmap is ignored.
218 208
 # -split same setting as in `Heatmap`, if it is specified, ``split`` in main heatmap is ignored.
219
-<<<<<<< HEAD
220 209
 # -combined_name_fun same setting as in `Heatmap`, if it is specified, ``combined_name_fun`` in main heatmap is ignored.
221
-=======
222
->>>>>>> bioc/master
223 210
 #
224 211
 # == detail
225 212
 # It sets the size of each component of the heatmap list and adjusts graphic parameters for each heatmap if necessary.
... ...
@@ -243,10 +230,7 @@ setMethod(f = "make_layout",
243 230
     column_title_side = c("top", "bottom"), 
244 231
     column_title_gp = gpar(fontsize = 14), 
245 232
     heatmap_legend_side = c("right", "left", "bottom", "top"), 
246
-<<<<<<< HEAD
247 233
     merge_legends = FALSE,
248
-=======
249
->>>>>>> bioc/master
250 234
     show_heatmap_legend = TRUE, 
251 235
     heatmap_legend_list = list(),
252 236
     annotation_legend_side = c("right", "left", "bottom", "top"), 
... ...
@@ -266,12 +250,8 @@ setMethod(f = "make_layout",
266 250
     row_dend_gp = NULL,
267 251
     row_order = NULL,
268 252
     km = NULL,
269
-<<<<<<< HEAD
270 253
     split = NULL,
271 254
     combined_name_fun = NULL) {
272
-=======
273
-    split = NULL) {
274
->>>>>>> bioc/master
275 255
 
276 256
     if(object@layout$initialized) {
277 257
         return(object)
... ...
@@ -309,11 +289,8 @@ setMethod(f = "make_layout",
309 289
     }
310 290
     object@ht_list_param$gap = gap
311 291
 
312
-<<<<<<< HEAD
313 292
     object@ht_list_param$merge_legends = merge_legends
314 293
 
315
-=======
316
->>>>>>> bioc/master
317 294
     for(i in seq_len(n)) {
318 295
         # if the zero-column matrix is the first one
319 296
         if(inherits(object@ht_list[[i]], "Heatmap")) {
... ...
@@ -333,12 +310,9 @@ setMethod(f = "make_layout",
333 310
     if(!is.null(km)) {
334 311
         object@ht_list[[i_main]]@matrix_param$km = km
335 312
     }
336
-<<<<<<< HEAD
337 313
     if(!missing(combined_name_fun)) {
338 314
         object@ht_list[[i_main]]@matrix_param$combined_name_fun = combined_name_fun
339 315
     }
340
-=======
341
->>>>>>> bioc/master
342 316
 
343 317
     if(!is.null(cluster_rows)) {
344 318
 
... ...
@@ -482,12 +456,8 @@ setMethod(f = "make_layout",
482 456
     }
483 457
     object@ht_list_param$gap = gap
484 458
     object@ht_list_param$main_heatmap = i_main
485
-<<<<<<< HEAD
486 459
     object@ht_list_param$merge_legends = merge_legends
487 460
 
488
-=======
489
-    
490
->>>>>>> bioc/master
491 461
     n = length(object@ht_list)
492 462
 
493 463
     ## orders of other heatmaps should be changed
... ...
@@ -633,7 +603,6 @@ setMethod(f = "make_layout",
633 603
     for(i in seq_along(object@ht_list)) {
634 604
         ht = object@ht_list[[i]]
635 605
         if(inherits(ht, "Heatmap")) {
636
-<<<<<<< HEAD
637 606
             if(merge_legends && !is.null(ht@top_annotation)) {
638 607
                 ColorMappingList = c(ColorMappingList, get_color_mapping_list(ht@top_annotation))
639 608
             }
... ...
@@ -643,11 +612,6 @@ setMethod(f = "make_layout",
643 612
             if(merge_legends && !is.null(ht@bottom_annotation)) {
644 613
                 ColorMappingList = c(ColorMappingList, get_color_mapping_list(ht@bottom_annotation))
645 614
             }
646
-=======
647
-            if(ht@heatmap_param$show_heatmap_legend) {
648
-                ColorMappingList = c(ColorMappingList, ht@matrix_color_mapping)
649
-            }
650
->>>>>>> bioc/master
651 615
         }
652 616
         if(inherits(ht, "HeatmapAnnotation")) {
653 617
             ColorMappingList = c(ColorMappingList, get_color_mapping_list(ht))
... ...
@@ -695,7 +659,6 @@ setMethod(f = "make_layout",
695 659
     ## annotation legend to top, bottom, left and right
696 660
     # default values
697 661
     ColorMappingList = list()
698
-<<<<<<< HEAD
699 662
     if(!merge_legends) {
700 663
         for(i in seq_along(object@ht_list)) {
701 664
             ht = object@ht_list[[i]]
... ...
@@ -710,18 +673,6 @@ setMethod(f = "make_layout",
710 673
         }
711 674
     } else {
712 675
         annotation_legend_list = list()
713
-=======
714
-    for(i in seq_along(object@ht_list)) {
715
-        ht = object@ht_list[[i]]
716
-        if(inherits(ht, "Heatmap")) {
717
-            if(!is.null(ht@top_annotation)) {
718
-                ColorMappingList = c(ColorMappingList, get_color_mapping_list(ht@top_annotation))
719
-            }
720
-            if(!is.null(ht@bottom_annotation)) {
721
-                ColorMappingList = c(ColorMappingList, get_color_mapping_list(ht@bottom_annotation))
722
-            }
723
-        }
724
->>>>>>> bioc/master
725 676
     }
726 677
     if(length(ColorMappingList) == 0 && length(annotation_legend_list) == 0) {
727 678
         show_annotation_legend = FALSE
... ...
@@ -1244,27 +1195,20 @@ setMethod(f = "draw_heatmap_legend",
1244 1195
     ColorMappingList = list()
1245 1196
     ColorMappingParamList = list()
1246 1197
     for(i in seq_along(object@ht_list)) {
1247
-<<<<<<< HEAD
1248 1198
         ht = object@ht_list[[i]]
1249 1199
         if(inherits(object@ht_list[[i]], "Heatmap")) {
1250 1200
             if(object@ht_list_param$merge_legends && !is.null(ht@top_annotation)) {
1251 1201
                 ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@top_annotation))
1252 1202
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@top_annotation))
1253 1203
             }
1254
-=======
1255
-        if(inherits(object@ht_list[[i]], "Heatmap")) {
1256
->>>>>>> bioc/master
1257 1204
             if(object@ht_list[[i]]@heatmap_param$show_heatmap_legend) {
1258 1205
                 ColorMappingList = c.list(ColorMappingList, object@ht_list[[i]]@matrix_color_mapping)
1259 1206
                 ColorMappingParamList = c.list(ColorMappingParamList, object@ht_list[[i]]@matrix_color_mapping_param)
1260 1207
             }
1261
-<<<<<<< HEAD
1262 1208
             if(object@ht_list_param$merge_legends && !is.null(ht@bottom_annotation)) {
1263 1209
                 ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@bottom_annotation))
1264 1210
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@bottom_annotation))
1265 1211
             }
1266
-=======
1267
->>>>>>> bioc/master
1268 1212
         } else if(inherits(object@ht_list[[i]], "HeatmapAnnotation")) {
1269 1213
             ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(object@ht_list[[i]]))
1270 1214
             ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(object@ht_list[[i]]))
... ...
@@ -1385,28 +1329,21 @@ setMethod(f = "heatmap_legend_size",
1385 1329
     ColorMappingList = list()
1386 1330
     ColorMappingParamList = list()
1387 1331
     for(i in seq_along(object@ht_list)) {
1388
-<<<<<<< HEAD
1389 1332
         ht = object@ht_list[[i]]
1390 1333
         if(inherits(object@ht_list[[i]], "Heatmap")) {
1391 1334
             if(object@ht_list_param$merge_legends && !is.null(ht@top_annotation)) {
1392 1335
                 ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@top_annotation))
1393 1336
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@top_annotation))
1394 1337
             }
1395
-=======
1396
-        if(inherits(object@ht_list[[i]], "Heatmap")) {
1397
->>>>>>> bioc/master
1398 1338
             if(object@ht_list[[i]]@heatmap_param$show_heatmap_legend) {
1399 1339
                 ColorMappingList = c.list(ColorMappingList, object@ht_list[[i]]@matrix_color_mapping)
1400 1340
                 ColorMappingParamList = c.list(ColorMappingParamList, object@ht_list[[i]]@matrix_color_mapping_param)
1401 1341
             }
1402
-<<<<<<< HEAD
1403 1342
             if(object@ht_list_param$merge_legends && !is.null(ht@bottom_annotation)) {
1404 1343
                 ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(ht@bottom_annotation))
1405 1344
                 ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(ht@bottom_annotation))
1406 1345
             }
1407 1346
             
1408
-=======
1409
->>>>>>> bioc/master
1410 1347
         } else if(inherits(object@ht_list[[i]], "HeatmapAnnotation")) {
1411 1348
             ColorMappingList = c.list(ColorMappingList, list = get_color_mapping_list(object@ht_list[[i]]))
1412 1349
             ColorMappingParamList = c.list(ColorMappingParamList, list = get_color_mapping_param_list(object@ht_list[[i]]))
... ...
@@ -1473,15 +1410,12 @@ draw_legend = function(ColorMappingList, ColorMappingParamList, side = c("right"
1473 1410
 
1474 1411
     side = match.arg(side)[1]
1475 1412
 
1476
-<<<<<<< HEAD
1477 1413
     # remove legends which are duplicated by testing the names
1478 1414
     legend_names = sapply(ColorMappingList, function(x) x@name)
1479 1415
     l = !duplicated(legend_names)
1480 1416
     ColorMappingList = ColorMappingList[l]
1481 1417
     ColorMappingParamList = ColorMappingParamList[l]
1482 1418
 
1483
-=======
1484
->>>>>>> bioc/master
1485 1419
     n = length(ColorMappingList)
1486 1420
     if(n == 0 && length(legend_list) == 0) {
1487 1421
         return(unit(c(0, 0), "null"))
... ...
@@ -135,17 +135,10 @@ Legend = function(at, labels = at, nrow = NULL, ncol = 1, col_fun,
135 135
 	# for(i in seq_len(length(odevlist) - length(dev.list()))) {
136 136
 	# 	dev.off()
137 137
 	# }
138
-<<<<<<< HEAD
139 138
 	return(gf)
140 139
 }
141 140
 
142 141
 # grids are arranged by rows
143
-=======
144
-
145
-	return(gf)
146
-}
147
-
148
->>>>>>> bioc/master
149 142
 discrete_legend_body = function(at, labels = at, nrow = NULL, ncol = 1,
150 143
 	grid_height = unit(4, "mm"), grid_width = unit(4, "mm"), gap = unit(2, "mm"),
151 144
 	labels_gp = gpar(fontsize = 10),
... ...
@@ -163,27 +156,18 @@ discrete_legend_body = function(at, labels = at, nrow = NULL, ncol = 1,
163 156
 		nrow = 1
164 157
 		ncol = 1
165 158
 	}
166
-<<<<<<< HEAD
167 159
 	ncol = ifelse(ncol > n_labels, n_labels, ncol)
168 160
 
169 161
 	labels_mat = matrix(c(labels, rep("", nrow*ncol - n_labels)), nrow = nrow, ncol = ncol, byrow = TRUE)
170 162
 	index_mat = matrix(1:(nrow*ncol), nrow = nrow, ncol = ncol, byrow = TRUE)
171 163
 
172
-=======
173
->>>>>>> bioc/master
174 164
 
175 165
 	labels_padding_left = unit(1, "mm")
176 166
 	
177 167
 	labels_max_width = NULL
178 168
 	for(i in 1:ncol) {
179
-<<<<<<< HEAD
180 169
 		if(i == 1) {
181 170
 			labels_max_width = max(do.call("unit.c", lapply(labels_mat[, i], function(x) {
182
-=======
183
-		index = seq(nrow*(i-1)+1, min(c(nrow*i, n_labels)))
184
-		if(i == 1) {
185
-			labels_max_width = max(do.call("unit.c", lapply(labels[index], function(x) {
186
->>>>>>> bioc/master
187 171
 					g = grobWidth(textGrob(x, gp = labels_gp))
188 172
 					if(i < ncol) {
189 173
 						g = g + gap
... ...
@@ -191,11 +175,7 @@ discrete_legend_body = function(at, labels = at, nrow = NULL, ncol = 1,
191 175
 					g
192 176
 				})))
193 177
 		} else {
194
-<<<<<<< HEAD
195 178
 			labels_max_width = unit.c(labels_max_width, max(do.call("unit.c", lapply(labels_mat[, i], function(x) {
196
-=======
197
-			labels_max_width = unit.c(labels_max_width, max(do.call("unit.c", lapply(labels[index], function(x) {
198
->>>>>>> bioc/master
199 179
 					g = grobWidth(textGrob(x, gp = labels_gp))
200 180
 					if(i < ncol) {
201 181
 						g = g + gap
... ...
@@ -215,11 +195,7 @@ discrete_legend_body = function(at, labels = at, nrow = NULL, ncol = 1,
215 195
 
216 196
 	# legend grid
217 197
 	for(i in 1:ncol) {
218
-<<<<<<< HEAD
219 198
 		index = index_mat[, i][labels_mat[, i] != ""]
220
-=======
221
-		index = seq(nrow*(i-1)+1, min(c(nrow*i, n_labels)))
222
->>>>>>> bioc/master
223 199
 		ni = length(index)
224 200
 		x = unit(rep(0, ni), "npc")
225 201
 		y = (0:(ni-1))*(grid_height)
... ...
@@ -245,15 +221,7 @@ discrete_legend_body = function(at, labels = at, nrow = NULL, ncol = 1,
245 221
 		if(any(c("points", "p") %in% type)) {
246 222
 			if(length(pch) == 1) pch = rep(pch, n_labels)
247 223
 			if(length(size) == 1) size = rep(size, n_labels)
248
-<<<<<<< HEAD
249 224
 			gf = placeGrob(gf, row = 1, col = 2*i-1, grob = pointsGrob(x+grid_width*0.5, y-grid_height*0.5, pch = pch[index], size = size[index], gp = subset_gp(legend_gp, index)))
250
-=======
251
-			if(inherits(pch, "character")) {
252
-				gf = placeGrob(gf, row = 1, col = 2*i-1, grob = textGrob(pch[index], x+grid_width*0.5, y-grid_height*0.5, gp = subset_gp(legend_gp, index)))
253
-			} else {
254
-				gf = placeGrob(gf, row = 1, col = 2*i-1, grob = pointsGrob(x+grid_width*0.5, y-grid_height*0.5, pch = pch[index], size = size[index], gp = subset_gp(legend_gp, index)))
255
-			}
256
->>>>>>> bioc/master
257 225
 		}
258 226
 		if(any(c("lines", "l") %in% type)) {
259 227
 			gf = placeGrob(gf, row = 1, col = 2*i-1, grob = segmentsGrob(x+unit(0.5, "mm"), y-grid_height*0.5, x+grid_width - unit(0.5, "mm"), y-grid_height*0.5, gp = subset_gp(legend_gp, index)))
... ...
@@ -35,12 +35,8 @@ SingleAnnotation = setClass("SingleAnnotation",
35 35
 		show_legend = "logical",
36 36
 		which = "character",
37 37
 		name_to_data_vp = "logical",
38
-<<<<<<< HEAD
39 38
 		name_param = "list",
40 39
         is_anno_matrix = "logical"
41
-=======
42
-		name_param = "list"
43
->>>>>>> bioc/master
44 40
 	),
45 41
 	prototype = list(
46 42
 		color_mapping = NULL,
... ...
@@ -142,7 +138,6 @@ SingleAnnotation = function(name, value, col, fun,
142 138
         stop("`name_rot` can only take values in c(0, 90, 180, 270)")
143 139
     }
144 140
 
145
-<<<<<<< HEAD
146 141
     .Object@is_anno_matrix = FALSE
147 142
     use_mat_column_names = FALSE
148 143
     if(!missing(value)) {
... ...
@@ -161,15 +156,11 @@ SingleAnnotation = function(name, value, col, fun,
161 156
         }
162 157
     }
163 158
 
164
-=======
165
-    
166
->>>>>>> bioc/master
167 159
     if(which == "column") {
168 160
     	if(!name_side %in% c("left", "right")) {
169 161
     		stop("`name_side` should be 'left' or 'right' when it is a column annotation.")
170 162
     	}
171 163
     	if(name_side == "left") {
172
-<<<<<<< HEAD
173 164
     		
174 165
             if(use_mat_column_names) {
175 166
                 name_x = unit(rep(0, use_mat_nc), "npc") - name_offset
... ...
@@ -178,10 +169,6 @@ SingleAnnotation = function(name, value, col, fun,
178 169
                 name_x = unit(0, "npc") - name_offset
179 170
                 name_y = unit(0.5, "npc")
180 171
             }
181
-=======
182
-    		name_x = unit(0, "npc") - name_offset
183
-    		name_y = unit(0.5, "npc")
184
->>>>>>> bioc/master
185 172
             if(name_rot == 0) {
186 173
                 name_just = "right"
187 174
             } else if(name_rot == 90) {
... ...
@@ -192,7 +179,6 @@ SingleAnnotation = function(name, value, col, fun,
192 179
                 name_just = "top"
193 180
             }
194 181
     	} else {
195
-<<<<<<< HEAD
196 182
             if(use_mat_column_names) {
197 183
                 name_x = unit(rep(1, use_mat_nc), "npc") + name_offset
198 184
                 name_y = unit((use_mat_nc - seq_len(use_mat_nc) + 0.5)/use_mat_nc, "npc")
... ...
@@ -200,10 +186,6 @@ SingleAnnotation = function(name, value, col, fun,
200 186
         		name_x = unit(1, "npc") + name_offset
201 187
         		name_y = unit(0.5, "npc")
202 188
             }
203
-=======
204
-    		name_x = unit(1, "npc") + name_offset
205
-    		name_y = unit(0.5, "npc")
206
->>>>>>> bioc/master
207 189
             if(name_rot == 0) {
208 190
                 name_just = "left"
209 191
             } else if(name_rot == 90) {
... ...
@@ -219,7 +201,6 @@ SingleAnnotation = function(name, value, col, fun,
219 201
     		stop("`name_side` should be 'left' or 'right' when it is a column annotation.")
220 202
     	}
221 203
     	if(name_side == "top") {
222
-<<<<<<< HEAD
223 204
             if(use_mat_column_names) {
224 205
                 name_x = unit((seq_len(use_mat_nc) - 0.5)/use_mat_nc, "npc")
225 206
                 name_y = unit(rep(1, use_mat_nc), "npc") + name_offset
... ...
@@ -227,10 +208,6 @@ SingleAnnotation = function(name, value, col, fun,
227 208
         		name_x = unit(0.5, "npc")
228 209
         		name_y = unit(1, "npc") + name_offset
229 210
             }
230
-=======
231
-    		name_x = unit(0.5, "npc")
232
-    		name_y = unit(1, "npc") + name_offset
233
->>>>>>> bioc/master
234 211
             if(name_rot == 0) {
235 212
                 name_just = "bottom"
236 213
             } else if(name_rot == 90) {
... ...
@@ -241,7 +218,6 @@ SingleAnnotation = function(name, value, col, fun,
241 218
                 name_just = "right"
242 219
             }
243 220
     	} else {
244
-<<<<<<< HEAD
245 221
             if(use_mat_column_names) {
246 222
                 name_x = unit((seq_len(use_mat_nc) - 0.5)/use_mat_nc, "npc")
247 223
                 name_y = unit(rep(0, use_mat_nc), "npc") - name_offset
... ...
@@ -249,10 +225,6 @@ SingleAnnotation = function(name, value, col, fun,
249 225
         		name_x = unit(0.5, "npc")
250 226
         		name_y = unit(0, "npc") - name_offset
251 227
             }
252
-=======
253
-    		name_x = unit(0.5, "npc")
254
-    		name_y = unit(0, "npc") - name_offset
255
->>>>>>> bioc/master
256 228
             if(name_rot == 0) {
257 229
                 name_just = "top"
258 230
             } else if(name_rot == 90) {
... ...
@@ -269,38 +241,18 @@ SingleAnnotation = function(name, value, col, fun,
269 241
     						  y = name_y,
270 242
     						  just = name_just,
271 243
     	                      gp = check_gp(name_gp),
272
-<<<<<<< HEAD
273 244
     	                      rot = name_rot,
274 245
                               side = name_side)
275
-=======
276
-    	                      rot = name_rot)
277
->>>>>>> bioc/master
278 246
 
279 247
     gp = check_gp(gp)
280 248
     if(!is.null(gp$fill)) {
281 249
     	stop("You should not set `fill`.")
282 250
     }
283 251
 
284
-<<<<<<< HEAD
285
-=======
286
-    if(!missing(value)) {
287
-	    if(is.logical(value)) {
288
-	    	value = as.character(value)
289
-	    }
290
-	    if(is.factor(value)) {
291
-            value = as.vector(value)
292
-        }
293
-	}
294
-
295
->>>>>>> bioc/master
296 252
     if(missing(fun)) {
297 253
     	if(missing(col)) {
298 254
     		col = default_col(value)
299 255
     	}
300
-<<<<<<< HEAD
301
-=======
302
-        
303
->>>>>>> bioc/master
304 256
     	if(is.atomic(col)) {
305 257
     	    if(is.null(names(col))) {
306 258
                 if(is.factor(value)) {
... ...
@@ -328,7 +280,6 @@ SingleAnnotation = function(name, value, col, fun,
328 280
 	        .Object@fun = function(index) {
329 281
 	        	n = length(index)
330 282
 				x = (seq_len(n) - 0.5) / n
331
-<<<<<<< HEAD
332 283
                 if(is.matrix(value)) {
333 284
                     nc = ncol(value)
334 285
                     for(i in seq_len(nc)) {
... ...
@@ -339,17 +290,11 @@ SingleAnnotation = function(name, value, col, fun,
339 290
     				fill = map_to_colors(color_mapping, value[index])
340 291
     				grid.rect(x, y = 0.5, width = 1/n, height = 1, gp = do.call("gpar", c(list(fill = fill), gp)))
341 292
                 }
342
-=======
343
-				fill = map_to_colors(color_mapping, value[index])
344
-				#l = which(!is.na(value[index]))
345
-				grid.rect(x, y = 0.5, width = 1/n, height = 1, gp = do.call("gpar", c(list(fill = fill), gp)))
346
->>>>>>> bioc/master
347 293
 			}
348 294
 		} else {
349 295
 			.Object@fun = function(index, k = NULL, N = NULL) {
350 296
 				n = length(index)
351 297
 				y = (n - seq_len(n) + 0.5) / n
352
-<<<<<<< HEAD
353 298
                 if(is.matrix(value)) {
354 299
                     nc = ncol(value)
355 300
                     for(i in seq_len(nc)) {
... ...
@@ -360,11 +305,6 @@ SingleAnnotation = function(name, value, col, fun,
360 305
     				fill = map_to_colors(color_mapping, value[index])
361 306
     				grid.rect(x = 0.5, y, height = 1/n, width = 1, gp = do.call("gpar", c(list(fill = fill), gp)))
362 307
                 }
363
-=======
364
-				fill = map_to_colors(color_mapping, value[index])
365
-				#l = which(!is.na(value[index]))
366
-				grid.rect(x = 0.5, y, height = 1/n, width = 1, gp = do.call("gpar", c(list(fill = fill), gp)))
367
->>>>>>> bioc/master
368 308
 			}
369 309
 		}
370 310
 
... ...
@@ -407,11 +347,7 @@ SingleAnnotation = function(name, value, col, fun,
407 347
 # == param
408 348
 # -object a `SingleAnnotation-class` object.
409 349
 # -index a vector of orders
410
-<<<<<<< HEAD
411 350
 # -k if row annotation is splitted, the value identifies which row slice. It is only used for the names of the viewport
412
-=======
413
-# -k if row annotation is splitted, the value identifies which row slice. It is only used for the naems of the viewport
414
->>>>>>> bioc/master
415 351
 #    which contains the annotation graphics.
416 352
 # -n total number of row slices
417 353
 #
... ...
@@ -450,7 +386,6 @@ setMethod(f = "draw",
450 386
 	}
451 387
 	# add annotation name
452 388
 	if(object@name_param$show) {
453
-<<<<<<< HEAD
454 389
         draw_name = TRUE
455 390
         if(object@which == "row") {
456 391
             if(!is.null(k)) {
... ...
@@ -480,10 +415,6 @@ setMethod(f = "draw",
480 415
         			rot = object@name_param$rot, gp = object@name_param$gp)
481 416
             }
482 417
         }
483
-=======
484
-		grid.text(object@name, x = object@name_param$x, y = object@name_param$y, just = object@name_param$just, 
485
-			rot = object@name_param$rot, gp = object@name_param$gp)
486
->>>>>>> bioc/master
487 418
 	}
488 419
 	upViewport()
489 420
 
... ...
@@ -504,11 +435,7 @@ setMethod(f = "draw",
504 435
 setMethod(f = "show",
505 436
 	signature = "SingleAnnotation",
506 437
 	definition = function(object) {
507
-<<<<<<< HEAD
508 438
 	if(is_fun_annotation(object)) {
509
-=======
510
-	if(is.null(object@color_mapping)) {
511
->>>>>>> bioc/master
512 439
 		cat("An annotation with self-defined function\n")
513 440
 		cat("name:", object@name, "\n")
514 441
 		cat("position:", object@which, "\n")
... ...
@@ -517,7 +444,6 @@ setMethod(f = "show",
517 444
 		cat("name:", object@name, "\n")
518 445
 		cat("position:", object@which, "\n")
519 446
 		cat("show legend:", object@show_legend, "\n")
520
-<<<<<<< HEAD
521 447
         if(is_matrix_annotation(object)) {
522 448
             cat("a matrix with", attr(object@is_anno_matrix, "k"), "columns\n")
523 449
         }
... ...
@@ -536,7 +462,3 @@ is_matrix_annotation = function(single_anno) {
536 462
 is_fun_annotation = function(single_anno) {
537 463
     is.null(single_anno@color_mapping)
538 464
 }
539
-=======
540
-	}
541
-})
542
->>>>>>> bioc/master
... ...
@@ -1050,11 +1050,7 @@ column_anno_text = function(...) {
1050 1050
 # == param
1051 1051
 # -at numeric index in the original matrix
1052 1052
 # -labels corresponding labels
1053
-<<<<<<< HEAD
1054 1053
 # -which column annotation or row annotation
1055
-=======
1056
-# -which column annotaiton or row annotation
1057
->>>>>>> bioc/master
1058 1054
 # -side side of the labels. If it is a column annotation, permitted values are "top" and "bottom";
1059 1055
 #       If it is a row annotation, permitted values are "left" and "right".
1060 1056
 # -lines_gp graphic settings for the segments
... ...
@@ -1141,11 +1137,7 @@ anno_link = function(at, labels, which = c("column", "row"), side = ifelse(which
1141 1137
 					grid.segments(rep(link_width*(1/3), n2), n-i2+1, rep(link_width*(2/3), n2), h, default.units = "native", gp = lines_gp)
1142 1138
 					grid.segments(rep(link_width*(2/3), n2), h, rep(link_width, n2), h, default.units = "native", gp = lines_gp)
1143 1139
 				} else {
1144
-<<<<<<< HEAD
1145 1140
 					grid.text(labels, unit(1, "npc")-rep(link_width, n2), h, default.units = "native", gp = labels_gp, just = "right")
1146
-=======
1147
-					grid.text(labels, rep(link_width, n2), h, default.units = "native", gp = labels_gp, just = "right")
1148
->>>>>>> bioc/master
1149 1141
 					link_width = link_width - unit(1, "mm")
1150 1142
 					grid.segments(unit(rep(1, n2), "npc"), n-i2+1, unit(1, "npc")-rep(link_width*(1/3), n2), n-i2+1, default.units = "native", gp = lines_gp)
1151 1143
 					grid.segments(unit(1, "npc")-rep(link_width*(1/3), n2), n-i2+1, unit(1, "npc")-rep(link_width*(2/3), n2), h, default.units = "native", gp = lines_gp)
... ...
@@ -1237,7 +1229,6 @@ row_anno_link = function(...) {
1237 1229
 column_anno_link = function(...) {
1238 1230
 	anno_link(..., which = "column")
1239 1231
 }
1240
-<<<<<<< HEAD
1241 1232
 
1242 1233
 
1243 1234
 grid.xaxis = function(main = TRUE, at = NULL, label = NULL, gp = gpar()) {
... ...
@@ -1260,5 +1251,3 @@ grid.xaxis = function(main = TRUE, at = NULL, label = NULL, gp = gpar()) {
1260 1251
 		grid.text(label, at, unit(1, "npc") + unit(rep(1, n), "lines"), rot = 90, just = "left", gp = gp, default.units = "native")
1261 1252
 	}
1262 1253
 }
1263
-=======
1264
->>>>>>> bioc/master
... ...
@@ -44,14 +44,11 @@
44 44
 #
45 45
 decorate_heatmap_body = function(heatmap, code, slice = 1, envir = new.env(parent = parent.frame())) {
46 46
 
47
-<<<<<<< HEAD
48 47
 	current_vp = current.viewport()$name
49 48
 	if(current_vp == "ROOT") {
50 49
 		current_vp = "global"
51 50
 	}
52 51
 	
53
-=======
54
->>>>>>> bioc/master
55 52
 	if(is.null(slice)) {
56 53
 		vp_name = paste0(heatmap, "_heatmap_body_", 1)
57 54
 		seekViewport(vp_name)
... ...
@@ -63,11 +60,7 @@ decorate_heatmap_body = function(heatmap, code, slice = 1, envir = new.env(paren
63 60
 
64 61
 	eval(substitute(code), envir = envir)
65 62
 
66
-<<<<<<< HEAD
67 63
 	seekViewport(current_vp)
68
-=======
69
-	seekViewport("global")
70
->>>>>>> bioc/master
71 64
 }
72 65
 
73 66
 # == title
... ...
@@ -110,14 +103,11 @@ decorate_heatmap_body = function(heatmap, code, slice = 1, envir = new.env(paren
110 103
 decorate_dend = function(heatmap, code, slice = 1, which = c("column", "row"), 
111 104
 	envir = new.env(parent = parent.frame())) {
112 105
 	
113
-<<<<<<< HEAD
114 106
 	current_vp = current.viewport()$name
115 107
 	if(current_vp == "ROOT") {
116 108
 		current_vp = "global"
117 109
 	}
118 110
 
119
-=======
120
->>>>>>> bioc/master
121 111
 	which = match.arg(which)[1]
122 112
 	if(which == "column") {
123 113
 		vp_name = paste0(heatmap, "_dend_", which)
... ...
@@ -136,11 +126,7 @@ decorate_dend = function(heatmap, code, slice = 1, which = c("column", "row"),
136 126
 	e = new.env(parent = parent.frame())
137 127
 	eval(substitute(code), envir = e)
138 128
 
139
-<<<<<<< HEAD
140 129
 	seekViewport(current_vp)
141
-=======
142
-	seekViewport("global")
143
->>>>>>> bioc/master
144 130
 }
145 131
 
146 132
 # == title
... ...
@@ -236,14 +222,11 @@ decorate_row_dend = function(..., envir = new.env(parent = parent.frame())) {
236 222
 decorate_dimnames = function(heatmap, code, slice = 1, which = c("column", "row"), 
237 223
 	envir = new.env(parent = parent.frame())) {
238 224
 	
239
-<<<<<<< HEAD
240 225
 	current_vp = current.viewport()$name
241 226
 	if(current_vp == "ROOT") {
242 227
 		current_vp = "global"
243 228
 	}
244 229
 
245
-=======
246
->>>>>>> bioc/master
247 230
 	which = match.arg(which)[1]
248 231
 	if(which == "column") {
249 232
 		vp_name = paste0(heatmap, "_", which, "_names")
... ...
@@ -260,11 +243,7 @@ decorate_dimnames = function(heatmap, code, slice = 1, which = c("column", "row"
260 243
 
261 244
 	seekViewport(vp_name)
262 245
 	eval(substitute(code), envir = envir)
263
-<<<<<<< HEAD
264 246
 	seekViewport(current_vp)
265
-=======
266
-	seekViewport("global")
267
->>>>>>> bioc/master
268 247
 }
269 248
 
270 249
 # == title
... ...
@@ -348,14 +327,11 @@ decorate_column_names = function(..., envir = new.env(parent = parent.frame()))
348 327
 decorate_title = function(heatmap, code, slice = 1, which = c("column", "row"), 
349 328
 	envir = new.env(parent = parent.frame())) {
350 329
 	
351
-<<<<<<< HEAD
352 330
 	current_vp = current.viewport()$name
353 331
 	if(current_vp == "ROOT") {
354 332
 		current_vp = "global"
355 333
 	}
356 334
 
357
-=======
358
->>>>>>> bioc/master
359 335
 	which = match.arg(which)[1]
360 336
 	if(which == "column") {
361 337
 		vp_name = paste0(heatmap, "_", which, "_title")
... ...
@@ -372,11 +348,7 @@ decorate_title = function(heatmap, code, slice = 1, which = c("column", "row"),
372 348
 
373 349
 	seekViewport(vp_name)
374 350
 	eval(substitute(code), envir = envir)
375
-<<<<<<< HEAD
376 351
 	seekViewport(current_vp)
377
-=======
378
-	seekViewport("global")
379
->>>>>>> bioc/master
380 352
 }
381 353
 
382 354
 # == title
... ...
@@ -464,14 +436,11 @@ decorate_column_title = function(..., envir = new.env(parent = parent.frame()))
464 436
 #
465 437
 decorate_annotation = function(annotation, code, slice, envir = new.env(parent = parent.frame())) {
466 438
 
467
-<<<<<<< HEAD
468 439
 	current_vp = current.viewport()$name
469 440
 	if(current_vp == "ROOT") {
470 441
 		current_vp = "global"
471 442
 	}
472 443
 	
473
-=======
474
->>>>>>> bioc/master
475 444
 	if(missing(slice)) {
476 445
 		vp_name = paste0("annotation_", annotation)
477 446
 		o = try(seekViewport(vp_name), silent = TRUE)
... ...
@@ -496,10 +465,6 @@ decorate_annotation = function(annotation, code, slice, envir = new.env(parent =
496 465
 	}
497 466
 
498 467
 	eval(substitute(code), envir = envir)
499
-<<<<<<< HEAD
500 468
 	seekViewport(current_vp)
501
-=======
502
-	seekViewport("global")
503
->>>>>>> bioc/master
504 469
 }
505 470
 
... ...
@@ -5,10 +5,7 @@
5 5
 # == param
6 6
 # -data  a matrix or a list. If it is a matrix, density will be calculated by columns.
7 7
 # -col a list of colors that density values are mapped to.
8
-<<<<<<< HEAD
9 8
 # -density_param parameters send to `stats::density`, ``na.rm`` is enforced to ``TRUE``.
10
-=======
11
->>>>>>> bioc/master
12 9
 # -color_space the color space in which colors are interpolated. Pass to `circlize::colorRamp2`.
13 10
 # -anno annotation for the matrix columns or the list. The value should be a vector or a data frame 
14 11
 #       and colors for annotations are randomly assigned. If you want to customize the annotation colors,
... ...
@@ -37,12 +34,9 @@
37 34
 # in each column (or each vector in the list) through a heatmap. It is useful if you have huge number 
38 35
 # of columns in ``data`` to visualize.
39 36
 #
40
-<<<<<<< HEAD
41 37
 # The density matrix is generated with 500 rows ranging between the maximun and minimal values in all densities.
42 38
 # The density values in each row are linearly intepolated between the two density values at the two nearest bounds.
43 39
 #
44
-=======
45
->>>>>>> bioc/master
46 40
 # == value
47 41
 # No value is returned.
48 42
 #
... ...
@@ -64,10 +58,7 @@
64 58
 #
65 59
 densityHeatmap = function(data, 
66 60
 	col = rev(brewer.pal(11, "Spectral")),
67
-<<<<<<< HEAD
68 61
 	density_param = list(na.rm = TRUE),
69
-=======
70
->>>>>>> bioc/master
71 62
 	color_space = "LAB", 
72 63
 	anno = NULL, 
73 64
 	ylab = deparse(substitute(data)), 
... ...
@@ -88,7 +79,6 @@ densityHeatmap = function(data,
88 79
 	column_order = NULL,
89 80
 	...) {
90 81
 
91
-<<<<<<< HEAD
92 82
 	density_param$na.rm = TRUE
93 83
 
94 84
 	if(is.matrix(data)) {
... ...
@@ -97,14 +87,6 @@ densityHeatmap = function(data,
97 87
 		mean_value = apply(data, 2, mean, na.rm = TRUE)
98 88
 	} else if(is.data.frame(data) || is.list(data)) {
99 89
 		density_list = lapply(data, function(x) do.call(density, c(list(x = x), density_param)))
100
-=======
101
-	if(is.matrix(data)) {
102
-		density_list = apply(data, 2, density, na.rm = TRUE)
103
-		quantile_list = apply(data, 2, quantile, na.rm = TRUE)
104
-		mean_value = apply(data, 2, mean, na.rm = TRUE)
105
-	} else if(is.data.frame(data) || is.list(data)) {
106
-		density_list = lapply(data, density, na.rm = TRUE)
107
->>>>>>> bioc/master
108 90
 		quantile_list = sapply(data, quantile, na.rm = TRUE)
109 91
 		mean_value = sapply(data, mean, na.rm = TRUE)
110 92
 	} else {
... ...
@@ -16,10 +16,6 @@
16 16
 #                            Set it to ``NULL`` if you don't want to set the order
17 17
 # -column_order order of samples. By default the order is calculated by the 'memo sort' method which can visualize
18 18
 #                                 the mutual exclusivity across genes. Set it to ``NULL`` if you don't want to set the order
19
-<<<<<<< HEAD
20
-=======
21
-# -show_column_names whether show column names
22
->>>>>>> bioc/master
23 19
 # -show_pct whether show percent values on the left of the oncoprint
24 20
 # -pct_gp graphic paramters for percent row annotation
25 21
 # -pct_digits digits for percent values
... ...
@@ -29,7 +25,6 @@
29 25
 # -remove_empty_columns if there is no alteration in that sample, whether remove it on the heatmap
30 26
 # -heatmap_legend_param pass to `Heatmap`
31 27
 # -top_annotation by default the top annotation contains barplots representing frequency of mutations in every sample.
32
-<<<<<<< HEAD
33 28
 # -top_annotation_height total height of the column annotations on the top.
34 29
 # -bottom_annotation a `HeatmapAnnotation` object.
35 30
 # -bottom_annotation_height total height of the column annotations on the bottom.
... ...
@@ -55,10 +50,6 @@
55 50
 #                 The input parameter for this function is a vector which contains level names under each column in ``split``.
56 51
 # -width the width of the single heatmap, should be a fixed `grid::unit` object. It is used for the layout when the heatmap
57 52
 #        is appended to a list of heatmaps.
58
-=======
59
-# -barplot_ignore specific alterations that you don't want to put on the barplots. If you want to really suppress the top barplot
60
-#        set ``top_annotation`` to ``NULL``.
61
->>>>>>> bioc/master
62 53
 # -... pass to `Heatmap`, so can set ``bottom_annotation`` here.
63 54
 #
64 55
 # == details
... ...
@@ -82,12 +73,7 @@ oncoPrint = function(mat, get_type = function(x) x,
82 73
 	alter_fun = alter_fun_list, alter_fun_list = NULL, col, 
83 74
 	row_order = oncoprint_row_order(),
84 75
 	column_order = oncoprint_column_order(),
85
-<<<<<<< HEAD
86 76
 	show_pct = TRUE, pct_gp = row_names_gp, pct_digits = 0,
87
-=======
88
-	show_column_names = FALSE,
89
-	show_pct = TRUE, pct_gp = gpar(), pct_digits = 0,
90
->>>>>>> bioc/master
91 77
 	axis_gp = gpar(fontsize = 8), 
92 78
 	show_row_barplot = TRUE, 
93 79
 	row_barplot_width = unit(2, "cm"),
... ...
@@ -95,7 +81,6 @@ oncoPrint = function(mat, get_type = function(x) x,
95 81
 	heatmap_legend_param = list(title = "Alterations"),
96 82
 	top_annotation = HeatmapAnnotation(column_bar = anno_oncoprint_barplot(), 
97 83
 		annotation_height = unit(2, "cm")),
98
-<<<<<<< HEAD
99 84
 	top_annotation_height = top_annotation@size,
100 85
 	bottom_annotation = new("HeatmapAnnotation"),
101 86
     bottom_annotation_height = bottom_annotation@size,
... ...
@@ -116,9 +101,6 @@ oncoPrint = function(mat, get_type = function(x) x,
116 101
     gap = unit(1, "mm"),
117 102
     combined_name_fun = function(x) paste(x, collapse = "/"),
118 103
     width = NULL,
119
-=======
120
-	barplot_ignore = NULL,
121
->>>>>>> bioc/master
122 104
 	...) {
123 105
 
124 106
 	if(length(names(list(...))) > 0) {
... ...
@@ -340,7 +322,6 @@ oncoPrint = function(mat, get_type = function(x) x,
340 322
 			z = arr[i, j, ]
341 323
 			names(z) = dimnames(arr)[[3]]
342 324
 			af(x, y, width, height, z)
343
-<<<<<<< HEAD
344 325
 		},
345 326
 		top_annotation = top_annotation,
346 327
 		top_annotation_height = top_annotation_height,
... ...
@@ -364,11 +345,6 @@ oncoPrint = function(mat, get_type = function(x) x,
364 345
 		combined_name_fun = combined_name_fun,
365 346
 		width = width,
366 347
 		...)
367
-=======
368
-		}, show_column_names = show_column_names,
369
-		top_annotation = top_annotation,
370
-		heatmap_legend_param = heatmap_legend_param, ...)
371
->>>>>>> bioc/master
372 348
 
373 349
 	ht@matrix_param$oncoprint = list()
374 350
 	ht@matrix_param$oncoprint$arr = arr
... ...
@@ -424,11 +400,7 @@ unify_mat_list = function(mat_list, default = 0) {
424 400
 
425 401
 
426 402
 # == title
427
-<<<<<<< HEAD
428 403
 # Column barplot annotation for oncoPrint
429
-=======
430
-# Column barplot annotaiton for oncoPrint
431
->>>>>>> bioc/master
432 404
 #
433 405
 # == details
434 406
 # This function is only used for column annotation
... ...
@@ -2,16 +2,12 @@
2 2
 # environment that contains global variables
3 3
 INDEX_ENV = new.env()
4 4
 
5
-<<<<<<< HEAD
6 5
 INDEX_ENV$I_FIGURE = 0
7
-=======
8
->>>>>>> bioc/master
9 6
 INDEX_ENV$I_HEATMAP = 0
10 7
 INDEX_ENV$I_ANNOTATION = 0
11 8
 INDEX_ENV$I_ROW_ANNOTATION = 0
12 9
 INDEX_ENV$I_COLOR_MAPPING = 0
13 10
 
14
-<<<<<<< HEAD
15 11
 get_figure_index = function() {
16 12
     INDEX_ENV$I_FIGURE
17 13
 }
... ...
@@ -20,8 +16,6 @@ increase_figure_index = function() {
20 16
     INDEX_ENV$I_FIGURE = INDEX_ENV$I_FIGURE + 1
21 17
 }
22 18
 
23
-=======
24
->>>>>>> bioc/master
25 19
 get_heatmap_index = function() {
26 20
 	INDEX_ENV$I_HEATMAP
27 21
 }
... ...
@@ -72,12 +66,8 @@ default_col = function(x, main_matrix = FALSE) {
72 66
 
73 67
     if(is.character(x)) {  # discrete
74 68
         levels = unique(x)
75
-<<<<<<< HEAD
76 69
         #colors = hsv(runif(length(levels)), 1-runif(1)/2, 1-runif(1)/2)
77 70
         colors = rand_color(length(levels), luminosity = sample(c("bright", "light", "dark", "random"), 1))
78
-=======
79
-        colors = hsv(runif(length(levels)), 1-runif(1)/2, 1-runif(1)/2)
80
->>>>>>> bioc/master
81 71
         names(colors) = levels
82 72
         return(colors)
83 73
     } else if(is.numeric(x)) {
... ...
@@ -88,12 +78,8 @@ default_col = function(x, main_matrix = FALSE) {
88 78
                 col_fun = colorRamp2(seq(min(x), max(x), length = 3), c("blue", "#EEEEEE", "red"))
89 79
             }
90 80
         } else {
91
-<<<<<<< HEAD
92 81
             #col_fun = colorRamp2(range(min(x), max(x)), c("white", hsv(runif(1), 1, 1)))
93 82
             col_fun = colorRamp2(range(min(x), max(x)), c("white", rand_color(1, luminosity = sample(c("bright", "dark"), 1))))
94
-=======
95
-            col_fun = colorRamp2(range(min(x), max(x)), c("white", hsv(runif(1), 1, 1)))
96
->>>>>>> bioc/master
97 83
         }
98 84
         return(col_fun)
99 85
     }
... ...
@@ -147,11 +133,6 @@ grid.dendrogram = function(dend, facing = c("bottom", "top", "left", "right"),
147 133
             leaf
148 134
         }
149 135
     }
150
-<<<<<<< HEAD
151
-=======
152
-
153
-    labels(dend) = paste0("leaf_", seq_len(nnodes(dend)))
154
->>>>>>> bioc/master
155 136
     
156 137
     draw.d = function(dend, max_height, facing = "bottom", order = "normal", max_width = 0, env = NULL) {
157 138
         leaf = attr(dend, "leaf")
... ...
@@ -302,7 +283,6 @@ grid.dendrogram = function(dend, facing = c("bottom", "top", "left", "right"),
302 283
 }
303 284
 
304 285
 # == title
305
-<<<<<<< HEAD
306 286
 # Adjust dendrogram based on width of leaves
307 287
 #
308 288
 # == param
... ...
@@ -584,8 +564,6 @@ grid.dendrogram2 = function(dend, facing = c("bottom", "top", "left", "right"),
584 564
 }
585 565
 
586 566
 # == title
587
-=======
588
->>>>>>> bioc/master
589 567
 # Calculate pairwise distance from a matrix
590 568
 #
591 569
 # == param
... ...
@@ -676,17 +654,12 @@ get_dend_order = function(x) {
676 654
 
677 655
 # can only cut dendrogram for which branches at every node are two
678 656
 cut_dendrogram = function(dend, k) {
679
-<<<<<<< HEAD
680 657
     h = sort(dend_branches_heights(dend), decreasing = TRUE)
681
-=======
682
-    h = sort(get_branches_heights(dend), decreasing = TRUE)
683
->>>>>>> bioc/master
684 658
     height = (h[k-1] + h[k])/2
685 659
     trees = cut(dend, h = height)
686 660
     trees$lower
687 661
 }
688 662
 
689
-<<<<<<< HEAD
690 663
 dend_branches_heights = function(d, v = NULL) {
691 664
     if(!is.leaf(d)) {
692 665
         v = c(v, attr(d, "height"))
... ...
@@ -696,8 +669,6 @@ dend_branches_heights = function(d, v = NULL) {
696 669
     return(v)
697 670
 }
698 671
 
699
-=======
700
->>>>>>> bioc/master
701 672
 recycle_gp = function(gp, n = 1) {
702 673
     for(i in seq_along(gp)) {
703 674
         x = gp[[i]]
... ...
@@ -818,12 +789,9 @@ list_component = f