Browse code

update

Zuguang Gu authored on 09/10/2018 10:30:53
Showing9 changed files

... ...
@@ -333,14 +333,14 @@ Heatmap = function(matrix, col, name,
333 333
     }
334 334
 
335 335
     if("heatmap_legend_param" %in% called_args) {
336
-        for(opt_name in setdiff(c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "grid_border"), names(heatmap_legend_param))) {
336
+        for(opt_name in setdiff(c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "border"), names(heatmap_legend_param))) {
337 337
             opt_name2 = paste0("legend_", opt_name)
338 338
             if(!is.null(ht_opt(opt_name2)))
339 339
                 if(verbose) qqcat("re-assign heatmap_legend_param$@{opt_name} with `ht_opt('@{opt_name2}'')`\n")
340 340
                 heatmap_legend_param[[opt_name]] = ht_opt(opt_name2)
341 341
         }
342 342
     } else {
343
-        for(opt_name in c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "grid_border")) {
343
+        for(opt_name in c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "border")) {
344 344
             opt_name2 = paste0("legend_", opt_name)
345 345
             if(!is.null(ht_opt(opt_name2)))
346 346
                 if(verbose) qqcat("re-assign heatmap_legend_param$@{opt_name} with `ht_opt('@{opt_name2}'')`\n")
... ...
@@ -477,6 +477,9 @@ Heatmap = function(matrix, col, name,
477 477
 
478 478
     ### parameters for heatmap body ###
479 479
     .Object@matrix_param$gp = check_gp(rect_gp)
480
+    if(missing(border)) {
481
+        if(!is.null(ht_opt$heatmap_border)) border = ht_opt$heatmap_border
482
+    }
480 483
     if(identical(border, TRUE)) border = "black"
481 484
     .Object@matrix_param$border = border
482 485
     .Object@matrix_param$cell_fun = cell_fun
... ...
@@ -600,7 +603,7 @@ Heatmap = function(matrix, col, name,
600 603
     .Object@row_dend_param$distance = clustering_distance_rows
601 604
     .Object@row_dend_param$method = clustering_method_rows
602 605
     .Object@row_dend_param$side = match.arg(row_dend_side)[1]
603
-    .Object@row_dend_param$width = row_dend_width + DENDROGRAM_PADDING  # append the gap
606
+    .Object@row_dend_param$width = row_dend_width + ht_opt$DENDROGRAM_PADDING  # append the gap
604 607
     .Object@row_dend_param$show = show_row_dend
605 608
     .Object@row_dend_param$gp = check_gp(row_dend_gp)
606 609
     .Object@row_dend_param$reorder = row_dend_reorder
... ...
@@ -637,7 +640,7 @@ Heatmap = function(matrix, col, name,
637 640
     .Object@column_dend_param$distance = clustering_distance_columns
638 641
     .Object@column_dend_param$method = clustering_method_columns
639 642
     .Object@column_dend_param$side = match.arg(column_dend_side)[1]
640
-    .Object@column_dend_param$height = column_dend_height + DENDROGRAM_PADDING  # append the gap
643
+    .Object@column_dend_param$height = column_dend_height + ht_opt$DENDROGRAM_PADDING  # append the gap
641 644
     .Object@column_dend_param$show = show_column_dend
642 645
     .Object@column_dend_param$gp = check_gp(column_dend_gp)
643 646
     .Object@column_dend_param$reorder = column_dend_reorder
... ...
@@ -655,7 +658,7 @@ Heatmap = function(matrix, col, name,
655 658
     if(is.null(top_annotation)) {
656 659
         .Object@top_annotation_param$height = unit(0, "mm")    
657 660
     } else {
658
-        .Object@top_annotation_param$height = height(top_annotation) + COLUMN_ANNO_PADDING  # append the gap
661
+        .Object@top_annotation_param$height = height(top_annotation) + ht_opt$COLUMN_ANNO_PADDING  # append the gap
659 662
     }
660 663
     if(!is.null(top_annotation)) {
661 664
         if(length(top_annotation) > 0) {
... ...
@@ -675,7 +678,7 @@ Heatmap = function(matrix, col, name,
675 678
     if(is.null(bottom_annotation)) {
676 679
         .Object@bottom_annotation_param$height = unit(0, "mm")
677 680
     } else {
678
-        .Object@bottom_annotation_param$height = height(bottom_annotation) + COLUMN_ANNO_PADDING  # append the gap
681
+        .Object@bottom_annotation_param$height = height(bottom_annotation) + ht_opt$COLUMN_ANNO_PADDING  # append the gap
679 682
     }
680 683
     if(!is.null(bottom_annotation)) {
681 684
         if(length(bottom_annotation) > 0) {
... ...
@@ -695,7 +698,7 @@ Heatmap = function(matrix, col, name,
695 698
     if(is.null(left_annotation)) {
696 699
         .Object@left_annotation_param$width = unit(0, "mm")
697 700
     } else {
698
-        .Object@left_annotation_param$width = width(left_annotation) + ROW_ANNO_PADDING  # append the gap
701
+        .Object@left_annotation_param$width = width(left_annotation) + ht_opt$ROW_ANNO_PADDING  # append the gap
699 702
     }
700 703
     if(!is.null(left_annotation)) {
701 704
         if(length(left_annotation) > 0) {
... ...
@@ -715,7 +718,7 @@ Heatmap = function(matrix, col, name,
715 718
     if(is.null(right_annotation)) {
716 719
         .Object@right_annotation_param$width = unit(0, "mm")
717 720
     } else {
718
-        .Object@right_annotation_param$width = width(right_annotation) + ROW_ANNO_PADDING  # append the gap
721
+        .Object@right_annotation_param$width = width(right_annotation) + ht_opt$ROW_ANNO_PADDING  # append the gap
719 722
     }
720 723
     if(!is.null(right_annotation)) {
721 724
         if(length(right_annotation) > 0) {
... ...
@@ -92,16 +92,16 @@ setMethod(f = "make_layout",
92 92
     if(length(column_title) > 0) {
93 93
         if(column_title_side == "top") {
94 94
             if(column_title_rot %in% c(0, 180)) {
95
-                object@layout$layout_size$column_title_top_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + TITLE_PADDING*2
95
+                object@layout$layout_size$column_title_top_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + ht_opt$TITLE_PADDING*2
96 96
             } else {
97
-                object@layout$layout_size$column_title_top_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + TITLE_PADDING*2
97
+                object@layout$layout_size$column_title_top_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + ht_opt$TITLE_PADDING*2
98 98
             }
99 99
             object@layout$layout_index = rbind(object@layout$layout_index, column_title_top = heatmap_layout_index("column_title_top"))
100 100
         } else {
101 101
             if(column_title_rot %in% c(0, 180)) {
102
-                object@layout$layout_size$column_title_bottom_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + TITLE_PADDING*2
102
+                object@layout$layout_size$column_title_bottom_height = grobHeight(textGrob(column_title, gp = column_title_gp)) + ht_opt$TITLE_PADDING*2
103 103
             } else {
104
-                object@layout$layout_size$column_title_bottom_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + TITLE_PADDING*2
104
+                object@layout$layout_size$column_title_bottom_height = grobWidth(textGrob(column_title, gp = column_title_gp)) + ht_opt$TITLE_PADDING*2
105 105
             }
106 106
             object@layout$layout_index = rbind(object@layout$layout_index, column_title_bottom = heatmap_layout_index("column_title_bottom"))
107 107
         }
... ...
@@ -125,16 +125,16 @@ setMethod(f = "make_layout",
125 125
     if(length(row_title) > 0) {
126 126
         if(row_title_side == "left") {
127 127
             if(row_title_rot %in% c(0, 180)) {
128
-                object@layout$layout_size$row_title_left_width = max_text_width(row_title, gp = row_title_gp) + TITLE_PADDING*2
128
+                object@layout$layout_size$row_title_left_width = max_text_width(row_title, gp = row_title_gp) + ht_opt$TITLE_PADDING*2
129 129
             } else {
130
-                object@layout$layout_size$row_title_left_width = max_text_height(row_title, gp = row_title_gp) + TITLE_PADDING*2
130
+                object@layout$layout_size$row_title_left_width = max_text_height(row_title, gp = row_title_gp) + ht_opt$TITLE_PADDING*2
131 131
             }
132 132
             object@layout$layout_index = rbind(object@layout$layout_index, row_title_left = heatmap_layout_index("row_title_left"))
133 133
         } else {
134 134
             if(row_title_rot %in% c(0, 180)) {
135
-                object@layout$layout_size$row_title_right_width = max_text_width(row_title, gp = row_title_gp) + TITLE_PADDING*2
135
+                object@layout$layout_size$row_title_right_width = max_text_width(row_title, gp = row_title_gp) + ht_opt$TITLE_PADDING*2
136 136
             } else {
137
-                object@layout$layout_size$row_title_right_width = max_text_height(row_title, gp = row_title_gp) + TITLE_PADDING*2
137
+                object@layout$layout_size$row_title_right_width = max_text_height(row_title, gp = row_title_gp) + ht_opt$TITLE_PADDING*2
138 138
             }
139 139
             object@layout$layout_index = rbind(object@layout$layout_index, row_title_right = heatmap_layout_index("row_title_right"))
140 140
         }
... ...
@@ -167,9 +167,9 @@ setMethod(f = "make_layout",
167 167
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
168 168
             
169 169
             if(row_dend_side == "left") {
170
-                pushViewport(viewport(x = unit(0, "npc"), width = unit(1, "npc") - DENDROGRAM_PADDING, just = "left"))
170
+                pushViewport(viewport(x = unit(0, "npc"), width = unit(1, "npc") - ht_opt$DENDROGRAM_PADDING, just = "left"))
171 171
             } else {
172
-                pushViewport(viewport(x = DENDROGRAM_PADDING, width = unit(1, "npc") - DENDROGRAM_PADDING, just = "left"))
172
+                pushViewport(viewport(x = ht_opt$DENDROGRAM_PADDING, width = unit(1, "npc") - ht_opt$DENDROGRAM_PADDING, just = "left"))
173 173
             }
174 174
             for(i in seq_len(nr_slice)) {
175 175
                 draw_dend(object, k = i, which = "row", y = slice_y[i], height = slice_height[i], just = "top",
... ...
@@ -218,9 +218,9 @@ setMethod(f = "make_layout",
218 218
         column_dend_max_height = dend_heights(column_dend_slice) + max(dend_heights(object@column_dend_list))
219 219
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
220 220
             if(column_dend_side == "top") {
221
-                pushViewport(viewport(y = DENDROGRAM_PADDING, height = unit(1, "npc") - DENDROGRAM_PADDING, just = "bottom"))
221
+                pushViewport(viewport(y = ht_opt$DENDROGRAM_PADDING, height = unit(1, "npc") - ht_opt$DENDROGRAM_PADDING, just = "bottom"))
222 222
             } else {
223
-                pushViewport(viewport(y = unit(0, "npc"), height = unit(1, "npc") - DENDROGRAM_PADDING, just = "bottom"))
223
+                pushViewport(viewport(y = unit(0, "npc"), height = unit(1, "npc") - ht_opt$DENDROGRAM_PADDING, just = "bottom"))
224 224
             }
225 225
             for(i in seq_len(nc_slice)) {
226 226
                 draw_dend(object, k = i, which = "column", x = slice_x[i], width = slice_width[i], just = "left",
... ...
@@ -258,7 +258,7 @@ setMethod(f = "make_layout",
258 258
     show_row_names = object@row_names_param$show
259 259
     row_names_anno = object@row_names_param$anno
260 260
     if(show_row_names) {
261
-        row_names_width = row_names_anno@width + DIMNAME_PADDING*2
261
+        row_names_width = row_names_anno@width + ht_opt$DIMNAME_PADDING*2
262 262
         row_names_width = min(row_names_width, object@row_names_param$max_width)
263 263
         if(row_names_side == "left") {
264 264
             object@layout$layout_size$row_names_left_width = row_names_width
... ...
@@ -270,7 +270,7 @@ setMethod(f = "make_layout",
270 270
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
271 271
             for(i in seq_len(nr_slice)) {
272 272
                 draw_dimnames(object, k = i, which = "row", y = slice_y[i], 
273
-                    height = slice_height[i], width = unit(1, "npc") - DIMNAME_PADDING*2, just = "top")
273
+                    height = slice_height[i], width = unit(1, "npc") - ht_opt$DIMNAME_PADDING*2, just = "top")
274 274
             }
275 275
         })
276 276
     }
... ...
@@ -281,7 +281,7 @@ setMethod(f = "make_layout",
281 281
     show_column_names = object@column_names_param$show
282 282
     column_names_anno = object@column_names_param$anno
283 283
     if(show_column_names) {
284
-        column_names_height = column_names_anno@height + DIMNAME_PADDING*2
284
+        column_names_height = column_names_anno@height + ht_opt$DIMNAME_PADDING*2
285 285
         column_names_height = min(column_names_height, object@column_names_param$max_height)
286 286
         if(column_names_side == "top") {
287 287
             object@layout$layout_size$column_names_top_height = column_names_height
... ...
@@ -293,7 +293,7 @@ setMethod(f = "make_layout",
293 293
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
294 294
             for(i in seq_len(nc_slice)) {
295 295
                 draw_dimnames(object, k = i, which = "column", x = slice_x[i], 
296
-                    width = slice_width[i], height = unit(1, "npc") - DIMNAME_PADDING*2, just = "left")
296
+                    width = slice_width[i], height = unit(1, "npc") - ht_opt$DIMNAME_PADDING*2, just = "left")
297 297
             }
298 298
         })
299 299
     }
... ...
@@ -310,7 +310,7 @@ setMethod(f = "make_layout",
310 310
             object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
311 311
                 for(i in seq_len(nc_slice)) {
312 312
                     draw_annotation(object, k = i, which = "top", x = slice_x[i], width = slice_width[i], 
313
-                        y = COLUMN_ANNO_PADDING, height = unit(1, "npc") - COLUMN_ANNO_PADDING, 
313
+                        y = ht_opt$COLUMN_ANNO_PADDING, height = unit(1, "npc") - ht_opt$COLUMN_ANNO_PADDING, 
314 314
                         just = c("left", "bottom"))
315 315
                 }
316 316
             }) 
... ...
@@ -328,7 +328,7 @@ setMethod(f = "make_layout",
328 328
             object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
329 329
                 for(i in seq_len(nc_slice)) {
330 330
                     draw_annotation(object, k = i, which = "bottom", x = slice_x[i], width = slice_width[i], 
331
-                        y = unit(0, "npc"), height = unit(1, "npc") - COLUMN_ANNO_PADDING, 
331
+                        y = unit(0, "npc"), height = unit(1, "npc") - ht_opt$COLUMN_ANNO_PADDING, 
332 332
                         just = c("left", "bottom"))
333 333
                 }
334 334
             })
... ...
@@ -346,7 +346,7 @@ setMethod(f = "make_layout",
346 346
             object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
347 347
                     for(i in seq_len(nr_slice)) {
348 348
                         draw_annotation(object, k = i, which = "left",  y = slice_y[i], height = slice_height[i], 
349
-                            x = unit(0, "npc"), width = unit(1, "npc") - ROW_ANNO_PADDING, 
349
+                            x = unit(0, "npc"), width = unit(1, "npc") - ht_opt$ROW_ANNO_PADDING, 
350 350
                             just = c("left", "top"))
351 351
                     }
352 352
                 }
... ...
@@ -365,7 +365,7 @@ setMethod(f = "make_layout",
365 365
             object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
366 366
                 for(i in seq_len(nr_slice)) {
367 367
                     draw_annotation(object, k = i, which = "right", y = slice_y[i], height = slice_height[i], 
368
-                        x = ROW_ANNO_PADDING, width = unit(1, "npc") - ROW_ANNO_PADDING, 
368
+                        x = ht_opt$ROW_ANNO_PADDING, width = unit(1, "npc") - ht_opt$ROW_ANNO_PADDING, 
369 369
                         just = c("left", "top"))
370 370
                 }
371 371
             })
... ...
@@ -223,6 +223,9 @@ HeatmapAnnotation = function(...,
223 223
     annotation_name_offset = recycle_param(annotation_name_offset, an, TRUE)
224 224
     annotation_name_side = recycle_param(annotation_name_side, an, TRUE)
225 225
     annotation_name_rot = recycle_param(annotation_name_rot, an, TRUE)
226
+    if(missing(border)) {
227
+    	if(!is.null(ht_opt$annotation_border)) border = ht_opt$annotation_border
228
+    }
226 229
     border = recycle_param(border, an, FALSE)
227 230
     annotation_name_gp = recycle_gp(annotation_name_gp, n_total_anno)
228 231
 
... ...
@@ -355,12 +355,42 @@ setMethod(f = "draw",
355 355
     legend_labels_gp = NULL,
356 356
     legend_grid_height = NULL,
357 357
     legend_grid_width = NULL,
358
-    legend_grid_border = NULL,
358
+    legend_border = NULL,
359
+    heatmap_border = NULL,
360
+    annotation_border = NULL,
359 361
     fastcluster = NULL,
360
-    show_vp_border = NULL,
361
-    anno_simple_row_size = NULL
362
+    anno_simple_size = NULL
362 363
     ) {
363 364
 
365
+    verbose = ht_opt$verbose
366
+
367
+    ovl = list()
368
+    for(opt_nm in c("heatmap_row_names_gp",
369
+                    "heatmap_column_names_gp",
370
+                    "heatmap_row_title_gp",
371
+                    "heatmap_column_title_gp",
372
+                    "legend_title_gp",
373
+                    "legend_title_position",
374
+                    "legend_labels_gp",
375
+                    "legend_grid_height",
376
+                    "legend_grid_width",
377
+                    "legend_border",
378
+                    "heatmap_border",
379
+                    "annotation_border",
380
+                    "fastcluster",
381
+                    "anno_simple_size")) {
382
+        v = get(opt_nm, inherits = FALSE)
383
+        if(!is.null(v)) {
384
+            ovl[[opt_nm]] = ht_opt[[opt_nm]]
385
+            ht_opt[[opt_nm]] = v
386
+
387
+            if(verbose) qqcat("temporarily set the global parameter @{opt_nm}\n")
388
+        }
389
+    }
390
+    if(length(ovl)) {
391
+        on.exit(ht_opt(ovl))
392
+    }
393
+
364 394
     direction = object@direction
365 395
 
366 396
     l = sapply(object@ht_list, inherits, "Heatmap")
... ...
@@ -449,65 +479,9 @@ setMethod(f = "draw",
449 479
         heatmap_body_width = heatmap_body_width
450 480
     )
451 481
 
452
-    verbose = ht_opt$verbose
453
-
454
-    ovl = list()
455
-    for(opt_nm in c("heatmap_row_names_gp",
456
-                    "heatmap_column_names_gp",
457
-                    "heatmap_row_title_gp",
458
-                    "heatmap_column_title_gp",
459
-                    "legend_title_gp",
460
-                    "legend_title_position",
461
-                    "legend_labels_gp",
462
-                    "legend_grid_height",
463
-                    "legend_grid_width",
464
-                    "legend_grid_border",
465
-                    "fastcluster",
466
-                    "show_vp_border",
467
-                    "anno_simple_row_size")) {
468
-        v = get(opt_nm, inherits = FALSE)
469
-        if(!is.null(v)) {
470
-            ovl[[opt_nm]] = ht_opt[[opt_nm]]
471
-            ht_opt[[opt_nm]] = v
472
-
473
-            if(verbose) qqcat("temporarily set the global parameter @{opt_nm}\n")
474
-        }
475
-    }
476
-    if(length(ovl)) {
477
-        on.exit(ht_opt(ovl))
478
-    }
479
-
480 482
     # calculate proper padding
481 483
     if(is.null(padding)) {
482 484
         padding = GLOBAL_PADDING
483
-        # if(!has_heatmap_list_component(object, "heatmap_legend_bottom") && 
484
-        #    !has_heatmap_list_component(object, "annotation_legend_bottom") &&
485
-        #    !has_heatmap_list_component(object, "column_title_bottom")) {
486
-        #     if(object@layout$row_anno_max_bottom_extended[[1]] > object@layout$max_bottom_component_height[[1]]) {
487
-        #         padding[1] = object@layout$row_anno_max_bottom_extended - object@layout$max_bottom_component_height + GLOBAL_PADDING[1]
488
-        #     }
489
-        # }
490
-        # if(!has_heatmap_list_component(object, "heatmap_legend_left") && 
491
-        #    !has_heatmap_list_component(object, "annotation_legend_left") &&
492
-        #    !has_heatmap_list_component(object, "row_title_left")) {
493
-        #     if(object@layout$column_anno_max_left_extended[[1]] > object@layout$max_left_component_width[[1]]) {
494
-        #         padding[2] = object@layout$column_anno_max_left_extended - object@layout$max_left_component_width + GLOBAL_PADDING[2]
495
-        #     }
496
-        # }
497
-        # if(!has_heatmap_list_component(object, "heatmap_legend_top") && 
498
-        #    !has_heatmap_list_component(object, "annotation_legend_top") &&
499
-        #    !has_heatmap_list_component(object, "column_title_top")) {
500
-        #     if(object@layout$row_anno_max_top_extended[[1]] > object@layout$max_top_component_height[[1]]) {
501
-        #         padding[3] = object@layout$row_anno_max_top_extended - object@layout$max_top_component_height + GLOBAL_PADDING[3]
502
-        #     }
503
-        # }
504
-        # if(!has_heatmap_list_component(object, "heatmap_legend_right") && 
505
-        #    !has_heatmap_list_component(object, "annotation_legend_right") &&
506
-        #    !has_heatmap_list_component(object, "row_title_right")) {
507
-        #     if(object@layout$column_anno_max_right_extended[[1]] > object@layout$max_right_component_width[[1]]) {
508
-        #         padding[4] = object@layout$column_anno_max_right_extended - object@layout$max_right_component_width + GLOBAL_PADDING[4]
509
-        #     }
510
-        # }
511 485
         object@ht_list_param$padding = padding
512 486
     }
513 487
 
... ...
@@ -23,20 +23,20 @@ setMethod(f = "adjust_heatmap_list",
23 23
     if(direction == "horizontal") {
24 24
 
25 25
         # adjust top anntatation, top annotation of all heatmaps should be aligned
26
-        max_top_anno_height = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_height(ht, "column_anno_top")))) - COLUMN_ANNO_PADDING
26
+        max_top_anno_height = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_height(ht, "column_anno_top")))) - ht_opt$COLUMN_ANNO_PADDING
27 27
         max_top_anno_height = convertHeight(max_top_anno_height, "mm")
28
-        max_bottom_anno_height = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_height(ht, "column_anno_bottom")))) - COLUMN_ANNO_PADDING
28
+        max_bottom_anno_height = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_height(ht, "column_anno_bottom")))) - ht_opt$COLUMN_ANNO_PADDING
29 29
         max_bottom_anno_height = convertHeight(max_bottom_anno_height, "mm")
30 30
         for(i in ht_index) {
31 31
             if(has_component(object@ht_list[[i]], "column_anno_top")) {
32 32
                 if(verbose) qqcat("adjust height of top annotation of heamtap @{object@ht_list[[i]]@name}\n")
33 33
                 object@ht_list[[i]]@top_annotation = resize(object@ht_list[[i]]@top_annotation, height = max_top_anno_height)
34
-                object@ht_list[[i]] = set_component_height(object@ht_list[[i]], "column_anno_top", object@ht_list[[i]]@top_annotation@height + COLUMN_ANNO_PADDING)
34
+                object@ht_list[[i]] = set_component_height(object@ht_list[[i]], "column_anno_top", object@ht_list[[i]]@top_annotation@height + ht_opt$COLUMN_ANNO_PADDING)
35 35
             }
36 36
             if(has_component(object@ht_list[[i]], "column_anno_bottom")) {   
37 37
                 if(verbose) qqcat("adjust height of bottom annotation of heamtap @{object@ht_list[[i]]@name}\n")
38 38
                 object@ht_list[[i]]@bottom_annotation = resize(object@ht_list[[i]]@bottom_annotation, height = max_bottom_anno_height)
39
-                object@ht_list[[i]] = set_component_height(object@ht_list[[i]], "column_anno_bottom", object@ht_list[[i]]@bottom_annotation@height + COLUMN_ANNO_PADDING)
39
+                object@ht_list[[i]] = set_component_height(object@ht_list[[i]], "column_anno_bottom", object@ht_list[[i]]@bottom_annotation@height + ht_opt$COLUMN_ANNO_PADDING)
40 40
             }
41 41
         }
42 42
 
... ...
@@ -138,7 +138,7 @@ setMethod(f = "adjust_heatmap_list",
138 138
         object@layout$max_bottom_component_height = max_bottom_component_height
139 139
 
140 140
         # and calcualte proper paddings
141
-        if(is.null(object@ht_list_param$padding)) {
141
+        if(TRUE) {
142 142
             object@ht_list_param$padding = GLOBAL_PADDING
143 143
             row_anno_max_top_extended = max(do.call("unit.c", lapply(object@ht_list, function(ht) {
144 144
                 if(inherits(ht, "HeatmapAnnotation")) {
... ...
@@ -188,7 +188,7 @@ setMethod(f = "adjust_heatmap_list",
188 188
             max_left_component_width = unit(0, "mm")
189 189
             if(inherits(object@ht_list[[1]], "Heatmap")) {
190 190
                 ht_first = object@ht_list[[1]]
191
-                max_left_component_width = sum(component_width(ht_first, c("row_title_left", "row_dend_left", "row_anno_left")))
191
+                max_left_component_width = sum(component_width(ht_first, c("row_names_left", "row_dend_left", "row_anno_left")))
192 192
                 u = unit(0, "mm")
193 193
                 if(!is.null(ht_first@top_annotation)) {
194 194
                     u = unit.c(u, ht_first@top_annotation@extended[2])
... ...
@@ -205,7 +205,7 @@ setMethod(f = "adjust_heatmap_list",
205 205
             max_right_component_width = unit(0, "mm")
206 206
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "Heatmap")) {
207 207
                 ht_last = object@ht_list[[ length(object@ht_list) ]]
208
-                max_right_component_width = sum(component_width(ht_last, c("row_title_right", "row_dend_right", "row_anno_right")))
208
+                max_right_component_width = sum(component_width(ht_last, c("row_names_right", "row_dend_right", "row_anno_right")))
209 209
                 u = unit(0, "mm")
210 210
                 if(!is.null(ht_last@top_annotation)) {
211 211
                     u = unit.c(u, ht_last@top_annotation@extended[4])
... ...
@@ -225,20 +225,20 @@ setMethod(f = "adjust_heatmap_list",
225 225
         }
226 226
     } else {
227 227
         # adjust left anntatation, right annotation of all heatmaps should be aligned
228
-        max_left_anno_width = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_width(ht, "row_anno_left")))) - ROW_ANNO_PADDING
228
+        max_left_anno_width = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_width(ht, "row_anno_left")))) - ht_opt$ROW_ANNO_PADDING
229 229
         max_left_anno_width = convertWidth(max_left_anno_width, "mm")
230
-        max_right_anno_width = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_width(ht, "row_anno_right")))) - ROW_ANNO_PADDING
230
+        max_right_anno_width = max(do.call("unit.c", lapply(object@ht_list[ht_index], function(ht) component_width(ht, "row_anno_right")))) - ht_opt$ROW_ANNO_PADDING
231 231
         max_right_anno_width = convertWidth(max_right_anno_width, "mm")
232 232
         for(i in ht_index) {
233 233
             if(has_component(object@ht_list[[i]], "row_anno_left")) {
234 234
                 if(verbose) qqcat("adjust width of left annotation of heamtap @{object@ht_list[[i]]@name}\n")
235 235
                 object@ht_list[[i]]@left_annotation = resize(object@ht_list[[i]]@left_annotation, width = max_left_anno_width)
236
-                object@ht_list[[i]] = set_component_width(object@ht_list[[i]], "row_anno_left", object@ht_list[[i]]@left_annotation@width + ROW_ANNO_PADDING)
236
+                object@ht_list[[i]] = set_component_width(object@ht_list[[i]], "row_anno_left", object@ht_list[[i]]@left_annotation@width + ht_opt$ROW_ANNO_PADDING)
237 237
             }
238 238
             if(has_component(object@ht_list[[i]], "row_anno_right")) {   
239 239
                 if(verbose) qqcat("adjust width of right annotation of heamtap @{object@ht_list[[i]]@name}\n")
240 240
                 object@ht_list[[i]]@right_annotation = resize(object@ht_list[[i]]@right_annotation, width = max_right_anno_width)
241
-                object@ht_list[[i]] = set_component_width(object@ht_list[[i]], "row_anno_right", object@ht_list[[i]]@right_annotation@width + ROW_ANNO_PADDING)
241
+                object@ht_list[[i]] = set_component_width(object@ht_list[[i]], "row_anno_right", object@ht_list[[i]]@right_annotation@width + ht_opt$ROW_ANNO_PADDING)
242 242
             }
243 243
         }
244 244
 
... ...
@@ -263,7 +263,7 @@ setMethod(f = "adjust_heatmap_list",
263 263
                 unit(0, "mm")
264 264
             }
265 265
         })))
266
-        max_right_component_width = convertHeight(max_right_component_width, "mm")
266
+        max_right_component_width = convertWidth(max_right_component_width, "mm")
267 267
 
268 268
         # adjust width 
269 269
         if(verbose) qqcat("adjust title/dend width of all heatmaps\n")
... ...
@@ -389,7 +389,7 @@ setMethod(f = "adjust_heatmap_list",
389 389
             max_top_component_height = unit(0, "mm")
390 390
             if(inherits(object@ht_list[[1]], "Heatmap")) {
391 391
                 ht_first = object@ht_list[[1]]
392
-                max_top_component_height = sum(component_height(ht_first, c("column_title_top", "column_dend_top", "column_anno_top")))
392
+                max_top_component_height = sum(component_height(ht_first, c("column_names_top", "column_dend_top", "column_anno_top")))
393 393
                 u = unit(0, "mm")
394 394
                 if(!is.null(ht_first@left_annotation)) {
395 395
                     u = unit.c(u, ht_first@left_annotation@extended[3])
... ...
@@ -406,7 +406,7 @@ setMethod(f = "adjust_heatmap_list",
406 406
             max_bottom_component_height = unit(0, "mm")
407 407
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "Heatmap")) {
408 408
                 ht_last = object@ht_list[[ length(object@ht_list) ]]
409
-                max_right_component_width = sum(component_height(ht_last, c("column_title_bottom", "column_dend_bottom", "column_anno_bottom")))
409
+                max_bottom_component_height = sum(component_height(ht_last, c("column_names_bottom", "column_dend_bottom", "column_anno_bottom")))
410 410
                 u = unit(0, "mm")
411 411
                 if(!is.null(ht_last@left_annotation)) {
412 412
                     u = unit.c(u, ht_last@left_annotation@extended[1])
... ...
@@ -456,7 +456,6 @@ setMethod(f = "draw_heatmap_list",
456 456
     adjust_annotation_extension = object@ht_list_param$adjust_annotation_extension
457 457
 
458 458
     padding = unit(c(0, 0, 0, 0), "mm")
459
-
460 459
     if(adjust_annotation_extension) {
461 460
         if(object@layout$row_anno_max_bottom_extended[[1]] > object@layout$max_bottom_component_height[[1]]) {
462 461
             padding[1] = object@layout$row_anno_max_bottom_extended - object@layout$max_bottom_component_height
... ...
@@ -349,7 +349,7 @@ proper_format_lt = function(lt) {
349 349
 			return(lt[[1]])
350 350
 		}
351 351
 	} else {
352
-		has_splitting = sapply(lt, function(x) length(x) != 1)
352
+		has_splitting = any(sapply(lt, function(x) length(x) != 1))
353 353
 		if(has_splitting) {
354 354
 			return(lt)
355 355
 		} else {
... ...
@@ -191,10 +191,21 @@ setMethod(f = "make_layout",
191 191
     }
192 192
 
193 193
     ### update some values for the main heatmap
194
+    ht_nr = nrow(object@ht_list[[i_main]]@matrix)
195
+    ht_nc = ncol(object@ht_list[[i_main]]@matrix)
194 196
     if(direction == "horizontal") {
195 197
         if(!is.null(row_split)) {
196 198
             object@ht_list[[i_main]]@matrix_param$row_split = row_split
197 199
             if(verbose) qqcat("set row_split to main heatmap\n")
200
+            if(is.data.frame(row_split)) {
201
+                if(nrow(row_split) != ht_nr) {
202
+                    stop_wrap("`row_split` should have same nrow as the main matrix.")
203
+                }
204
+            } else if(is.atomic(row_split)) {
205
+                if(length(row_split) > 1 && length(row_split) != ht_nr) {
206
+                    stop_wrap("`row_split` should have same length as nrow of the main matrix.")
207
+                }
208
+            }
198 209
         }
199 210
         if(!is.null(row_km)) {
200 211
             object@ht_list[[i_main]]@matrix_param$row_km = row_km
... ...
@@ -274,6 +285,15 @@ setMethod(f = "make_layout",
274 285
         if(!is.null(column_split)) {
275 286
             object@ht_list[[i_main]]@matrix_param$column_split = column_split
276 287
             if(verbose) qqcat("set column_split to main heatmap\n")
288
+            if(is.data.frame(column_split)) {
289
+                if(nrow(column_split) != ht_nc) {
290
+                    stop_wrap("`column_split` should have same ncol as the main matrix.")
291
+                }
292
+            } else if(is.atomic(column_split)) {
293
+                if(length(column_split) > 1 && length(column_split) != ht_nr) {
294
+                    stop_wrap("`column_split` should have same length as ncol of the main matrix.")
295
+                }
296
+            }
277 297
         }
278 298
         if(!is.null(column_km)) {
279 299
             object@ht_list[[i_main]]@matrix_param$column_km = column_km
... ...
@@ -463,11 +483,13 @@ setMethod(f = "make_layout",
463 483
             }
464 484
         } else {
465 485
             for(i in seq_len(n_ht)) {
466
-                if(inherits(object@ht_list[[i]], "Heatmap") & i != i_main) {
467
-                    object@ht_list[[i]]@column_order_list = ht_main@column_order_list
468
-                    object@ht_list[[i]]@column_order = ht_main@column_order
469
-                    object@ht_list[[i]]@column_dend_param$show = FALSE
470
-                    object@ht_list[[i]]@column_dend_param$cluster = FALSE  # don't do clustering because cluster was already done
486
+                if(inherits(object@ht_list[[i]], "Heatmap")) {
487
+                    if(i == 1 && !is.null(object@ht_list[[i]]@column_names_param$anno) && object@ht_list[[i]]@column_names_param$side == "top") {
488
+                    } else if(i == n_ht && !is.null(object@ht_list[[i]]@column_names_param$anno) && object@ht_list[[i]]@column_names_param$side == "bottom") {
489
+                    } else {
490
+                        object@ht_list[[i]]@column_names_param$anno = NULL
491
+                        object@ht_list[[i]]@column_names_param$show = FALSE
492
+                    }
471 493
                 }
472 494
             }
473 495
         }   
... ...
@@ -495,12 +517,14 @@ setMethod(f = "make_layout",
495 517
             # move dend to the first one
496 518
             object@ht_list[[i_main]]@row_dend_param$show = FALSE
497 519
             object@ht_list[[1]]@row_dend_list = ht_main@row_dend_list
520
+            object@ht_list[[1]]@row_dend_slice = ht_main@row_dend_slice
498 521
             object@ht_list[[1]]@row_dend_param = ht_main@row_dend_param
499 522
             object@ht_list[[1]]@row_dend_param$side = "left"
500 523
             if(verbose) qqcat("add dendrogram of the main heatmap to the left of the first heatmap\n")
501 524
         } else if(row_dend_side == "right") {
502 525
             object@ht_list[[i_main]]@row_dend_param$show = FALSE
503 526
             object@ht_list[[n_ht]]@row_dend_list = ht_main@row_dend_list
527
+            object@ht_list[[n_ht]]@row_dend_slice = ht_main@row_dend_slice
504 528
             object@ht_list[[n_ht]]@row_dend_param = ht_main@row_dend_param
505 529
             object@ht_list[[n_ht]]@row_dend_param$side = "right"
506 530
             if(verbose) qqcat("add dendrogram of the main heatmap to the right of the last heatmap\n")
... ...
@@ -525,12 +549,14 @@ setMethod(f = "make_layout",
525 549
         if(column_dend_side == "top") {
526 550
             object@ht_list[[i_main]]@column_dend_param$show = FALSE
527 551
             object@ht_list[[1]]@column_dend_list = ht_main@column_dend_list
552
+            object@ht_list[[1]]@column_dend_slice = ht_main@column_dend_slice
528 553
             object@ht_list[[1]]@column_dend_param = ht_main@column_dend_param
529 554
             object@ht_list[[1]]@column_dend_param$side = "top"
530 555
             if(verbose) qqcat("add dendrogram of the main heatmap to the top of the first heatmap\n")
531 556
         } else if(column_dend_side == "bottom") {
532 557
             object@ht_list[[i_main]]@column_dend_param$show = FALSE
533 558
             object@ht_list[[n_ht]]@column_dend_list = ht_main@column_dend_list
559
+            object@ht_list[[n_ht]]@column_dend_slice = ht_main@column_dend_slice
534 560
             object@ht_list[[n_ht]]@column_dend_param = ht_main@column_dend_param
535 561
             object@ht_list[[n_ht]]@column_dend_param$side = "bottom"
536 562
             if(verbose) qqcat("add dendrogram of the main heatmap to the bottom of the last heatmap\n")
... ...
@@ -165,13 +165,13 @@ SingleAnnotation = function(name, value, col, fun,
165 165
     # re-define some of the argument values according to global settings
166 166
     called_args = names(as.list(match.call())[-1])
167 167
     if("legend_param" %in% called_args) {
168
-        for(opt_name in setdiff(c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "grid_border"), names(legend_param))) {
168
+        for(opt_name in setdiff(c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "border"), names(legend_param))) {
169 169
             opt_name2 = paste0("legend_", opt_name)
170 170
             if(!is.null(ht_opt(opt_name2)))
171 171
                 legend_param[[opt_name]] = ht_opt(opt_name2)
172 172
         }
173 173
     } else {
174
-        for(opt_name in c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "grid_border")) {
174
+        for(opt_name in c("title_gp", "title_position", "labels_gp", "grid_width", "grid_height", "border")) {
175 175
             opt_name2 = paste0("legend_", opt_name)
176 176
             if(!is.null(ht_opt(opt_name2)))
177 177
                 legend_param[[opt_name]] = ht_opt(opt_name2)
... ...
@@ -85,10 +85,12 @@ ht_opt = setGlobalOptions(
85 85
 	legend_grid_width = list(
86 86
 		.value = NULL,
87 87
 		.class = "unit"),
88
-	legend_grid_border = list(
88
+	legend_border = list(
89 89
 		.value = NULL),
90 90
 
91
-	border = list(
91
+	heatmap_border = list(
92
+		.value = NULL),
93
+	annotation_border = list(
92 94
 		.value = NULL),
93 95
 
94 96
 	fast_hclust = list(
... ...
@@ -110,7 +112,31 @@ ht_opt = setGlobalOptions(
110 112
 		},
111 113
 		.length = 1),
112 114
 	show_vp_border = FALSE,
113
-	anno_simple_size = unit(5, "mm")
115
+	anno_simple_size = list(
116
+		.value = unit(5, "mm"),
117
+		.class = "unit"
118
+	),
119
+
120
+	DENDROGRAM_PADDING = list(
121
+		.value = unit(0.5, "mm"),
122
+		.class = "unit"
123
+	),
124
+	DIMNAME_PADDING = list(
125
+		.value = unit(1, "mm"),
126
+		.class = "unit"
127
+	),
128
+	TITLE_PADDING = list(
129
+		.value = unit(2.5, "mm"),
130
+		.class = "unit"
131
+	),
132
+	COLUMN_ANNO_PADDING = list(
133
+		.value = unit(1, "mm"),
134
+		.class = "unit"
135
+	),
136
+	ROW_ANNO_PADDING = list(
137
+		.value = unit(1, "mm"),
138
+		.class = "unit"
139
+	)
114 140
 )
115 141
 
116 142
 
... ...
@@ -138,11 +164,13 @@ ht_global_opt = ht_opt
138 164
 .ENV$row_pos = NULL
139 165
 
140 166
 
141
-DENDROGRAM_PADDING = unit(0.5, "mm")
142
-DIMNAME_PADDING = unit(1, "mm")
143
-TITLE_PADDING = unit(2.5, "mm")
144
-COLUMN_ANNO_PADDING = unit(1, "mm")
145
-ROW_ANNO_PADDING = unit(1, "mm")
167
+# DENDROGRAM_PADDING = unit(0.5, "mm")
168
+# DIMNAME_PADDING = unit(1, "mm")
169
+# TITLE_PADDING = unit(2.5, "mm")
170
+# COLUMN_ANNO_PADDING = unit(1, "mm")
171
+# ROW_ANNO_PADDING = unit(1, "mm")
146 172
 
147 173
 GLOBAL_PADDING = unit(c(2, 2, 2, 2), "mm")
148 174
 
175
+
176
+