Browse code

update

Zuguang Gu authored on 29/04/2019 07:51:08
Showing 5 changed files

... ...
@@ -2,7 +2,7 @@ Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Make Complex Heatmaps
4 4
 Version: 1.99.8
5
-Date: 2019-04-25
5
+Date: 2019-04-28
6 6
 Author: Zuguang Gu
7 7
 Maintainer: Zuguang Gu <z.gu@dkfz.de>
8 8
 Depends: R (>= 3.1.2), methods, grid, graphics, stats, grDevices
... ...
@@ -3,6 +3,9 @@ CHANGES in VERSION 1.99.8
3 3
 * add `title_gap` in `Legend()
4 4
 * fixed a bug of wrong row title spaces when multiple heatmaps are vertically
5 5
   concatenated.
6
+* fixed a bug of *_sub_title_side when the heatmap annotation is the first/last
7
+  element in the heatmap list.
8
+* zero-column/row heatmap is supported.
6 9
 
7 10
 ========================
8 11
 
... ...
@@ -358,14 +358,15 @@ Heatmap = function(matrix, col, name,
358 358
     #     show_heatmap_legend = FALSE
359 359
     #     .Object@heatmap_param$show_heatmap_legend = FALSE
360 360
     # }
361
-    if(ncol(matrix) == 0 && (!is.null(left_annotation) || !is.null(right_annotation))) {
362
-        message_wrap("If you have row annotations for a zeor-column matrix, please directly use in form of `rowAnnotation(...) + NULL`")
363
-        return(invisible(NULL))
364
-    }
365
-    if(nrow(matrix) == 0 && (!is.null(top_annotation) || !is.null(bottom_annotation))) {
366
-        message_wrap("If you have column annotations for a zero-row matrix, please directly use in form of `HeatmapAnnotation(...) %v% NULL`")
367
-        return(invisible(NULL))
368
-    }
361
+    
362
+    # if(ncol(matrix) == 0 && (!is.null(left_annotation) || !is.null(right_annotation))) {
363
+    #     message_wrap("If you have row annotations for a zeor-column matrix, please directly use in form of `rowAnnotation(...) + NULL`")
364
+    #     return(invisible(NULL))
365
+    # }
366
+    # if(nrow(matrix) == 0 && (!is.null(top_annotation) || !is.null(bottom_annotation))) {
367
+    #     message_wrap("If you have column annotations for a zero-row matrix, please directly use in form of `HeatmapAnnotation(...) %v% NULL`")
368
+    #     return(invisible(NULL))
369
+    # }
369 370
 
370 371
     ### normalize km/split and row_km/row_split
371 372
     if(missing(row_km)) row_km = km
... ...
@@ -803,7 +804,7 @@ Heatmap = function(matrix, col, name,
803 804
             row_anno_right_width = unit(0, "mm")
804 805
         ),
805 806
 
806
-        layout_index = NULL,
807
+        layout_index = matrix(nrow = 0, ncol = 2),
807 808
         graphic_fun_list = list(),
808 809
         initialized = FALSE
809 810
     )
... ...
@@ -1488,7 +1489,8 @@ setMethod(f = "draw",
1488 1489
         upViewport()
1489 1490
     } else {
1490 1491
         if(internal) {  # a heatmap without legend
1491
-            if(ncol(object@matrix) == 0 || nrow(object@matrix) == 0) return(invisible(NULL))
1492
+            # if(ncol(object@matrix) == 0 || nrow(object@matrix) == 0) return(invisible(NULL))
1493
+            if(nrow(object@layout$layout_index) == 0) return(invisible(NULL))
1492 1494
             layout = grid.layout(nrow = length(HEATMAP_LAYOUT_COLUMN_COMPONENT), 
1493 1495
                 ncol = length(HEATMAP_LAYOUT_ROW_COMPONENT), widths = component_width(object), 
1494 1496
                 heights = component_height(object))
... ...
@@ -1507,9 +1509,9 @@ setMethod(f = "draw",
1507 1509
             }
1508 1510
             upViewport()
1509 1511
         } else {
1510
-            if(ncol(object@matrix) == 0) {
1511
-                stop_wrap("Single heatmap should contains a matrix with at least one column. Zero-column matrix can only be appended to the heatmap list.")
1512
-            }
1512
+            # if(ncol(object@matrix) == 0) {
1513
+            #     stop_wrap("Single heatmap should contains a matrix with at least one column. Zero-column matrix can only be appended to the heatmap list.")
1514
+            # }
1513 1515
             ht_list = new("HeatmapList")
1514 1516
             ht_list = add_heatmap(ht_list, object)
1515 1517
             draw(ht_list, ...)
... ...
@@ -524,9 +524,9 @@ setMethod(f = "make_layout",
524 524
                 object@ht_list = c(list(Heatmap(matrix(nrow = nr, ncol = 0))), object@ht_list)
525 525
                 ht_gap = unit.c(unit(0, "mm"), ht_gap)
526 526
                 i_main = i_main + 1
527
+                n_ht = n_ht + 1
527 528
                 if(verbose) qqcat("add a zero-column heatmap for row dend/title on the very left\n")
528
-            }
529
-                
529
+            }     
530 530
         }
531 531
 
532 532
         if(row_dend_side == "right" || row_sub_title_side == "right") {
... ...
@@ -534,6 +534,7 @@ setMethod(f = "make_layout",
534 534
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "HeatmapAnnotation")) {
535 535
                 object@ht_list = c(object@ht_list, list(Heatmap(matrix(nrow = nr, ncol = 0))))
536 536
                 ht_gap = unit.c(ht_gap, unit(0, "mm"))
537
+                n_ht = n_ht + 1
537 538
                 if(verbose) qqcat("add a zero-column heatmap for row dend/title on the very right\n")
538 539
             }
539 540
         }
... ...
@@ -546,6 +547,7 @@ setMethod(f = "make_layout",
546 547
                 object@ht_list = c(list(Heatmap(matrix(nrow = 0, ncol = nc))), object@ht_list)
547 548
                 ht_gap = unit.c(unit(0, "mm"), ht_gap)
548 549
                 i_main = i_main + 1
550
+                n_ht = n_ht + 1
549 551
                 if(verbose) qqcat("add a zero-row heatmap for column dend/title on the very top\n")
550 552
             }   
551 553
         }
... ...
@@ -554,6 +556,7 @@ setMethod(f = "make_layout",
554 556
             if(inherits(object@ht_list[[ length(object@ht_list) ]], "HeatmapAnnotation")) {
555 557
                 object@ht_list = c(object@ht_list, list(Heatmap(matrix(nrow = 0, ncol = nc))))
556 558
                 ht_gap = unit.c(ht_gap, unit(0, "mm"))
559
+                n_ht = n_ht + 1
557 560
                 if(verbose) qqcat("add a zero-column heatmap for row dend/title on the very bottom\n")
558 561
             }
559 562
         }
... ...
@@ -167,6 +167,20 @@ different results for different runs. To solve this problem, you do either way a
167 167
    final consensus k-means clustering. Note you might still get different
168 168
    results, but the chance is much smaller than just running k-means once.
169 169
 
170
+### I only want to draw dendrograms plus a list of annotations.
171
+
172
+You need to assign the dendrograms to a zero-row/column matrix:
173
+
174
+```{r}
175
+hc = hclust(dist(matrix(rnorm(100), 10)))
176
+Heatmap(matrix(nc = 0, nr = 10), cluster_rows = hc, 
177
+	right_annotation = rowAnnotation(
178
+		foo = anno_points(1:10),
179
+		sth = 1:10,
180
+		bar = anno_barplot(1:10)),
181
+	row_split = 2)
182
+```
183
+
170 184
 ### I still have a problem with the package and I am lost in the ocean of the huge vignette.
171 185
 
172 186
 The vignette (https://jokergoo.github.io/ComplexHeatmap-reference/book/)