Browse code

change *hclust* to *dend*

Zuguang Gu authored on 03/09/2015 15:07:02
Showing 82 changed files

1 1
Binary files a/.DS_Store and b/.DS_Store differ
2 2
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+# History files
2
+.Rhistory
3
+
4
+# Example code in package build process
5
+*-Ex.R
6
+
7
+# R data files from past sessions
8
+.Rdata
9
+
10
+# RStudio files
11
+.Rproj.user/
12
+
13
+.DS_Store
... ...
@@ -8,19 +8,18 @@ export(row_anno_barplot)
8 8
 export(Heatmap)
9 9
 export(row_anno_points)
10 10
 export(column_anno_text)
11
+export(decorate_row_dend)
12
+export(decorate_column_dend)
11 13
 exportMethods(draw)
12 14
 exportMethods(draw_heatmap_body)
13 15
 exportMethods(color_mapping_legend)
14 16
 exportMethods(prepare)
15 17
 export(decorate_annotation)
16 18
 exportMethods(map_to_colors)
17
-export(decorate_hclust)
18 19
 export(decorate_dimnames)
19 20
 export(column_anno_points)
20 21
 exportMethods(component_height)
21 22
 export(row_anno_text)
22
-export(decorate_column_hclust)
23
-exportMethods(draw_hclust)
24 23
 exportClasses(SingleAnnotation)
25 24
 export(SingleAnnotation)
26 25
 export(oncoPrint)
... ...
@@ -32,6 +31,7 @@ exportMethods(row_order)
32 31
 export(AdditiveUnit)
33 32
 exportMethods(draw_heatmap_list)
34 33
 export(row_anno_density)
34
+export(is_abs_unit)
35 35
 export(dist2)
36 36
 export(decorate_heatmap_body)
37 37
 exportMethods(draw_heatmap_legend)
... ...
@@ -49,7 +49,6 @@ exportClasses(ColorMapping)
49 49
 export(ColorMapping)
50 50
 exportClasses(HeatmapAnnotation)
51 51
 export(HeatmapAnnotation)
52
-export(decorate_row_hclust)
53 52
 export(anno_points)
54 53
 exportMethods(draw_title)
55 54
 export(ht_global_opt)
... ...
@@ -71,18 +70,20 @@ exportMethods(draw_annotation)
71 70
 exportMethods(make_column_cluster)
72 71
 export(SingleAnnotation)
73 72
 export(row_anno_histogram)
74
-export(select)
75 73
 exportMethods(get_color_mapping_list)
76 74
 exportMethods(make_row_cluster)
77 75
 exportMethods(component_width)
78 76
 export(decorate_column_title)
77
+exportMethods(draw_dend)
79 78
 exportMethods(get_color_mapping_param_list)
80 79
 export(grid.dendrogram)
81 80
 export(decorate_title)
81
+export(decorate_dend)
82 82
 export(rowAnnotation)
83 83
 export(columnAnnotation)
84 84
 export(decorate_row_names)
85 85
 export(anno_text)
86
+export(select)
86 87
 export(anno_density)
87 88
 
88 89
 import(grid)
... ...
@@ -1,10 +1,11 @@
1
-CHANGES in VERSION 1.3.4
1
+CHANGES in VERSION 1.4.0
2 2
 
3 3
 * returned value for `draw` method has been changes
4 4
 * add `row_order`, `column_order`, `row_dend` and `column_dend`
5 5
   to extract orders and dendrograms after heatmap clustering
6
-* add `select_region` to interactively select sub region in the heatmap
6
+* add `select` function to interactively select sub region in the heatmap
7 7
   and retrieve row/column index in the selected sub region.
8
+* renames all varialbes `*hclust*` to `*dend*`
8 9
 
9 10
 ====================================
10 11
 
... ...
@@ -9,8 +9,6 @@ setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heat
9 9
 
10 10
 setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
11 11
 
12
-setGeneric('draw_hclust', function(object, ...) standardGeneric('draw_hclust'))
13
-
14 12
 setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
15 13
 
16 14
 setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
... ...
@@ -49,6 +47,8 @@ setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_
49 47
 
50 48
 setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
51 49
 
50
+setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
51
+
52 52
 setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
53 53
 
54 54
 setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
... ...
@@ -23,6 +23,10 @@ AdditiveUnit = setClass("AdditiveUnit")
23 23
 # == author
24 24
 # Zuguang Gu <z.gu@dkfz.de>
25 25
 #
26
+# == example
27
+# # no example for this function
28
+# NULL
29
+#
26 30
 AdditiveUnit = function(...) {
27 31
     new("AdditiveUnit", ...)
28 32
 }
... ...
@@ -36,7 +40,7 @@ AdditiveUnit = function(...) {
36 40
 # -y a `Heatmap-class` object, a `HeatmapAnnotation-class` object or a `HeatmapList-class` object.
37 41
 #
38 42
 # == detail
39
-# It is only a shortcut function. It actually calls `add_heatmap,Heatmap-method`, `add_heatmap,HeatmapList-method`
43
+# It is only a helper function. It actually calls `add_heatmap,Heatmap-method`, `add_heatmap,HeatmapList-method`
40 44
 # or `add_heatmap,HeatmapAnnotation-method` depending on the class of the input objects.
41 45
 #
42 46
 # The `HeatmapAnnotation-class` object to be added should only be row annotations.
... ...
@@ -27,23 +27,23 @@
27 27
 # From top to bottom in column 4, the regions are:
28 28
 #
29 29
 # - title which is put on the top of the heatmap, graphics are drawn by `draw_title,Heatmap-method`.
30
-# - column cluster on the top, graphics are drawn by `draw_hclust,Heatmap-method`.
30
+# - column cluster on the top, graphics are drawn by `draw_dend,Heatmap-method`.
31 31
 # - column annotation on the top, graphics are drawn by `draw_annotation,Heatmap-method`.
32 32
 # - column names on the top, graphics are drawn by `draw_dimnames,Heatmap-method`.
33 33
 # - heatmap body, graphics are drawn by `draw_heatmap_body,Heatmap-method`.
34 34
 # - column names on the bottom, graphics are drawn by `draw_dimnames,Heatmap-method`.
35 35
 # - column annotation on the bottom, graphics are drawn by `draw_annotation,Heatmap-method`.
36
-# - column cluster on the bottom, graphics are drawn by `draw_hclust,Heatmap-method`.
36
+# - column cluster on the bottom, graphics are drawn by `draw_dend,Heatmap-method`.
37 37
 # - title on the bottom, graphics are drawn by `draw_title,Heatmap-method`.
38 38
 # 
39 39
 # From left to right in row 5, the regions are:
40 40
 #
41 41
 # - title which is put in the left of the heatmap, graphics are drawn by `draw_title,Heatmap-method`.
42
-# - row cluster on the left, graphics are drawn by `draw_hclust,Heatmap-method`.
42
+# - row cluster on the left, graphics are drawn by `draw_dend,Heatmap-method`.
43 43
 # - row names on the left, graphics are drawn by `draw_dimnames,Heatmap-method`.
44 44
 # - heatmap body
45 45
 # - row names on the right, graphics are drawn by `draw_dimnames,Heatmap-method`.
46
-# - row cluster on the right, graphics are drawn by `draw_hclust,Heatmap-method`.
46
+# - row cluster on the right, graphics are drawn by `draw_dend,Heatmap-method`.
47 47
 # - title on the right, graphics are drawn by `draw_title,Heatmap-method`.
48 48
 #
49 49
 # The `Heatmap-class` is not responsible for heatmap legend and annotation legends. The `draw,Heatmap-method` method
... ...
@@ -78,13 +78,13 @@ Heatmap = setClass("Heatmap",
78 78
         column_title_rot = "numeric",
79 79
         column_title_just = "numeric",
80 80
 
81
-        row_hclust_list = "list", # one or more row clusters
82
-        row_hclust_param = "list", # parameters for row cluster
81
+        row_dend_list = "list", # one or more row clusters
82
+        row_dend_param = "list", # parameters for row cluster
83 83
         row_order_list = "list",
84 84
         row_order = "numeric",
85 85
 
86
-        column_hclust = "ANY",
87
-        column_hclust_param = "list", # parameters for column cluster
86
+        column_dend = "ANY",
87
+        column_dend_param = "list", # parameters for column cluster
88 88
         column_order = "numeric",
89 89
 
90 90
         row_names_param = "list",
... ...
@@ -143,33 +143,43 @@ Heatmap = setClass("Heatmap",
143 143
 #                the input arguments are two vectors and the function calculates distance between these
144 144
 #                two vectors.
145 145
 # -clustering_method_rows method to make cluster, pass to `stats::hclust`.
146
-# -row_hclust_side should the row cluster be put on the left or right of the heatmap?
147
-# -row_hclust_width width of the row cluster, should be a `grid::unit` object.
148
-# -show_row_hclust whether show row clusters. 
149
-# -row_hclust_gp graphics parameters for drawing lines. If users already provide a `stats::dendrogram`
146
+# -row_dend_side should the row cluster be put on the left or right of the heatmap?
147
+# -row_dend_width width of the row cluster, should be a `grid::unit` object.
148
+# -show_row_dend whether show row clusters. 
149
+# -row_dend_gp graphics parameters for drawing lines. If users already provide a `stats::dendrogram`
150 150
 #                object with edges rendered, this argument will be ignored.
151
+# -row_dend_reorder apply reordering on rows. The value can be a logical value or a vector which contains weight 
152
+#               which is used to reorder rows
153
+# -row_hclust_side deprecated, use ``row_dend_side`` instead
154
+# -row_hclust_width deprecated, use ``row_dend_width`` instead
155
+# -show_row_hclust deprecated, use ``show_row_dend`` instead
156
+# -row_hclust_gp deprecated, use ``row_dend_gp`` instead
157
+# -row_hclust_reorder deprecated, use ``row_dend_reorder`` instead
151 158
 # -cluster_columns whether make cluster on columns. Same settings as ``cluster_rows``.
152 159
 # -clustering_distance_columns same setting as ``clustering_distance_rows``.
153 160
 # -clustering_method_columns method to make cluster, pass to `stats::hclust`.
154
-# -column_hclust_side should the column cluster be put on the top or bottom of the heatmap?
155
-# -column_hclust_height height of the column cluster, should be a `grid::unit` object.
156
-# -show_column_hclust whether show column clusters.
157
-# -column_hclust_gp graphic parameters for drawling lines. Same settings as ``row_hclust_gp``.
161
+# -column_dend_side should the column cluster be put on the top or bottom of the heatmap?
162
+# -column_dend_height height of the column cluster, should be a `grid::unit` object.
163
+# -show_column_dend whether show column clusters.
164
+# -column_dend_gp graphic parameters for drawling lines. Same settings as ``row_dend_gp``.
165
+# -column_dend_reorder apply reordering on columns. The value can be a logical value or a vector which contains weight 
166
+#               which is used to reorder columns
167
+# -column_hclust_side deprecated, use ``column_dend_side`` instead
168
+# -column_hclust_height deprecated, use ``column_dend_height`` instead
169
+# -show_column_hclust deprecated, use ``show_column_dend`` instead
170
+# -column_hclust_gp deprecated, use ``column_dend_gp`` instead
171
+# -column_hclust_reorder deprecated, use ``column_dend_reorder`` instead
158 172
 # -row_order order of rows. It makes it easy to adjust row order for a list of heatmaps if this heatmap 
159 173
 #      is selected as the main heatmap. Manually setting row order should turn off clustering
160 174
 # -column_order order of column. It makes it easy to adjust column order for both matrix and column annotations.
161 175
 # -row_names_side should the row names be put on the left or right of the heatmap?
162 176
 # -show_row_names whether show row names.
163
-# -row_hclust_reorder apply reordering on rows. The value can be a logical value or a vector which contains weight 
164
-#               which is used to reorder rows
165 177
 # -row_names_max_width maximum width of row names viewport. Because some times row names can be very long, it is not reasonable
166 178
 #                      to show them all.
167 179
 # -row_names_gp graphic parameters for drawing text.
168 180
 # -column_names_side should the column names be put on the top or bottom of the heatmap?
169 181
 # -column_names_max_height maximum height of column names viewport.
170 182
 # -show_column_names whether show column names.
171
-# -column_hclust_reorder apply reordering on columns. The value can be a logical value or a vector which contains weight 
172
-#               which is used to reorder columns
173 183
 # -column_names_gp graphic parameters for drawing text.
174 184
 # -top_annotation a `HeatmapAnnotation` object which contains a list of annotations.
175 185
 # -top_annotation_height total height of the column annotations on the top.
... ...
@@ -206,35 +216,65 @@ Heatmap = setClass("Heatmap",
206 216
 # == author
207 217
 # Zuguang Gu <z.gu@dkfz.de>
208 218
 #
209
-Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
210
-    rect_gp = gpar(col = NA), cell_fun = function(j, i, x, y, width, height, fill) NULL,
211
-    row_title = character(0), row_title_side = c("left", "right"), 
219
+Heatmap = function(matrix, col, name, 
220
+    na_col = "grey", 
221
+    color_space = "LAB",
222
+    rect_gp = gpar(col = NA), 
223
+    cell_fun = function(j, i, x, y, width, height, fill) NULL,
224
+    row_title = character(0), 
225
+    row_title_side = c("left", "right"), 
212 226
     row_title_gp = gpar(fontsize = 14), 
213 227
     row_title_rot = switch(row_title_side[1], "left" = 90, "right" = 270),
214
-    column_title = character(0), column_title_side = c("top", "bottom"), 
215
-    column_title_gp = gpar(fontsize = 14), column_title_rot = 0,
216
-    cluster_rows = TRUE, clustering_distance_rows = "euclidean",
217
-    clustering_method_rows = "complete", row_hclust_side = c("left", "right"),
218
-    row_hclust_width = unit(10, "mm"), show_row_hclust = TRUE, 
219
-    row_hclust_reorder = FALSE,
220
-    row_hclust_gp = gpar(), cluster_columns = TRUE, 
221
-    clustering_distance_columns = "euclidean", clustering_method_columns = "complete",
222
-    column_hclust_side = c("top", "bottom"), column_hclust_height = unit(10, "mm"), 
223
-    show_column_hclust = TRUE, column_hclust_gp = gpar(), 
224
-    column_hclust_reorder = FALSE,
225
-    row_order = NULL, column_order = NULL,
226
-    row_names_side = c("right", "left"), show_row_names = TRUE, 
227
-    row_names_max_width = unit(4, "cm"), row_names_gp = gpar(fontsize = 12), 
228
+    column_title = character(0), 
229
+    column_title_side = c("top", "bottom"), 
230
+    column_title_gp = gpar(fontsize = 14), 
231
+    column_title_rot = 0,
232
+    cluster_rows = TRUE, 
233
+    clustering_distance_rows = "euclidean",
234
+    clustering_method_rows = "complete", 
235
+    row_dend_side = c("left", "right"),
236
+    row_dend_width = unit(10, "mm"), 
237
+    show_row_dend = TRUE, 
238
+    row_dend_reorder = FALSE,
239
+    row_dend_gp = gpar(), 
240
+    row_hclust_side = row_dend_side,
241
+    row_hclust_width = row_dend_width, 
242
+    show_row_hclust = show_row_dend, 
243
+    row_hclust_reorder = row_dend_reorder,
244
+    row_hclust_gp = row_dend_gp, 
245
+    cluster_columns = TRUE, 
246
+    clustering_distance_columns = "euclidean", 
247
+    clustering_method_columns = "complete",
248
+    column_dend_side = c("top", "bottom"), 
249
+    column_dend_height = unit(10, "mm"), 
250
+    show_column_dend = TRUE, 
251
+    column_dend_gp = gpar(), 
252
+    column_dend_reorder = FALSE,
253
+    column_hclust_side = column_dend_side, 
254
+    column_hclust_height = column_dend_height, 
255
+    show_column_hclust = show_column_dend, 
256
+    column_hclust_gp = column_dend_gp, 
257
+    column_hclust_reorder = column_dend_reorder,
258
+    row_order = NULL, 
259
+    column_order = NULL,
260
+    row_names_side = c("right", "left"), 
261
+    show_row_names = TRUE, 
262
+    row_names_max_width = unit(4, "cm"), 
263
+    row_names_gp = gpar(fontsize = 12), 
228 264
     column_names_side = c("bottom", "top"), 
229
-    show_column_names = TRUE, column_names_max_height = unit(4, "cm"), 
265
+    show_column_names = TRUE, 
266
+    column_names_max_height = unit(4, "cm"), 
230 267
     column_names_gp = gpar(fontsize = 12),
231 268
     top_annotation = new("HeatmapAnnotation"),
232 269
     top_annotation_height = top_annotation@size,
233 270
     bottom_annotation = new("HeatmapAnnotation"),
234 271
     bottom_annotation_height = bottom_annotation@size,
235
-    km = 1, split = NULL, gap = unit(1, "mm"), 
272
+    km = 1, 
273
+    split = NULL, 
274
+    gap = unit(1, "mm"), 
236 275
     combined_name_fun = function(x) paste(x, collapse = "/"),
237
-    width = NULL, show_heatmap_legend = TRUE,
276
+    width = NULL, 
277
+    show_heatmap_legend = TRUE,
238 278
     heatmap_legend_param = list(title = name, color_bar = "discrete")) {
239 279
 
240 280
     # re-define some of the argument values according to global settings
... ...
@@ -248,6 +288,17 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
248 288
             }
249 289
         }
250 290
     }
291
+
292
+    for(ca in called_args) {
293
+        if(ca %in% c("row_hclust_side", "row_hclust_width", "show_row_hclust", "row_hclust_reorder", "row_hclust_gp",
294
+                     "column_hclust_side", "column_hclust_height", "show_column_hclust", "column_hclust_gp", "column_hclust_reorder")) {
295
+            ca_new = gsub("hclust", "dend", ca)
296
+            if(!ca_new %in% called_args) {
297
+                assign(ca_new, get(ca))
298
+            }
299
+            warning(paste0("'", ca, "' is deprecated in the future, use '", ca_new, "' instead."))
300
+        }
301
+    }
251 302
    
252 303
     if("heatmap_legend_param" %in% called_args) {
253 304
         for(opt_name in setdiff(c("title_gp", "labels_gp", "grid_width", "grid_height", "grid_border"), names(heatmap_legend_param))) {
... ...
@@ -294,24 +345,24 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
294 345
     if(ncol(matrix) == 0 || nrow(matrix) == 0) {
295 346
         if(!inherits(cluster_columns, c("dendrogram", "hclust"))) {
296 347
             cluster_columns = FALSE
297
-            show_column_hclust = FALSE
348
+            show_column_dend = FALSE
298 349
         }
299 350
         if(!inherits(cluster_rows, c("dendrogram", "hclust"))) {
300 351
             cluster_rows = FALSE
301
-            show_row_hclust = FALSE
352
+            show_row_dend = FALSE
302 353
         }
303 354
         km = 1
304 355
     }
305 356
     if(ncol(matrix) == 1) {
306 357
         if(!inherits(cluster_columns, c("dendrogram", "hclust"))) {
307 358
             cluster_columns = FALSE
308
-            show_column_hclust = FALSE
359
+            show_column_dend = FALSE
309 360
         }
310 361
     }
311 362
     if(nrow(matrix) == 1) {
312 363
         if(!inherits(cluster_rows, c("dendrogram", "hclust"))) {
313 364
             cluster_rows = FALSE
314
-            show_row_hclust = FALSE
365
+            show_row_dend = FALSE
315 366
         }
316 367
         km = 1
317 368
     }
... ...
@@ -321,16 +372,16 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
321 372
         } else if(inherits(cluster_rows, c("dendrogram", "hclust"))) {
322 373
         } else {
323 374
             cluster_rows = FALSE
324
-            show_row_hclust = FALSE
375
+            show_row_dend = FALSE
325 376
         }
326
-        row_hclust_reorder = FALSE
377
+        row_dend_reorder = FALSE
327 378
         if("clustering_distance_columns" %in% called_args) {
328 379
         } else if(inherits(cluster_columns, c("dendrogram", "hclust"))) {
329 380
         } else {
330 381
             cluster_columns = FALSE
331
-            show_column_hclust = FALSE
382
+            show_column_dend = FALSE
332 383
         }
333
-        column_hclust_reorder = FALSE
384
+        column_dend_reorder = FALSE
334 385
         km = 1
335 386
     }
336 387
     .Object@matrix = matrix
... ...
@@ -403,7 +454,7 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
403 454
     .Object@row_title = row_title
404 455
     .Object@row_title_rot = row_title_rot %% 360
405 456
     .Object@row_title_param$side = match.arg(row_title_side)[1]
406
-    .Object@row_title_param$gp = check_gp(row_title_gp)  # if the number of settings is same as number of row-splits, gp will be adjusted by `make_row_hclust`
457
+    .Object@row_title_param$gp = check_gp(row_title_gp)  # if the number of settings is same as number of row-splits, gp will be adjusted by `make_row_dend`
407 458
     .Object@row_title_param$combined_name_fun = combined_name_fun
408 459
     .Object@row_title_just = get_text_just(rot = row_title_rot, side = .Object@row_title_param$side)
409 460
 
... ...
@@ -439,29 +490,29 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
439 490
     .Object@column_names_param$max_height = column_names_max_height + unit(2, "mm")
440 491
 
441 492
     if(inherits(cluster_rows, "dendrogram") || inherits(cluster_rows, "hclust")) {
442
-        .Object@row_hclust_param$obj = cluster_rows
443
-        .Object@row_hclust_param$cluster = TRUE
493
+        .Object@row_dend_param$obj = cluster_rows
494
+        .Object@row_dend_param$cluster = TRUE
444 495
     } else if(inherits(cluster_rows, "function")) {
445
-        .Object@row_hclust_param$fun = cluster_rows
446
-        .Object@row_hclust_param$cluster = TRUE
496
+        .Object@row_dend_param$fun = cluster_rows
497
+        .Object@row_dend_param$cluster = TRUE
447 498
     } else {
448
-        .Object@row_hclust_param$cluster = cluster_rows
499
+        .Object@row_dend_param$cluster = cluster_rows
449 500
         if(!cluster_rows) {
450
-            row_hclust_width = unit(0, "mm")
451
-            show_row_hclust = FALSE
501
+            row_dend_width = unit(0, "mm")
502
+            show_row_dend = FALSE
452 503
         }
453 504
     }
454
-    if(!show_row_hclust) {
455
-        row_hclust_width = unit(0, "mm")
505
+    if(!show_row_dend) {
506
+        row_dend_width = unit(0, "mm")
456 507
     }
457
-    .Object@row_hclust_list = list()
458
-    .Object@row_hclust_param$distance = clustering_distance_rows
459
-    .Object@row_hclust_param$method = clustering_method_rows
460
-    .Object@row_hclust_param$side = match.arg(row_hclust_side)[1]
461
-    .Object@row_hclust_param$width = row_hclust_width + unit(1, "mm")  # append the gap
462
-    .Object@row_hclust_param$show = show_row_hclust
463
-    .Object@row_hclust_param$gp = check_gp(row_hclust_gp)
464
-    .Object@row_hclust_param$reorder = row_hclust_reorder
508
+    .Object@row_dend_list = list()
509
+    .Object@row_dend_param$distance = clustering_distance_rows
510
+    .Object@row_dend_param$method = clustering_method_rows
511
+    .Object@row_dend_param$side = match.arg(row_dend_side)[1]
512
+    .Object@row_dend_param$width = row_dend_width + unit(1, "mm")  # append the gap
513
+    .Object@row_dend_param$show = show_row_dend
514
+    .Object@row_dend_param$gp = check_gp(row_dend_gp)
515
+    .Object@row_dend_param$reorder = row_dend_reorder
465 516
     .Object@row_order_list = list() # default order
466 517
     if(is.null(row_order)) {
467 518
         .Object@row_order = seq_len(nrow(matrix))
... ...
@@ -473,29 +524,29 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
473 524
     }
474 525
 
475 526
     if(inherits(cluster_columns, "dendrogram") || inherits(cluster_columns, "hclust")) {
476
-        .Object@column_hclust_param$obj = cluster_columns
477
-        .Object@column_hclust_param$cluster = TRUE
527
+        .Object@column_dend_param$obj = cluster_columns
528
+        .Object@column_dend_param$cluster = TRUE
478 529
     } else if(inherits(cluster_columns, "function")) {
479
-        .Object@column_hclust_param$fun = cluster_columns
480
-        .Object@column_hclust_param$cluster = TRUE
530
+        .Object@column_dend_param$fun = cluster_columns
531
+        .Object@column_dend_param$cluster = TRUE
481 532
     } else {
482
-        .Object@column_hclust_param$cluster = cluster_columns
533
+        .Object@column_dend_param$cluster = cluster_columns
483 534
         if(!cluster_columns) {
484
-            column_hclust_height = unit(0, "mm")
485
-            show_column_hclust = FALSE
535
+            column_dend_height = unit(0, "mm")
536
+            show_column_dend = FALSE
486 537
         }
487 538
     }
488
-    if(!show_column_hclust) {
489
-        column_hclust_height = unit(0, "mm")
539
+    if(!show_column_dend) {
540
+        column_dend_height = unit(0, "mm")
490 541
     }
491
-    .Object@column_hclust = NULL
492
-    .Object@column_hclust_param$distance = clustering_distance_columns
493
-    .Object@column_hclust_param$method = clustering_method_columns
494
-    .Object@column_hclust_param$side = match.arg(column_hclust_side)[1]
495
-    .Object@column_hclust_param$height = column_hclust_height + unit(1, "mm")  # append the gap
496
-    .Object@column_hclust_param$show = show_column_hclust
497
-    .Object@column_hclust_param$gp = check_gp(column_hclust_gp)
498
-    .Object@column_hclust_param$reorder = column_hclust_reorder
542
+    .Object@column_dend = NULL
543
+    .Object@column_dend_param$distance = clustering_distance_columns
544
+    .Object@column_dend_param$method = clustering_method_columns
545
+    .Object@column_dend_param$side = match.arg(column_dend_side)[1]
546
+    .Object@column_dend_param$height = column_dend_height + unit(1, "mm")  # append the gap
547
+    .Object@column_dend_param$show = show_column_dend
548
+    .Object@column_dend_param$gp = check_gp(column_dend_gp)
549
+    .Object@column_dend_param$reorder = column_dend_reorder
499 550
     if(is.null(column_order)) {
500 551
         .Object@column_order = seq_len(ncol(matrix))
501 552
     } else {
... ...
@@ -535,18 +586,18 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
535 586
 
536 587
     .Object@layout = list(
537 588
         layout_column_title_top_height = unit(0, "mm"),
538
-        layout_column_hclust_top_height = unit(0, "mm"),
589
+        layout_column_dend_top_height = unit(0, "mm"),
539 590
         layout_column_anno_top_height = unit(0, "mm"),
540 591
         layout_column_names_top_height = unit(0, "mm"),
541 592
         layout_column_title_bottom_height = unit(0, "mm"),
542
-        layout_column_hclust_bottom_height = unit(0, "mm"),
593
+        layout_column_dend_bottom_height = unit(0, "mm"),
543 594
         layout_column_anno_bottom_height = unit(0, "mm"),
544 595
         layout_column_names_bottom_height = unit(0, "mm"),
545 596
 
546 597
         layout_row_title_left_width = unit(0, "mm"),
547
-        layout_row_hclust_left_width = unit(0, "mm"),
598
+        layout_row_dend_left_width = unit(0, "mm"),
548 599
         layout_row_names_left_width = unit(0, "mm"),
549
-        layout_row_hclust_right_width = unit(0, "mm"),
600
+        layout_row_dend_right_width = unit(0, "mm"),
550 601
         layout_row_names_right_width = unit(0, "mm"),
551 602
         layout_row_title_right_width = unit(0, "mm"),
552 603
 
... ...
@@ -567,7 +618,7 @@ Heatmap = function(matrix, col, name, na_col = "grey", color_space = "LAB",
567 618
 # -object a `Heatmap-class` object.
568 619
 #
569 620
 # == details
570
-# The function will fill or adjust ``column_hclust`` and ``column_order`` slots.
621
+# The function will fill or adjust ``column_dend`` and ``column_order`` slots.
571 622
 #
572 623
 # This function is only for internal use.
573 624
 #
... ...
@@ -582,23 +633,23 @@ setMethod(f = "make_column_cluster",
582 633
     definition = function(object) {
583 634
     
584 635
     mat = object@matrix
585
-    distance = object@column_hclust_param$distance
586
-    method = object@column_hclust_param$method
636
+    distance = object@column_dend_param$distance
637
+    method = object@column_dend_param$method
587 638
     order = object@column_order
588
-    reorder = object@column_hclust_param$reorder
639
+    reorder = object@column_dend_param$reorder
589 640
 
590
-    if(object@column_hclust_param$cluster) {
591
-        if(!is.null(object@column_hclust_param$obj)) {
592
-            object@column_hclust = object@column_hclust_param$obj
593
-        } else if(!is.null(object@column_hclust_param$fun)) {
594
-            object@column_hclust = object@column_hclust_param$fun(t(mat))
641
+    if(object@column_dend_param$cluster) {
642
+        if(!is.null(object@column_dend_param$obj)) {
643
+            object@column_dend = object@column_dend_param$obj
644
+        } else if(!is.null(object@column_dend_param$fun)) {
645
+            object@column_dend = object@column_dend_param$fun(t(mat))
595 646
         } else {
596
-            object@column_hclust = hclust(get_dist(t(mat), distance), method = method)
647
+            object@column_dend = hclust(get_dist(t(mat), distance), method = method)
597 648
         }
598
-        column_order = get_hclust_order(object@column_hclust)  # we don't need the pre-defined orders
649
+        column_order = get_dend_order(object@column_dend)  # we don't need the pre-defined orders
599 650
 
600
-        if(inherits(object@column_hclust, "hclust")) {
601
-            object@column_hclust = as.dendrogram(object@column_hclust)
651
+        if(inherits(object@column_dend, "hclust")) {
652
+            object@column_dend = as.dendrogram(object@column_dend)
602 653
         }
603 654
 
604 655
         if(identical(reorder, NULL)) {
... ...
@@ -622,8 +673,8 @@ setMethod(f = "make_column_cluster",
622 673
             if(length(reorder) != ncol(mat)) {
623 674
                 stop("weight of reordering should have same length as number of columns.\n")
624 675
             }
625
-            object@column_hclust = reorder(object@column_hclust, reorder)
626
-            column_order = order.dendrogram(object@column_hclust)
676
+            object@column_dend = reorder(object@column_dend, reorder)
677
+            column_order = order.dendrogram(object@column_dend)
627 678
         }
628 679
     } else {
629 680
         column_order = order
... ...
@@ -647,7 +698,7 @@ setMethod(f = "make_column_cluster",
647 698
 # -object a `Heatmap-class` object.
648 699
 #
649 700
 # == details
650
-# The function will fill or adjust ``row_hclust_list``, ``row_order_list``, ``row_title`` and ``matrix_param`` slots.
701
+# The function will fill or adjust ``row_dend_list``, ``row_order_list``, ``row_title`` and ``matrix_param`` slots.
651 702
 #
652 703
 # If ``order`` is defined, no clustering will be applied.
653 704
 #
... ...
@@ -664,28 +715,28 @@ setMethod(f = "make_row_cluster",
664 715
     definition = function(object) {
665 716
 
666 717
     mat = object@matrix
667
-    distance = object@row_hclust_param$distance
668
-    method = object@row_hclust_param$method
718
+    distance = object@row_dend_param$distance
719
+    method = object@row_dend_param$method
669 720
     order = object@row_order  # pre-defined row order
670 721
     km = object@matrix_param$km
671 722
     split = object@matrix_param$split
672
-    reorder = object@row_hclust_param$reorder
723
+    reorder = object@row_dend_param$reorder
673 724
 
674
-    if(object@row_hclust_param$cluster) {
725
+    if(object@row_dend_param$cluster) {
675 726
 
676 727
         if(is.numeric(split) && length(split) == 1) {
677
-            if(is.null(object@row_hclust_param$obj)) {
678
-                object@row_hclust_param$obj = hclust(get_dist(mat, distance), method = method)
728
+            if(is.null(object@row_dend_param$obj)) {
729
+                object@row_dend_param$obj = hclust(get_dist(mat, distance), method = method)
679 730
             }
680 731
         }
681 732
 
682
-        if(!is.null(object@row_hclust_param$obj)) {
733
+        if(!is.null(object@row_dend_param$obj)) {
683 734
             if(km > 1) {
684 735
                 stop("You can not make k-means clustering since you have already specified a clustering object.")
685 736
             }
686 737
             if(is.null(split)) {
687
-                object@row_hclust_list = list(object@row_hclust_param$obj)
688
-                object@row_order_list = list(get_hclust_order(object@row_hclust_param$obj))
738
+                object@row_dend_list = list(object@row_dend_param$obj)
739
+                object@row_order_list = list(get_dend_order(object@row_dend_param$obj))
689 740
             } else {
690 741
                 if(length(split) > 1 || !is.numeric(split)) {
691 742
                     stop("Since you specified a clustering object, you can only split rows by providing a number (number of row slices.")
... ...
@@ -693,12 +744,12 @@ setMethod(f = "make_row_cluster",
693 744
                 if(split < 2) {
694 745
                     stop("Here `split` should be equal or larger than 2.")
695 746
                 }
696
-                if(inherits(object@row_hclust_param$obj, "hclust")) {
697
-                    object@row_hclust_param$obj = as.dendrogram(object@row_hclust_param$obj)
747
+                if(inherits(object@row_dend_param$obj, "hclust")) {
748
+                    object@row_dend_param$obj = as.dendrogram(object@row_dend_param$obj)
698 749
                 }
699
-                object@row_hclust_list = cut_dendrogram(object@row_hclust_param$obj, split)
700
-                sth = tapply(order.dendrogram(object@row_hclust_param$obj), 
701
-                    rep(seq_along(object@row_hclust_list), times = sapply(object@row_hclust_list, nobs)), 
750
+                object@row_dend_list = cut_dendrogram(object@row_dend_param$obj, split)
751
+                sth = tapply(order.dendrogram(object@row_dend_param$obj), 
752
+                    rep(seq_along(object@row_dend_list), times = sapply(object@row_dend_list, nobs)), 
702 753
                     function(x) x)
703 754
                 attributes(sth) = NULL
704 755
                 object@row_order_list = sth
... ...
@@ -782,31 +833,31 @@ setMethod(f = "make_row_cluster",
782 833
         }
783 834
     }
784 835
     o_row_order_list = row_order_list
785
-    # make hclust in each slice
786
-    if(object@row_hclust_param$cluster) {
787
-        row_hclust_list = rep(list(NULL), length(row_order_list))
836
+    # make dend in each slice
837
+    if(object@row_dend_param$cluster) {
838
+        row_dend_list = rep(list(NULL), length(row_order_list))
788 839
         for(i in seq_along(row_order_list)) {
789 840
             submat = mat[ row_order_list[[i]], , drop = FALSE]
790 841
             if(nrow(submat) > 1) {
791
-                if(!is.null(object@row_hclust_param$fun)) {
792
-                    row_hclust_list[[i]] = object@row_hclust_param$fun(mat)
793
-                    row_order_list[[i]] = row_order_list[[i]][ get_hclust_order(row_hclust_list[[i]]) ]
842
+                if(!is.null(object@row_dend_param$fun)) {
843
+                    row_dend_list[[i]] = object@row_dend_param$fun(mat)
844
+                    row_order_list[[i]] = row_order_list[[i]][ get_dend_order(row_dend_list[[i]]) ]
794 845
                 } else {
795 846
                     #if(is.numeric(mat)) {
796
-                        row_hclust_list[[i]] = hclust(get_dist(submat, distance), method = method)
797
-                        row_order_list[[i]] = row_order_list[[i]][ get_hclust_order(row_hclust_list[[i]]) ]
847
+                        row_dend_list[[i]] = hclust(get_dist(submat, distance), method = method)
848
+                        row_order_list[[i]] = row_order_list[[i]][ get_dend_order(row_dend_list[[i]]) ]
798 849
                     #}
799 850
                 }
800 851
             } else {
801
-                row_hclust_list[[i]] = NULL
852
+                row_dend_list[[i]] = NULL
802 853
                 row_order_list[[i]] = row_order_list[[i]][1]
803 854
             }
804 855
         }
805
-        object@row_hclust_list = row_hclust_list
856
+        object@row_dend_list = row_dend_list
806 857
 
807
-        for(i in seq_along(object@row_hclust_list)) {
808
-            if(inherits(object@row_hclust_list[[i]], "hclust")) {
809
-                object@row_hclust_list[[i]] = as.dendrogram(object@row_hclust_list[[i]])
858
+        for(i in seq_along(object@row_dend_list)) {
859
+            if(inherits(object@row_dend_list[[i]], "hclust")) {
860
+                object@row_dend_list[[i]] = as.dendrogram(object@row_dend_list[[i]])
810 861
             }
811 862
         }
812 863
 
... ...
@@ -832,10 +883,10 @@ setMethod(f = "make_row_cluster",
832 883
             if(length(reorder) != nrow(mat)) {
833 884
                 stop("weight of reordering should have same length as number of rows.\n")
834 885
             }
835
-            for(i in seq_along(row_hclust_list)) {
886
+            for(i in seq_along(row_dend_list)) {
836 887
                 if(length(row_order_list[[i]]) > 1) {
837
-                    object@row_hclust_list[[i]] = reorder(object@row_hclust_list[[i]], reorder[which(seq_len(nrow(mat)) %in% o_row_order_list[[i]])])
838
-                    row_order_list[[i]] = o_row_order_list[[i]][ order.dendrogram(object@row_hclust_list[[i]]) ]
888
+                    object@row_dend_list[[i]] = reorder(object@row_dend_list[[i]], reorder[which(seq_len(nrow(mat)) %in% o_row_order_list[[i]])])
889
+                    row_order_list[[i]] = o_row_order_list[[i]][ order.dendrogram(object@row_dend_list[[i]]) ]
839 890
                 }
840 891
             }
841 892
         }
... ...
@@ -971,40 +1022,40 @@ setMethod(f = "make_layout",
971 1022
     }
972 1023
 
973 1024
     ##########################################
974
-    ## hclust on left or right
975
-    show_row_hclust = object@row_hclust_param$show
976
-    row_hclust_side = object@row_hclust_param$side
977
-    row_hclust_width = object@row_hclust_param$width
978
-    if(show_row_hclust) {
979
-        if(row_hclust_side == "left") {
980
-            object@layout$layout_row_hclust_left_width = row_hclust_width
1025
+    ## dend on left or right
1026
+    show_row_dend = object@row_dend_param$show
1027
+    row_dend_side = object@row_dend_param$side
1028
+    row_dend_width = object@row_dend_param$width
1029
+    if(show_row_dend) {
1030
+        if(row_dend_side == "left") {
1031
+            object@layout$layout_row_dend_left_width = row_dend_width
981 1032
             object@layout$layout_index = rbind(object@layout$layout_index, c(5, 2))
982 1033
         } else {
983
-            object@layout$layout_row_hclust_right_width = row_hclust_width
1034
+            object@layout$layout_row_dend_right_width = row_dend_width
984 1035
             object@layout$layout_index = rbind(object@layout$layout_index, c(5, 6))
985 1036
         }
986
-        #max_hclust_height = max(sapply(object@row_hclust_list, function(hc) attr(as.dendrogram(hc), "height")))
1037
+        #max_dend_height = max(sapply(object@row_dend_list, function(hc) attr(as.dendrogram(hc), "height")))
987 1038
         object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) {
988 1039
             for(i in seq_len(n_slice)) {
989
-                draw_hclust(object, k = i, which = "row", y = slice_y[i], height = slice_height[i], just = c("center", "top"))
1040
+                draw_dend(object, k = i, which = "row", y = slice_y[i], height = slice_height[i], just = c("center", "top"))
990 1041
             }
991 1042
         })
992 1043
     }
993 1044
 
994 1045
     ##########################################
995
-    ## hclust on top or bottom
996
-    show_column_hclust = object@column_hclust_param$show
997
-    column_hclust_side = object@column_hclust_param$side
998
-    column_hclust_height = object@column_hclust_param$height
999
-    if(show_column_hclust) {
1000
-        if(column_hclust_side == "top") {
1001
-            object@layout$layout_column_hclust_top_height = column_hclust_height
1046
+    ## dend on top or bottom
1047
+    show_column_dend = object@column_dend_param$show
1048
+    column_dend_side = object@column_dend_param$side
1049
+    column_dend_height = object@column_dend_param$height
1050
+    if(show_column_dend) {
1051
+        if(column_dend_side == "top") {
1052
+            object@layout$layout_column_dend_top_height = column_dend_height
1002 1053
             object@layout$layout_index = rbind(object@layout$layout_index, c(2, 4))
1003 1054
         } else {
1004
-            object@layout$layout_column_hclust_bottom_height = column_hclust_height
1055
+            object@layout$layout_column_dend_bottom_height = column_dend_height
1005 1056
             object@layout$layout_index = rbind(object@layout$layout_index, c(8, 4))
1006 1057
         }
1007
-        object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) draw_hclust(object, which = "column"))
1058
+        object@layout$graphic_fun_list = c(object@layout$graphic_fun_list, function(object) draw_dend(object, which = "column"))
1008 1059
     }
1009 1060
     
1010 1061
 
... ...
@@ -1232,7 +1283,7 @@ setMethod(f = "draw_heatmap_body",
1232 1283
 # == author
1233 1284
 # Zuguang Gu <z.gu@dkfz.de>
1234 1285
 #
1235
-setMethod(f = "draw_hclust",
1286
+setMethod(f = "draw_dend",
1236 1287
     signature = "Heatmap",
1237 1288
     definition = function(object,
1238 1289
     which = c("row", "column"), k = 1, max_height = NULL, ...) {
... ...
@@ -1240,16 +1291,16 @@ setMethod(f = "draw_hclust",
1240 1291
     which = match.arg(which)[1]
1241 1292
 
1242 1293
     side = switch(which,
1243
-        "row" = object@row_hclust_param$side,
1244
-        "column" = object@column_hclust_param$side)
1294
+        "row" = object@row_dend_param$side,
1295
+        "column" = object@column_dend_param$side)
1245 1296
     
1246 1297
     hc = switch(which,
1247
-        "row" = object@row_hclust_list[[k]],
1248
-        "column" = object@column_hclust)
1298
+        "row" = object@row_dend_list[[k]],
1299
+        "column" = object@column_dend)
1249 1300
     
1250 1301
     gp = switch(which,
1251
-        "row" = object@row_hclust_param$gp,
1252
-        "column" = object@column_hclust_param$gp)
1302
+        "row" = object@row_dend_param$gp,
1303
+        "column" = object@column_dend_param$gp)
1253 1304
 
1254 1305
     if(length(hc) == 0) {
1255 1306
         return(invisible(NULL))
... ...
@@ -1260,17 +1311,17 @@ setMethod(f = "draw_hclust",
1260 1311
     dend = as.dendrogram(hc)
1261 1312
     n = length(labels(dend))
1262 1313
 
1263
-    hclust_padding = unit(1, "mm")
1314
+    dend_padding = unit(1, "mm")
1264 1315
     pushViewport(viewport(name = paste(object@name, which, "cluster", k, sep = "_"), ...))
1265 1316
 
1266 1317
     if(side == "left") {
1267
-        grid.dendrogram(dend, name = paste(object@name, "hclust_row", k, sep = "_"), max_height = max_height, facing = "right", order = "reverse", x = hclust_padding, width = unit(1, "npc") - hclust_padding*2, just = "left")
1318
+        grid.dendrogram(dend, name = paste(object@name, "dend_row", k, sep = "_"), max_height = max_height, facing = "right", order = "reverse", x = dend_padding, width = unit(1, "npc") - dend_padding*2, just = "left")
1268 1319
     } else if(side == "right") {
1269
-        grid.dendrogram(dend, name = paste(object@name, "hclust_row", k, sep = "_"), max_height = max_height, facing = "left", order = "reverse", x = unit(0, "mm"), width = unit(1, "npc") - hclust_padding*2, just = "left")
1320
+        grid.dendrogram(dend, name = paste(object@name, "dend_row", k, sep = "_"), max_height = max_height, facing = "left", order = "reverse", x = unit(0, "mm"), width = unit(1, "npc") - dend_padding*2, just = "left")
1270 1321
     } else if(side == "top") {
1271
-        grid.dendrogram(dend, name = paste(object@name, "hclust_column", sep = "_"), max_height = max_height, facing = "bottom", y = hclust_padding, height = unit(1, "npc") - hclust_padding*2, just = "bottom")
1322
+        grid.dendrogram(dend, name = paste(object@name, "dend_column", sep = "_"), max_height = max_height, facing = "bottom", y = dend_padding, height = unit(1, "npc") - dend_padding*2, just = "bottom")
1272 1323
     } else if(side == "bottom") {
1273
-        grid.dendrogram(dend, name = paste(object@name, "hclust_column", sep = "_"), max_height = max_height, facing = "top", y = hclust_padding, height = unit(1, "npc") - hclust_padding*2, just = "bottom")
1324
+        grid.dendrogram(dend, name = paste(object@name, "dend_column", sep = "_"), max_height = max_height, facing = "top", y = dend_padding, height = unit(1, "npc") - dend_padding*2, just = "bottom")
1274 1325
     } 
1275 1326
 
1276 1327
     upViewport()
... ...
@@ -1494,7 +1545,7 @@ setMethod(f = "component_width",
1494 1545
         if(k == 1) {
1495 1546
             object@layout$layout_row_title_left_width
1496 1547
         } else if(k == 2) {
1497
-            object@layout$layout_row_hclust_left_width
1548
+            object@layout$layout_row_dend_left_width
1498 1549
         } else if(k == 3) {
1499 1550
             object@layout$layout_row_names_left_width
1500 1551
         } else if(k == 4) {
... ...
@@ -1510,7 +1561,7 @@ setMethod(f = "component_width",
1510 1561
         } else if(k == 5) {
1511 1562
             object@layout$layout_row_names_right_width
1512 1563
         } else if(k == 6) {
1513
-            object@layout$layout_row_hclust_right_width
1564
+            object@layout$layout_row_dend_right_width
1514 1565
         } else if(k == 7) {
1515 1566
             object@layout$layout_row_title_right_width
1516 1567
         } else {
... ...
@@ -1546,7 +1597,7 @@ setMethod(f = "component_height",
1546 1597
         if(k == 1) {
1547 1598
             object@layout$layout_column_title_top_height
1548 1599
         } else if(k == 2) {
1549
-            object@layout$layout_column_hclust_top_height
1600
+            object@layout$layout_column_dend_top_height
1550 1601
         } else if(k == 3) {
1551 1602
             object@layout$layout_column_anno_top_height
1552 1603
         } else if(k == 4) {
... ...
@@ -1558,7 +1609,7 @@ setMethod(f = "component_height",
1558 1609
         } else if(k == 7) {
1559 1610
             object@layout$layout_column_anno_bottom_height
1560 1611
         } else if(k == 8) {
1561
-            object@layout$layout_column_hclust_bottom_height
1612
+            object@layout$layout_column_dend_bottom_height
1562 1613
         } else if(k == 9) {
1563 1614
             object@layout$layout_column_title_bottom_height
1564 1615
         } else {
... ...
@@ -1594,7 +1645,7 @@ setMethod(f = "set_component_height",
1594 1645
     if(k == 1) {
1595 1646
         object@layout$layout_column_title_top_height = v
1596 1647
     } else if(k == 2) {
1597
-        object@layout$layout_column_hclust_top_height = v
1648
+        object@layout$layout_column_dend_top_height = v
1598 1649
     } else if(k == 3) {
1599 1650
         object@layout$layout_column_anno_top_height = v
1600 1651
     } else if(k == 4) {
... ...
@@ -1604,7 +1655,7 @@ setMethod(f = "set_component_height",
1604 1655
     } else if(k == 7) {
1605 1656
         object@layout$layout_column_anno_bottom_height = v
1606 1657
     } else if(k == 8) {
1607
-        object@layout$layout_column_hclust_bottom_height = v
1658
+        object@layout$layout_column_dend_bottom_height = v
1608 1659
     } else if(k == 9) {
1609 1660
         object@layout$layout_column_title_bottom_height = v
1610 1661
     } else {
... ...
@@ -1699,7 +1750,7 @@ setMethod(f = "prepare",
1699 1750
     if(process_rows) {
1700 1751
         object = make_row_cluster(object)
1701 1752
     }
1702
-    if(object@column_hclust_param$cluster) object = make_column_cluster(object)
1753
+    if(object@column_dend_param$cluster) object = make_column_cluster(object)
1703 1754
 
1704 1755
     object = make_layout(object)
1705 1756
     return(object)
... ...
@@ -65,10 +65,16 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
65 65
 # == author
66 66
 # Zuguang Gu <z.gu@dkfz.de>
67 67
 #
68
-HeatmapAnnotation = function(df, name, col, annotation_legend_param = list(), 
69
-	show_legend = rep(TRUE, n_anno), ..., 
70
-	which = c("column", "row"), annotation_height = 1, annotation_width = 1, 
71
-	height = calc_anno_size(), width = calc_anno_size(), gp = gpar(col = NA),
68
+HeatmapAnnotation = function(df, name, col, 
69
+	annotation_legend_param = list(), 
70
+	show_legend = rep(TRUE, n_anno), 
71
+	..., 
72
+	which = c("column", "row"), 
73
+	annotation_height = 1, 
74
+	annotation_width = 1, 
75
+	height = calc_anno_size(), 
76
+	width = calc_anno_size(), 
77
+	gp = gpar(col = NA),
72 78
 	gap = unit(0, "mm")) {
73 79
 
74 80
 	.Object = new("HeatmapAnnotation")
... ...
@@ -180,7 +180,8 @@ setMethod(f = "add_heatmap",
180 180
 # -annotation_legend_list a list of self-defined legend, should be wrapped into `grid::grob` objects.
181 181
 # -gap gap between heatmaps, should be a `grid::unit` object.
182 182
 # -main_heatmap name or index for the main heatmap
183
-# -row_hclust_side if auto adjust, where to put the row dendrograms for the main heatmap
183
+# -row_dend_side if auto adjust, where to put the row dendrograms for the main heatmap
184
+# -row_hclust_side deprecated, use ``row_dend_side`` instead
184 185
 # -row_sub_title_side if auto adjust, where to put sub row titles for the main heatmap
185 186
 #
186 187
 # == detail
... ...
@@ -199,16 +200,21 @@ setMethod(f = "add_heatmap",
199 200
 setMethod(f = "make_layout",
200 201
     signature = "HeatmapList",
201 202
     definition = function(object, row_title = character(0), 
202
-    row_title_side = c("left", "right"), row_title_gp = gpar(fontsize = 14),
203
-    column_title = character(0), column_title_side = c("top", "bottom"), 
203
+    row_title_side = c("left", "right"), 
204
+    row_title_gp = gpar(fontsize = 14),
205
+    column_title = character(0), 
206
+    column_title_side = c("top", "bottom"), 
204 207
     column_title_gp = gpar(fontsize = 14), 
205 208
     heatmap_legend_side = c("right", "left", "bottom", "top"), 
206
-    show_heatmap_legend = TRUE, heatmap_legend_list = list(),
209
+    show_heatmap_legend = TRUE, 
210
+    heatmap_legend_list = list(),
207 211
     annotation_legend_side = c("right", "left", "bottom", "top"), 
208
-    show_annotation_legend = TRUE, annotation_legend_list = list(),
212
+    show_annotation_legend = TRUE, 
213
+    annotation_legend_list = list(),
209 214
     gap = unit(3, "mm"), 
210 215
     main_heatmap = which(sapply(object@ht_list, inherits, "Heatmap"))[1],
211
-    row_hclust_side = c("original", "left", "right"),
216
+    row_dend_side = c("original", "left", "right"),
217
+    row_hclust_side = row_dend_side,
212 218
     row_sub_title_side = c("original", "left", "right")) {
213 219
 
214 220
     if(object@layout$initialized) {
... ...
@@ -265,12 +271,20 @@ setMethod(f = "make_layout",
265 271
     ht_main = make_row_cluster(ht_main)  # with pre-defined order
266 272
     object@ht_list[[i_main]] = ht_main
267 273
 
268
-    row_hclust_side = match.arg(row_hclust_side)[1]
274
+    called_args = names(as.list(match.call())[-1])
275
+    if("row_hclust_side" %in% called_args) {
276
+        if(!'row_dend_side' %in% called_args) {
277
+            row_dend_side = row_hclust_side
278
+            warning("'row_hclust_side' is deprecated in the future, use 'row_dend_side' instead.")
279
+        }
280
+    }
281
+
282
+    row_dend_side = match.arg(row_dend_side)[1]
269 283
     row_sub_title_side = match.arg(row_sub_title_side)[1]
270 284
 
271
-    if(row_hclust_side == "left" || row_sub_title_side == "left") {
285
+    if(row_dend_side == "left" || row_sub_title_side == "left") {
272 286
         # if the first one is a HeatmapAnnotation object
273
-        # add a heatmap with zero column so that we can put titles and hclust on the most left
287
+        # add a heatmap with zero column so that we can put titles and dend on the most left
274 288
         if(inherits(object@ht_list[[1]], "HeatmapAnnotation")) {
275 289
             object = Heatmap(matrix(nrow = nr, ncol = 0)) + object
276 290
             gap = unit.c(unit(0, "mm"), gap)
... ...
@@ -279,7 +293,7 @@ setMethod(f = "make_layout",
279 293
             
280 294
     }
281 295
 
282
-    if(row_hclust_side == "right" || row_sub_title_side == "right") {
296
+    if(row_dend_side == "right" || row_sub_title_side == "right") {
283 297
         # if the last one is a HeatmapAnnotation object
284 298
         if(inherits(object@ht_list[[ length(object@ht_list) ]], "HeatmapAnnotation")) {
285 299
             object = object + Heatmap(matrix(nrow = nr, ncol = 0))
... ...
@@ -300,7 +314,7 @@ setMethod(f = "make_layout",
300 314
         if(inherits(object@ht_list[[i]], "Heatmap")) {
301 315
             object@ht_list[[i]]@row_order_list = ht_main@row_order_list
302 316
             object@ht_list[[i]]@row_order = ht_main@row_order
303
-            object@ht_list[[i]]@row_hclust_param$cluster = FALSE  # don't do clustering because cluster was already done
317
+            object@ht_list[[i]]@row_dend_param$cluster = FALSE  # don't do clustering because cluster was already done
304 318
         }
305 319
     }
306 320
 
... ...
@@ -317,21 +331,21 @@ setMethod(f = "make_layout",
317 331
     for(i in seq_len(n)) {
318 332
         if(i != i_main) {
319 333
             if(inherits(object@ht_list[[i]], "Heatmap")) {
320
-                object@ht_list[[i]]@row_hclust_param$show = FALSE
334
+                object@ht_list[[i]]@row_dend_param$show = FALSE
321 335
             }
322 336
         }
323 337
     }
324
-    if(row_hclust_side == "left") {
325
-        # move hclust to the first one
326
-        object@ht_list[[i_main]]@row_hclust_param$show = FALSE
327
-        object@ht_list[[1]]@row_hclust_list = ht_main@row_hclust_list
328
-        object@ht_list[[1]]@row_hclust_param = ht_main@row_hclust_param
329
-        object@ht_list[[1]]@row_hclust_param$side = "left"
330
-    } else if(row_hclust_side == "right") {
331
-        object@ht_list[[i_main]]@row_hclust_param$show = FALSE
332
-        object@ht_list[[n]]@row_hclust_list = ht_main@row_hclust_list
333
-        object@ht_list[[n]]@row_hclust_param = ht_main@row_hclust_param
334
-        object@ht_list[[n]]@row_hclust_param$side = "right"
338
+    if(row_dend_side == "left") {
339
+        # move dend to the first one
340
+        object@ht_list[[i_main]]@row_dend_param$show = FALSE
341
+        object@ht_list[[1]]@row_dend_list = ht_main@row_dend_list
342
+        object@ht_list[[1]]@row_dend_param = ht_main@row_dend_param
343
+        object@ht_list[[1]]@row_dend_param$side = "left"
344
+    } else if(row_dend_side == "right") {
345
+        object@ht_list[[i_main]]@row_dend_param$show = FALSE
346
+        object@ht_list[[n]]@row_dend_list = ht_main@row_dend_list
347
+        object@ht_list[[n]]@row_dend_param = ht_main@row_dend_param
348
+        object@ht_list[[n]]@row_dend_param$side = "right"
335 349
     }
336 350
 
337 351
     # adjust row subtitles
... ...
@@ -558,8 +572,8 @@ setMethod(f = "make_layout",
558 572
 # == param
559 573
 # -object a `HeatmapList-class` object
560 574
 # -padding padding of the plot. Elements correspond to bottom, left, top, right paddings.
575
+# -newpage whether create a new page for the graphics.
561 576
 # -... pass to `make_layout,HeatmapList-method`
562
-# -newpage whether to create a new page
563 577
 #
564 578
 # == detail
565 579
 # The function first calls `make_layout,HeatmapList-method` to calculate
... ...
@@ -575,8 +589,10 @@ setMethod(f = "make_layout",
575 589
 #
576 590
 setMethod(f = "draw",
577 591
     signature = "HeatmapList",
578
-    definition = function(object, padding = unit(c(2, 2, 2, 2), "mm"), ..., 
579
-        newpage= TRUE) {
592
+    definition = function(object, 
593
+        padding = unit(c(2, 2, 2, 2), "mm"), 
594
+        newpage = TRUE,
595
+        ...) {
580 596
 
581 597
     l = sapply(object@ht_list, inherits, "Heatmap")
582 598
     if(! any(l)) {
... ...
@@ -616,6 +632,12 @@ setMethod(f = "draw",
616 632
 
617 633
     .LAST_HT_LIST$object = object
618 634
 
635
+    for(i in seq_along(.LAST_HT_LIST$object@ht_list)) {
636
+        if(inherits(.LAST_HT_LIST$object@ht_list[[i]], "Heatmap")) {
637
+            .LAST_HT_LIST$object@ht_list[[i]]@matrix = matrix(nr = 0, nc = 0)
638
+        }
639
+    }
640
+
619 641
 
620 642
     return(invisible(object))
621 643
 })
... ...
@@ -1272,8 +1294,3 @@ setMethod(f = "show",
1272 1294
 })
1273 1295
 
1274 1296
 
1275
-compare_unit = function(u1, u2) {
1276
-    u1 = convertUnit(u1, "cm", valueOnly = TRUE)
1277
-    u2 = convertUnit(u2, "cm", valueOnly = TRUE)
1278
-    ifelse(u1 > u2, 1, ifelse(u1 < u2, -1, 0))
1279
-}
... ...
@@ -18,7 +18,9 @@ setMethod(f = "row_order",
18 18
 	for(i in seq_len(n)) {
19 19
         if(inherits(object@ht_list[[i]], "Heatmap")) {
20 20
         	lt = object@ht_list[[i]]@row_order_list
21
-        	names(lt) = object@ht_list[[i]]@row_title
21
+        	if(length(object@ht_list[[i]]@row_title) > 0) {
22
+        		names(lt) = object@ht_list[[i]]@row_title
23
+        	}
22 24
         	return(lt)
23 25
         }
24 26
     }
... ...
@@ -43,7 +45,9 @@ setMethod(f = "row_order",
43 45
 	object = prepare(object)
44 46
 
45 47
 	lt = object@row_order_list
46
-	names(lt) = object@row_title
48
+	if(length(object@row_title) > 0) {
49
+		names(lt) = object@row_title
50
+	}
47 51
 	return(lt)
48 52
 	
49 53
 })
... ...
@@ -115,8 +119,10 @@ setMethod(f = "row_dend",
115 119
 	n = length(object@ht_list)
116 120
     for(i in seq_len(n)) {
117 121
         if(inherits(object@ht_list[[i]], "Heatmap")) {
118
-        	lt = object@ht_list[[i]]@row_hclust_list
119
-        	names(lt) = object@ht_list[[i]]@row_title
122
+        	lt = object@ht_list[[i]]@row_dend_list
123
+        	if(length(object@ht_list[[i]]@row_title) > 0) {
124
+        		names(lt) = object@ht_list[[i]]@row_title
125
+        	}
120 126
         	return(lt)
121 127
         }
122 128
     }
... ...
@@ -139,8 +145,10 @@ setMethod(f = "row_dend",
139 145
 
140 146
 	object = prepare(object)
141 147
 
142
-	lt = object@row_hclust_list
143
-	names(lt) = object@row_title
148
+	lt = object@row_dend_list
149
+	if(length(object@row_title) > 0) {
150
+		names(lt) = object@row_title
151
+	}
144 152
 	return(lt)
145 153
 })
146 154
 
... ...
@@ -167,7 +175,7 @@ setMethod(f = "column_dend",
167 175
     for(i in seq_len(n)) {
168 176
         if(inherits(object@ht_list[[i]], "HeatmapAnnotation")) {
169 177
         } else {
170
-            dend_list[[i]] = object@ht_list[[i]]@column_hclust
178
+            dend_list[[i]] = object@ht_list[[i]]@column_dend
171 179
         }
172 180
     }
173 181
 
... ...
@@ -189,6 +197,6 @@ setMethod(f = "column_dend",
189 197
 
190 198
 	object = prepare(object)
191 199
 
192
-	return(object@column_hclust)
200
+	return(object@column_dend)
193 201
 })
194 202
 
... ...
@@ -81,8 +81,11 @@ SingleAnnotation = setClass("SingleAnnotation",
81 81
 # == author
82 82
 # Zuguang Gu <z.gu@dkfz.de>
83 83
 #
84
-SingleAnnotation = function(name, value, col, fun, which = c("column", "row"), 
85
-	show_legend = TRUE, gp = gpar(col = NA), legend_param = list()) {
84
+SingleAnnotation = function(name, value, col, fun, 
85
+	which = c("column", "row"), 
86
+	show_legend = TRUE, 
87
+	gp = gpar(col = NA), 
88
+	legend_param = list()) {
86 89
 
87 90
 	# re-define some of the argument values according to global settings
88 91
     called_args = names(as.list(match.call())[-1])
... ...
@@ -633,6 +633,12 @@ anno_text = function(x, which = c("column", "row"), gp = gpar(), rot = 0,
633 633
 # == details
634 634
 # A wrapper of `anno_points` with pre-defined ``which`` to ``row``.
635 635
 #
636
+# == value
637
+# See help page of `anno_points`
638
+#
639
+# == author
640
+# Zuguang Gu <z.gu@dkfz.de>
641
+#
636 642
 row_anno_points = function(...) {
637 643
 	anno_points(..., which = "row")
638 644
 }
... ...
@@ -646,6 +652,12 @@ row_anno_points = function(...) {
646 652
 # == details
647 653
 # A wrapper of `anno_points` with pre-defined ``which`` to ``column``.
648 654
 #
655
+# == value
656
+# See help page of `anno_points`
657
+#
658
+# == author
659
+# Zuguang Gu <z.gu@dkfz.de>
660
+#
649 661
 column_anno_points = function(...) {
650 662
 	anno_points(..., which = "column")
651 663
 }
... ...
@@ -659,6 +671,12 @@ column_anno_points = function(...) {
659 671
 # == details
660 672
 # A wrapper of `anno_barplot` with pre-defined ``which`` to ``row``.
661 673
 #
674
+# == value
675
+# See help page of `anno_barplot`
676
+#
677
+# == author
678
+# Zuguang Gu <z.gu@dkfz.de>
679
+#
662 680
 row_anno_barplot = function(...) {
663 681
 	anno_barplot(..., which = "row")
664 682
 }
... ...
@@ -672,6 +690,12 @@ row_anno_barplot = function(...) {
672 690
 # == details
673 691
 # A wrapper of `anno_barplot` with pre-defined ``which`` to ``column``.
674 692
 #
693
+# == value
694
+# See help page of `anno_barplot`
695
+#
696
+# == author
697
+# Zuguang Gu <z.gu@dkfz.de>
698
+#
675 699
 column_anno_barplot = function(...) {
676 700
 	anno_barplot(..., which = "column")
677 701
 }
... ...
@@ -685,6 +709,12 @@ column_anno_barplot = function(...) {
685 709
 # == details
686 710
 # A wrapper of `anno_boxplot` with pre-defined ``which`` to ``row``.
687 711
 #
712
+# == value
713
+# See help page of `anno_boxplot`
714
+#
715
+# == author
716
+# Zuguang Gu <z.gu@dkfz.de>
717
+#
688 718
 row_anno_boxplot = function(...) {
689 719
 	anno_boxplot(..., which = "row")
690 720
 }
... ...
@@ -698,6 +728,12 @@ row_anno_boxplot = function(...) {
698 728
 # == details
699 729
 # A wrapper of `anno_boxplot` with pre-defined ``which`` to ``column``.
700 730
 #
731
+# == value
732
+# See help page of `anno_boxplot`
733
+#
734
+# == author
735
+# Zuguang Gu <z.gu@dkfz.de>
736
+#
701 737
 column_anno_boxplot = function(...) {
702 738
 	anno_boxplot(..., which = "column")
703 739
 }
... ...
@@ -711,6 +747,12 @@ column_anno_boxplot = function(...) {
711 747
 # == details
712 748
 # A wrapper of `anno_histogram` with pre-defined ``which`` to ``row``.
713 749
 #
750
+# == value
751
+# See help page of `anno_histogram`
752
+#
753
+# == author
754
+# Zuguang Gu <z.gu@dkfz.de>
755
+#
714 756
 row_anno_histogram = function(...) {
715 757
 	anno_histogram(..., which = "row")
716 758
 }
... ...
@@ -724,6 +766,12 @@ row_anno_histogram = function(...) {
724 766
 # == details
725 767
 # A wrapper of `anno_histogram` with pre-defined ``which`` to ``column``.
726 768
 #
769
+# == value
770
+# See help page of `anno_histogram`
771
+#
772
+# == author
773
+# Zuguang Gu <z.gu@dkfz.de>
774
+#
727 775
 column_anno_histogram = function(...) {
728 776
 	anno_histogram(..., which = "column")
729 777
 }
... ...
@@ -737,6 +785,12 @@ column_anno_histogram = function(...) {
737 785
 # == details
738 786
 # A wrapper of `anno_density` with pre-defined ``which`` to ``row``.
739 787
 #
788
+# == value
789
+# See help page of `anno_density`
790
+#
791
+# == author
792
+# Zuguang Gu <z.gu@dkfz.de>
793
+#
740 794
 row_anno_density = function(...) {
741 795
 	anno_density(..., which = "row")
742 796
 }
... ...
@@ -750,6 +804,12 @@ row_anno_density = function(...) {
750 804
 # == details
751 805
 # A wrapper of `anno_density` with pre-defined ``which`` to ``column``.
752 806
 #
807
+# == value
808
+# See help page of `anno_density`
809
+#
810
+# == author
811
+# Zuguang Gu <z.gu@dkfz.de>
812
+#
753 813
 column_anno_density = function(...) {
754 814
 	anno_density(..., which = "column")
755 815
 }
... ...
@@ -763,6 +823,12 @@ column_anno_density = function(...) {
763 823
 # == details
764 824
 # A wrapper of `anno_text` with pre-defined ``which`` to ``row``.
765 825
 #
826
+# == value
827
+# See help page of `anno_text`
828
+#
829
+# == author
830
+# Zuguang Gu <z.gu@dkfz.de>
831
+#
766 832
 row_anno_text = function(...) {
767 833
 	anno_text(..., which = "row")
768 834
 }
... ...
@@ -776,6 +842,12 @@ row_anno_text = function(...) {
776 842
 # == details
777 843
 # A wrapper of `anno_text` with pre-defined ``which`` to ``column``.
778 844
 #
845
+# == value
846
+# See help page of `anno_text`
847
+#
848
+# == author
849
+# Zuguang Gu <z.gu@dkfz.de>
850
+#
779 851
 column_anno_text = function(...) {
780 852
 	anno_text(..., which = "column")
781 853
 }
... ...
@@ -3,14 +3,34 @@
3 3
 #
4 4
 # == param
5 5
 # -heatmap name of the heatmap
6
-# -code code that is executed in the heatmap body
6
+# -code code that adds graphics in the selected heatmap body
7 7
 # -slice index of row slices in the heatmap
8 8
 #
9 9
 # == details
10
-# This simple function actually contructs the name of the viewport,
10
+# There is a viewport for each row slice in each heatmap.
11
+# This function contructs the name of the viewport,
11 12
 # goes to the viewport by `grid::seekViewport` and applies code
12 13
 # to that viewport.
13 14
 #
15
+# Since you know the number of rows and columns for that row slice, it is
16
+# simple to calculate the position of every small grid in the row slice.
17
+# E.g., the position for the grid in i^th row and j^th column is:
18
+#
19
+#     # assume nc is the number of columns 
20
+#     # and nr is the number of rows in that row slice
21
+#     unit((i-0.5)/nc, "npc")
22
+#     unit((j-0.5)/nr, "npc")
23
+#
24
+#     # the width is
25
+#     unit(1/nc, "npc")
26
+#
27
+#     # the height is
28
+#     unit(1/nr, "npc")
29
+#
30
+#
31
+# == value
32
+# This function returns no value.
33
+#
14 34
 # == author
15 35
 # Zuguang Gu <z.gu@dkfz.de>
16 36
 #
... ...
@@ -21,7 +41,7 @@
21 41
 #     grid.circle(gp = gpar(fill = "#FF000080"))
22 42
 # })
23 43
 #
24
-decorate_heatmap_body = function(heatmap, code = {}, slice = 1) {
44
+decorate_heatmap_body = function(heatmap, code, slice = 1) {
25 45
 
26 46
 	vp_name = paste0(heatmap, "_heatmap_body_", slice)
27 47
 
... ...
@@ -37,32 +57,44 @@ decorate_heatmap_body = function(heatmap, code = {}, slice = 1) {
37 57
 #
38 58
 # == param
39 59
 # -heatmap name of the heatmap
40
-# -code code that is executed in the heatmap body
60
+# -code code that adds graphics in the selected heatmap body
41 61
 # -slice index of row slices in the heatmap
42 62
 # -which on rows or on columns?
43 63
 #
44 64
 # == details
45
-# This simple function actually contructs the name of the viewport,
65
+# There is a viewport for each dendrogram in the heatmap.
66
+# This function contructs the name of the viewport,
46 67
 # goes to the viewport by `grid::seekViewport` and applies code
47 68
 # to that viewport.
48 69
 #
70
+# Since you know the number of leaves in the dendrogram, it is
71
+# simple to calculate the position of every leave in the dendrogram.
72
+# E.g., for the column dendrogram, the i^th leave is located at:
73
+#
74
+#     # assume nc is the number of columns 
75
+#     unit((i-0.5)/nc, "npc")
76
+#
77
+#
78
+# == value
79
+# This function returns no value.
80
+#
49 81
 # == author
50 82
 # Zuguang Gu <z.gu@dkfz.de>
51 83
 #
52 84
 # == example
53 85
 # set.seed(123)
54 86
 # Heatmap(matrix(rnorm(100), 10), name = "mat", km = 2)
55
-# decorate_hclust("mat", {
87
+# decorate_dend("mat", {
56 88
 #     grid.rect(gp = gpar(fill = "#FF000080"))
57 89
 # }, which = "row", slice = 2)
58 90
 #
59
-decorate_hclust = function(heatmap, code, slice = 1, which = c("column", "row")) {
91
+decorate_dend = function(heatmap, code, slice = 1, which = c("column", "row")) {
60 92
 	
61 93
 	which = match.arg(which)[1]
62 94
 	if(which == "column") {
63
-		vp_name = paste0(heatmap, "_hclust_", which)
95
+		vp_name = paste0(heatmap, "_dend_", which)
64 96
 	} else if(which == "row") {
65
-		vp_name = paste0(heatmap, "_hclust_", which, "_", slice)
97
+		vp_name = paste0(heatmap, "_dend_", which, "_", slice)
66 98
 	}
67 99
 
68 100
 	seekViewport(vp_name)
... ...
@@ -76,26 +108,46 @@ decorate_hclust = function(heatmap, code, slice = 1, which = c("column", "row"))
76 108
 # Decorate heatmap dendrogram on columns
77 109
 #
78 110
 # == param
79
-# -... pass to `decorate_hclust`
111
+# -... pass to `decorate_dend`
80 112
 #
81