Browse code

add test script for the heatmap annotation size

jokergoo authored on 15/03/2019 13:47:43
Showing42 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 ^\..*
2 2
 README.*
3
-tests/
3
+tests_not_run/
4 4
 check.bat
5 5
 ^.*\.Rproj$
6 6
 ^\.Rproj\.user$
... ...
@@ -1,14 +1,14 @@
1 1
 Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Make Complex Heatmaps
4
-Version: 1.99.5
5
-Date: 2019-02-12
4
+Version: 1.99.6
5
+Date: 2019-03-15
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
9 9
 Imports: circlize (>= 0.4.5), GetoptLong, colorspace,
10 10
     RColorBrewer, GlobalOptions (>= 0.1.0), parallel
11
-Suggests: testthat (>= 0.3), knitr, markdown, dendsort, 
11
+Suggests: testthat (>= 1.0.0), knitr, markdown, dendsort, 
12 12
     Cairo, png, jpeg, tiff, fastcluster,
13 13
     dendextend (>= 1.0.1), grImport, grImport2, glue
14 14
 VignetteBuilder: knitr
... ...
@@ -265,8 +265,9 @@ importFrom("circlize", rand_color)
265 265
 importFrom("circlize", smartAlign)
266 266
 importFrom("colorspace", diverge_hcl)
267 267
 importFrom("colorspace", rainbow_hcl)
268
+importFrom("parallel", "mclapply")
268 269
 importFrom("utils", "combn")
269 270
 importFrom("utils", "getFromNamespace")
270 271
 importFrom("utils", "packageDescription")
271 272
 importFrom("utils", "str")
272
-importFrom("parallel", "mclapply")
273
+
... ...
@@ -1,3 +1,9 @@
1
+CHANGES in VERSION 1.99.6
2
+
3
+* adjust the size of heatmap annotations and add testing scripts
4
+
5
+========================
6
+
1 7
 CHANGES in VERSION 1.99.5
2 8
 
3 9
 * add `UpSet()` and some related functions to make Upset plots
... ...
@@ -1,31 +1,31 @@
1
-setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
2
-setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
3
-setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
4
-setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
5
-setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
6
-setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
7
-setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
8
-setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
9
-setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
1
+setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
2
+setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
10 3
 setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
11
-setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
4
+setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
5
+setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
6
+setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
7
+setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
12 8
 setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
13
-setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
14
-setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
15
-setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
16
-setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
17
-setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
18
-setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
9
+setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
19 10
 setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
20
-setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
21
-setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
22
-setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
23
-setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
11
+setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
12
+setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
13
+setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
24 14
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
25 15
 setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
26
-setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
16
+setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
27 17
 setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
28
-setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
29
-setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
18
+setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
19
+setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
20
+setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
21
+setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
22
+setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
23
+setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
24
+setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
25
+setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
26
+setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
30 27
 setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
31
-setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
28
+setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
29
+setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
30
+setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
31
+setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
... ...
@@ -126,7 +126,7 @@ subset_vector = function(x, i) x[i]
126 126
 #          only be a single value.
127 127
 # -pt_gp Graphic parameters for points/symbols. The length setting is same as ``pt_size``.
128 128
 #     If ``pch`` is set as letters, the fontsize should be set as ``pt_gp = gpar(fontsize = ...)``.
129
-# -anno_simple_size size of the simple annotation.
129
+# -simple_anno_size size of the simple annotation.
130 130
 # -width Width of the annotation. The value should be an absolute unit. Width is not allowed to be set for column annotation.
131 131
 # -height Height of the annotation. The value should be an absolute unit. Height is not allowed to be set for row annotation.
132 132
 #
... ...
@@ -162,7 +162,7 @@ subset_vector = function(x, i) x[i]
162 162
 anno_simple = function(x, col, na_col = "grey", 
163 163
 	which = c("column", "row"), border = FALSE, gp = gpar(col = NA),
164 164
 	pch = NULL, pt_size = unit(1, "snpc")*0.8, pt_gp = gpar(), 
165
-	anno_simple_size = ht_opt$anno_simple_size,
165
+	simple_anno_size = ht_opt$simple_anno_size,
166 166
 	width = NULL, height = NULL) {
167 167
 
168 168
 	if(is.null(.ENV$current_annotation_which)) {
... ...
@@ -180,7 +180,7 @@ anno_simple = function(x, col, na_col = "grey",
180 180
 	input_is_matrix = is.matrix(x)
181 181
 
182 182
 	anno_size = anno_width_and_height(which, width, height, 
183
-		anno_simple_size*ifelse(input_is_matrix, ncol(x), 1))
183
+		simple_anno_size*ifelse(input_is_matrix, ncol(x), 1))
184 184
 	
185 185
 	if(missing(col)) {
186 186
 		col = default_col(x)
... ...
@@ -26,14 +26,16 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
26 26
 		height = "ANY",  
27 27
 		gap = "ANY",
28 28
 		subsetable = "logical",
29
-		extended = "ANY"
29
+		extended = "ANY",
30
+		param = "list"
30 31
 	),
31 32
 	prototype = list(
32 33
 		anno_list = list(),
33 34
 		which = "column",
34 35
 		gap = unit(0, "mm"),
35 36
 		subsetable = FALSE,
36
-		extended = unit(c(0, 0, 0, 0), "mm")
37
+		extended = unit(c(0, 0, 0, 0), "mm"),
38
+		param = list()
37 39
 	),
38 40
     contains = "AdditiveUnit"
39 41
 )
... ...
@@ -65,7 +67,7 @@ HeatmapAnnotation = setClass("HeatmapAnnotation",
65 67
 # -annotation_width Width of each annotation if annotations are row annotations.
66 68
 # -height Height of the whole column annotations.
67 69
 # -width Width of the whole heatmap annotations.
68
-# -anno_simple_size Size of the simple annotation.
70
+# -simple_anno_size Size of the simple annotation.
69 71
 # -simple_anno_size_adjust Whether also adjust the size of simple annotations when adjusting the whole heatmap annotation.
70 72
 #
71 73
 # == details
... ...
@@ -109,12 +111,17 @@ HeatmapAnnotation = function(...,
109 111
 	annotation_width = NULL, 
110 112
 	height = NULL,
111 113
 	width = NULL,
112
-	anno_simple_size = ht_opt$anno_simple_size,
114
+	simple_anno_size = ht_opt$simple_anno_size,
113 115
 	simple_anno_size_adjust = FALSE
114 116
 	) {
115 117
 
116 118
 	dev.null()
117 119
 
120
+	is_height_set = !missing(height)
121
+	is_width_set = !missing(width)
122
+	is_annotation_height_set = !missing(annotation_height)
123
+	is_annotation_width_set = !missing(annotation_width)
124
+
118 125
 	.ENV$current_annotation_which = NULL
119 126
 	which = match.arg(which)[1]
120 127
 	.ENV$current_annotation_which = which
... ...
@@ -198,6 +205,10 @@ HeatmapAnnotation = function(...,
198 205
     n_simple_anno = sum(l_simple_anno)
199 206
     simple_anno_name = names(anno_value_list[l_simple_anno])
200 207
 
208
+    if("anno_simple_size" %in% names(anno_value_list)) {
209
+    	stop_wrap("Please use `simple_anno_size` as the argument.")
210
+    }
211
+
201 212
     if(verbose) qqcat("in total there are @{length(anno_value_list)} annotations (@{n_simple_anno} simple annotations)\n")
202 213
 	
203 214
     # normalize `show_legend`
... ...
@@ -318,7 +329,7 @@ HeatmapAnnotation = function(...,
318 329
 			arg_list$legend_param = annotation_legend_param[[i_simple + 1]]
319 330
 			arg_list$value = anno_value_list[[ag]]
320 331
 			arg_list$na_col = na_col
321
-			# arg_list$anno_simple_size = anno_simple_size
332
+			arg_list$simple_anno_size = simple_anno_size
322 333
 			if(missing(col)) {
323 334
 				anno_list[[ag]] = do.call(SingleAnnotation, arg_list)
324 335
 		    } else {
... ...
@@ -361,6 +372,8 @@ HeatmapAnnotation = function(...,
361 372
 
362 373
 
363 374
 	if(is.null(gap)) gap = unit(0, "mm")
375
+	if(identical(gap, 0)) gap = unit(0, "mm")
376
+	if(!inherits(gap, "unit")) stop_wrap("`gap` needs to be a unit object.")
364 377
 
365 378
 	# the nth gap does not really matter
366 379
     if(length(gap) == 1) {
... ...
@@ -428,14 +441,20 @@ HeatmapAnnotation = function(...,
428 441
     	}))
429 442
     }
430 443
     .Object@extended = extended
444
+    .Object@param = list(
445
+    	simple_anno_size = simple_anno_size, 
446
+    	simple_anno_size_adjust = simple_anno_size_adjust,
447
+    	is_height_set = is_height_set,
448
+    	is_width_set = is_width_set,
449
+    	is_annotation_height_set = is_annotation_height_set,
450
+    	is_annotation_width_set = is_annotation_width_set
451
+    )
431 452
 
432 453
     ## adjust height/width if `width`/`annotation_width` is set
433 454
     if(which == "column") {
434
-	    .Object = re_size(.Object, height = height, annotation_height = annotation_height,
435
-	    	anno_simple_size = anno_simple_size, simple_anno_size_adjust = simple_anno_size_adjust)
455
+	    .Object = re_size(.Object, height = height, annotation_height = annotation_height)
436 456
 	} else {
437
-		.Object = re_size(.Object, width = width, annotation_width = annotation_width, 
438
-			anno_simple_size = anno_simple_size, simple_anno_size_adjust = simple_anno_size_adjust)
457
+		.Object = re_size(.Object, width = width, annotation_width = annotation_width)
439 458
 	}
440 459
 
441 460
     return(.Object)
... ...
@@ -1015,7 +1034,7 @@ length.HeatmapAnnotation = function(x) {
1015 1034
 # -annotation_width A vector of of annotation widths in `grid::unit` class.
1016 1035
 # -height The height of the complete heatmap annotation.
1017 1036
 # -width The width of the complete heatmap annotation.
1018
-# -anno_simple_size The size of one line of the simple annotation.
1037
+# -simple_anno_size The size of one line of the simple annotation.
1019 1038
 # -simple_anno_size_adjust Whether adjust the size of the simple annotation?
1020 1039
 #
1021 1040
 # == details
... ...
@@ -1027,10 +1046,10 @@ length.HeatmapAnnotation = function(x) {
1027 1046
 #    ``annotation_height`` are absolute units, ``height`` is ignored.
1028 1047
 # 2. If ``annotation_height`` contains non-absolute units, ``height`` also need to be set and the
1029 1048
 #    non-absolute units should be set in a simple form such as 1:10 or ``unit(1, "null")``.
1030
-# 3. ``anno_simple_size`` is only used when ``annotation_height`` is NULL.
1049
+# 3. ``simple_anno_size`` is only used when ``annotation_height`` is NULL.
1031 1050
 # 4. If only ``height`` is set, non-simple annotation is adjusted while keeps simple anntation unchanged.
1032 1051
 # 5. If only ``height`` is set and all annotations are simple annotations, all anntations are adjusted,
1033
-#      and ``anno_simple_size`` is disabled.
1052
+#      and ``simple_anno_size`` is disabled.
1034 1053
 # 6. If ``simple_anno_size_adjust`` is ``FALSE``, the size of the simple annotations will not change.
1035 1054
 #
1036 1055
 setMethod(f = "re_size",
... ...
@@ -1040,17 +1059,17 @@ setMethod(f = "re_size",
1040 1059
 	annotation_width = NULL,
1041 1060
 	height = NULL, 
1042 1061
 	width = NULL, 
1043
-	anno_simple_size = ht_opt$anno_simple_size,
1044
-	simple_anno_size_adjust = NULL) {
1062
+	simple_anno_size = object@param$simple_anno_size,
1063
+	simple_anno_size_adjust = object@param$simple_anno_size_adjust) {
1045 1064
 
1046 1065
 	if(object@which == "column") {
1047 1066
 		if(!missing(width) || !missing(annotation_width)) {
1048
-			stop_wrap("Please use ComplexHeatmap:::width() directly")
1067
+			stop_wrap("You cannot set the width of the column annotations.")
1049 1068
 		}
1050 1069
 	}
1051 1070
 	if(object@which == "colrowumn") {
1052 1071
 		if(!missing(height) || !missing(annotation_height)) {
1053
-			stop_wrap("Please use ComplexHeatmap:::height() directly")
1072
+			stop_wrap("You cannot set the height of the row annotations.")
1054 1073
 		}
1055 1074
 	}
1056 1075
 
... ...
@@ -1078,7 +1097,6 @@ setMethod(f = "re_size",
1078 1097
 			return(object)
1079 1098
 		}
1080 1099
 	}
1081
-
1082 1100
 	if(which == "column") {
1083 1101
 		if(is.null(height)) {
1084 1102
 			is_size_set = FALSE
... ...
@@ -1106,7 +1124,7 @@ setMethod(f = "re_size",
1106 1124
 				if(length(object@anno_list) == 1 && !inherits(annotation_height, "unit")) {
1107 1125
 					stop_wrap("When there is only one annotation, `annotation_height` should be set as a unit object.")
1108 1126
 				}
1109
-				if(!inherits(height, "unit")) {
1127
+				if(!inherits(height, "unit") || !object@param$is_height_set) {
1110 1128
 					height = annotation_height[1]
1111 1129
 				}
1112 1130
 				if(!inherits(height, "unit")) {
... ...
@@ -1151,7 +1169,7 @@ setMethod(f = "re_size",
1151 1169
 				if(length(object@anno_list) == 1 && !inherits(annotation_width, "unit")) {
1152 1170
 					stop_wrap("When there is only one annotation, `annotation_width` should be set as a unit object.")
1153 1171
 				}
1154
-				if(!inherits(width, "unit")) {
1172
+				if(!inherits(width, "unit") || !object@param$is_width_set) {
1155 1173
 					width = annotation_width[1]
1156 1174
 				}
1157 1175
 				if(!inherits(width, "unit")) {
... ...
@@ -1260,10 +1278,14 @@ setMethod(f = "re_size",
1260 1278
 	} else {
1261 1279
 		size = convertUnitFun(size, "mm", valueOnly = TRUE)
1262 1280
 		anno_size = convertUnitFun(anno_size, "mm", valueOnly = TRUE)
1263
-	
1264
-		l_simple_anno = sapply(seq_len(n), function(i) {
1265
-			!is.null(object@anno_list[[i]]@color_mapping)
1266
-		})
1281
+		
1282
+		if(simple_anno_size_adjust) {
1283
+			l_simple_anno = rep(FALSE, n)
1284
+		} else {
1285
+			l_simple_anno = sapply(seq_len(n), function(i) {
1286
+				!is.null(object@anno_list[[i]]@color_mapping)
1287
+			})
1288
+		}
1267 1289
 
1268 1290
 		if(all(l_simple_anno)) {
1269 1291
 			anno_size2 = anno_size/sum(anno_size) * (size_adjusted - sum(gap))
... ...
@@ -1273,22 +1295,21 @@ setMethod(f = "re_size",
1273 1295
 
1274 1296
 			anno_size2 = anno_size
1275 1297
 			# size_adjusted = convertUnitFun(size_adjusted, "mm", valueOnly = TRUE)
1276
-			if(is.null(anno_simple_size)) {
1277
-				anno_simple_size = 5
1298
+			if(is.null(simple_anno_size)) {
1299
+				simple_anno_size = 5
1278 1300
 			} else {
1279
-				anno_simple_size = convertUnitFun(anno_simple_size, "mm", valueOnly = TRUE)
1301
+				simple_anno_size = convertUnitFun(simple_anno_size, "mm", valueOnly = TRUE)
1280 1302
 			}
1281 1303
 			if(size_adjusted <= sum(gap)) {
1282 1304
 				stop_wrap(paste0(size_name, " you set is smaller than sum of gaps."))
1283 1305
 			}
1284 1306
 
1285 1307
 			## fix the size of simple annotation and zoom function annotations
1286
-			ts = size_adjusted - sum(gap) - sum(anno_size[l_simple_anno]*anno_simple_size/5)
1308
+			ts = size_adjusted - sum(gap) - sum(anno_size[l_simple_anno]) # total size excluding simple annotations and gap
1287 1309
 			if(ts < 0) {
1288 1310
 				stop_wrap(paste0(size_name, " you set is too small."))
1289 1311
 			}
1290 1312
 			anno_size2[!l_simple_anno] = anno_size[!l_simple_anno]/sum(anno_size[!l_simple_anno]) * ts
1291
-			anno_size2[l_simple_anno] = anno_size[l_simple_anno]*anno_simple_size/5
1292 1313
 
1293 1314
 			size_adjusted = unit(size_adjusted, "mm")
1294 1315
 			anno_size2 = unit(anno_size2, "mm")
... ...
@@ -235,7 +235,7 @@ setMethod(f = "add_heatmap",
235 235
 # -heatmap_border this set the value in `ht_opt` and reset back after the plot is done
236 236
 # -annotation_border  this set the value in `ht_opt` and reset back after the plot is done
237 237
 # -fastcluster this set the value in `ht_opt` and reset back after the plot is done
238
-# -anno_simple_size  this set the value in `ht_opt` and reset back after the plot is done
238
+# -simple_anno_size  this set the value in `ht_opt` and reset back after the plot is done
239 239
 # -show_parent_dend_line this set the value in `ht_opt` and reset back after the plot is done
240 240
 #
241 241
 # == detail
... ...
@@ -330,7 +330,7 @@ setMethod(f = "draw",
330 330
     heatmap_border = NULL,
331 331
     annotation_border = NULL,
332 332
     fastcluster = NULL,
333
-    anno_simple_size = NULL,
333
+    simple_anno_size = NULL,
334 334
     show_parent_dend_line = NULL
335 335
     ) {
336 336
 
... ...
@@ -350,7 +350,7 @@ setMethod(f = "draw",
350 350
                     "heatmap_border",
351 351
                     "annotation_border",
352 352
                     "fastcluster",
353
-                    "anno_simple_size",
353
+                    "simple_anno_size",
354 354
                     "show_parent_dend_line")) {
355 355
         v = get(opt_nm, inherits = FALSE)
356 356
         if(!is.null(v)) {
... ...
@@ -73,7 +73,7 @@ SingleAnnotation = setClass("SingleAnnotation",
73 73
 # -name_offset Offset to the annotation, a `grid::unit` object.
74 74
 # -name_side 'right' and 'left' for column annotations and 'top' and 'bottom' for row annotations
75 75
 # -name_rot Rotation of the annotation name, it can only take values in ``c(0, 90, 180, 270)``.
76
-# -anno_simple_size size of the simple annotation.
76
+# -simple_anno_size size of the simple annotation.
77 77
 # -width The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation,
78 78
 #        the width must be an absolute unit.
79 79
 # -height The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation,
... ...
@@ -152,7 +152,7 @@ SingleAnnotation = function(name, value, col, fun,
152 152
 	name_offset = NULL,
153 153
 	name_side = ifelse(which == "column", "right", "bottom"),
154 154
     name_rot = NULL,
155
-    anno_simple_size = ht_opt$anno_simple_size,
155
+    simple_anno_size = ht_opt$simple_anno_size,
156 156
     width = NULL, height = NULL) {
157 157
 
158 158
     .ENV$current_annotation_which = NULL
... ...
@@ -471,7 +471,7 @@ SingleAnnotation = function(name, value, col, fun,
471 471
         value = value
472 472
 
473 473
         if(verbose) qqcat("@{name}: generate AnnotationFunction for simple annotation values by anno_simple()\n")
474
-        .Object@fun = anno_simple(value, col = color_mapping, which = which, na_col = na_col, gp = gp, border = border, anno_simple_size = anno_simple_size)
474
+        .Object@fun = anno_simple(value, col = color_mapping, which = which, na_col = na_col, gp = gp, border = border, simple_anno_size = simple_anno_size)
475 475
         if(missing(width)) {
476 476
             .Object@width = .Object@fun@width
477 477
         } else {
... ...
@@ -35,7 +35,7 @@
35 35
 # Following parameters control heatmap annotations:
36 36
 #
37 37
 # -annotation_border ``border`` in all `HeatmapAnnotation`.
38
-# -anno_simple_size size for the simple annotation.
38
+# -simple_anno_size size for the simple annotation.
39 39
 #
40 40
 # Following parameters control the space between heatmap components:
41 41
 #
... ...
@@ -126,7 +126,7 @@ ht_opt = setGlobalOptions(
126 126
 		},
127 127
 		.length = 1),
128 128
 	show_vp = FALSE,
129
-	anno_simple_size = list(
129
+	simple_anno_size = list(
130 130
 		.value = unit(5, "mm"),
131 131
 		.class = "unit"
132 132
 	),
... ...
@@ -26,7 +26,7 @@ HeatmapAnnotation(...,
26 26
     annotation_width = NULL,
27 27
     height = NULL,
28 28
     width = NULL,
29
-    anno_simple_size = ht_opt$anno_simple_size,
29
+    simple_anno_size = ht_opt$simple_anno_size,
30 30
     simple_anno_size_adjust = FALSE)
31 31
 }
32 32
 \arguments{
... ...
@@ -51,7 +51,7 @@ HeatmapAnnotation(...,
51 51
   \item{annotation_width}{Width of each annotation if annotations are row annotations.}
52 52
   \item{height}{Height of the whole column annotations.}
53 53
   \item{width}{Width of the whole heatmap annotations.}
54
-  \item{anno_simple_size}{Size of the simple annotation.}
54
+  \item{simple_anno_size}{Size of the simple annotation.}
55 55
   \item{simple_anno_size_adjust}{Whether also adjust the size of simple annotations when adjusting the whole heatmap annotation.}
56 56
 
57 57
 }
... ...
@@ -19,7 +19,7 @@ SingleAnnotation(name, value, col, fun,
19 19
     name_offset = NULL,
20 20
     name_side = ifelse(which == "column", "right", "bottom"),
21 21
     name_rot = NULL,
22
-    anno_simple_size = ht_opt$anno_simple_size,
22
+    simple_anno_size = ht_opt$simple_anno_size,
23 23
     width = NULL, height = NULL)
24 24
 }
25 25
 \arguments{
... ...
@@ -39,7 +39,7 @@ SingleAnnotation(name, value, col, fun,
39 39
   \item{name_offset}{Offset to the annotation, a \code{\link[grid]{unit}} object.}
40 40
   \item{name_side}{'right' and 'left' for column annotations and 'top' and 'bottom' for row annotations}
41 41
   \item{name_rot}{Rotation of the annotation name, it can only take values in \code{c(0, 90, 180, 270)}.}
42
-  \item{anno_simple_size}{size of the simple annotation.}
42
+  \item{simple_anno_size}{size of the simple annotation.}
43 43
   \item{width}{The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation, the width must be an absolute unit.}
44 44
   \item{height}{The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation, the width must be an absolute unit.}
45 45
 
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{add_heatmap}.
10 10
 \code{add_heatmap} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
14 13
 \item \code{\link{add_heatmap,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14
+\item \code{\link{add_heatmap,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
15 15
 \item \code{\link{add_heatmap,Heatmap-method}}, \code{\link{Heatmap-class}} class method
16 16
 }
17 17
 }
... ...
@@ -10,7 +10,7 @@ Simple Annotation
10 10
 anno_simple(x, col, na_col = "grey",
11 11
     which = c("column", "row"), border = FALSE, gp = gpar(col = NA),
12 12
     pch = NULL, pt_size = unit(1, "snpc")*0.8, pt_gp = gpar(),
13
-    anno_simple_size = ht_opt$anno_simple_size,
13
+    simple_anno_size = ht_opt$simple_anno_size,
14 14
     width = NULL, height = NULL)
15 15
 }
16 16
 \arguments{
... ...
@@ -24,7 +24,7 @@ anno_simple(x, col, na_col = "grey",
24 24
   \item{pch}{Points/symbols that are added on top of the annotation grids. The value can be numeric or single letters. It can be a vector if \code{x} is a vector and a matrix if \code{x} is a matrix. No points are drawn if the corresponding values are NA.}
25 25
   \item{pt_size}{Size of the points/symbols. It should be a \code{\link[grid]{unit}} object. If \code{x} is a vector, the value of \code{pt_size} can be a vector, while if \code{x} is a matrix, \code{pt_size} can only be a single value.}
26 26
   \item{pt_gp}{Graphic parameters for points/symbols. The length setting is same as \code{pt_size}. If \code{pch} is set as letters, the fontsize should be set as \code{pt_gp = gpar(fontsize = ...)}.}
27
-  \item{anno_simple_size}{size of the simple annotation.}
27
+  \item{simple_anno_size}{size of the simple annotation.}
28 28
   \item{width}{Width of the annotation. The value should be an absolute unit. Width is not allowed to be set for column annotation.}
29 29
   \item{height}{Height of the annotation. The value should be an absolute unit. Height is not allowed to be set for row annotation.}
30 30
 
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{column_order}.
10 10
 \code{column_order} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{column_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{column_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{component_height}.
10 10
 \code{component_height} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{component_height,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{component_height,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{component_height,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{component_width}.
10 10
 \code{component_width} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{component_width,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{component_width,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{component_width,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -82,7 +82,7 @@ Draw a list of heatmaps
82 82
     heatmap_border = NULL,
83 83
     annotation_border = NULL,
84 84
     fastcluster = NULL,
85
-    anno_simple_size = NULL,
85
+    simple_anno_size = NULL,
86 86
     show_parent_dend_line = NULL)
87 87
 }
88 88
 \arguments{
... ...
@@ -153,7 +153,7 @@ Draw a list of heatmaps
153 153
   \item{heatmap_border}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
154 154
   \item{annotation_border}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
155 155
   \item{fastcluster}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
156
-  \item{anno_simple_size}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
156
+  \item{simple_anno_size}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
157 157
   \item{show_parent_dend_line}{this set the value in \code{\link{ht_opt}} and reset back after the plot is done}
158 158
 
159 159
 }
... ...
@@ -10,11 +10,11 @@ Method dispatch page for \code{draw}.
10 10
 \code{draw} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{draw,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
14 13
 \item \code{\link{draw,Legends-method}}, \code{\link{Legends-class}} class method
15
-\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
16
-\item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
14
+\item \code{\link{draw,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
17 15
 \item \code{\link{draw,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
16
+\item \code{\link{draw,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
17
+\item \code{\link{draw,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
18 18
 \item \code{\link{draw,Heatmap-method}}, \code{\link{Heatmap-class}} class method
19 19
 }
20 20
 }
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{draw_title}.
10 10
 \code{draw_title} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{draw_title,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{draw_title,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{draw_title,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -48,7 +48,7 @@ Following parameters control heatmap annotations:
48 48
 
49 49
 \describe{
50 50
   \item{annotation_border}{\code{border} in all \code{\link{HeatmapAnnotation}}.}
51
-  \item{anno_simple_size}{size for the simple annotation.}
51
+  \item{simple_anno_size}{size for the simple annotation.}
52 52
 }
53 53
 
54 54
 Following parameters control the space between heatmap components:
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{make_layout}.
10 10
 \code{make_layout} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{make_layout,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{make_layout,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{make_layout,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -13,8 +13,8 @@ Resize the Width or Height of Heatmap Annotations
13 13
     annotation_width = NULL,
14 14
     height = NULL,
15 15
     width = NULL,
16
-    anno_simple_size = ht_opt$anno_simple_size,
17
-    simple_anno_size_adjust = NULL)
16
+    simple_anno_size = object@param$simple_anno_size,
17
+    simple_anno_size_adjust = object@param$simple_anno_size_adjust)
18 18
 }
19 19
 \arguments{
20 20
 
... ...
@@ -23,7 +23,7 @@ Resize the Width or Height of Heatmap Annotations
23 23
   \item{annotation_width}{A vector of of annotation widths in \code{\link[grid]{unit}} class.}
24 24
   \item{height}{The height of the complete heatmap annotation.}
25 25
   \item{width}{The width of the complete heatmap annotation.}
26
-  \item{anno_simple_size}{The size of one line of the simple annotation.}
26
+  \item{simple_anno_size}{The size of one line of the simple annotation.}
27 27
   \item{simple_anno_size_adjust}{Whether adjust the size of the simple annotation?}
28 28
 
29 29
 }
... ...
@@ -36,10 +36,10 @@ The basic rules are (take \code{height} and \code{annotation_height} for example
36 36
    \code{annotation_height} are absolute units, \code{height} is ignored.
37 37
 2. If \code{annotation_height} contains non-absolute units, \code{height} also need to be set and the
38 38
    non-absolute units should be set in a simple form such as 1:10 or \code{unit(1, "null")}.
39
-3. \code{anno_simple_size} is only used when \code{annotation_height} is NULL.
39
+3. \code{simple_anno_size} is only used when \code{annotation_height} is NULL.
40 40
 4. If only \code{height} is set, non-simple annotation is adjusted while keeps simple anntation unchanged.
41 41
 5. If only \code{height} is set and all annotations are simple annotations, all anntations are adjusted,
42
-     and \code{anno_simple_size} is disabled.
42
+     and \code{simple_anno_size} is disabled.
43 43
 6. If \code{simple_anno_size_adjust} is \code{FALSE}, the size of the simple annotations will not change.
44 44
 }
45 45
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{row_dend}.
10 10
 \code{row_dend} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{row_dend,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{row_dend,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,8 +10,8 @@ Method dispatch page for \code{row_order}.
10 10
 \code{row_order} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{row_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
14 13
 \item \code{\link{row_order,Heatmap-method}}, \code{\link{Heatmap-class}} class method
14
+\item \code{\link{row_order,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
15 15
 }
16 16
 }
17 17
 \examples{
... ...
@@ -10,12 +10,12 @@ Method dispatch page for \code{show}.
10 10
 \code{show} can be dispatched on following classes:
11 11
 
12 12
 \itemize{
13
-\item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
14
-\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
15
-\item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
13
+\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
16 14
 \item \code{\link{show,SingleAnnotation-method}}, \code{\link{SingleAnnotation-class}} class method
15
+\item \code{\link{show,HeatmapAnnotation-method}}, \code{\link{HeatmapAnnotation-class}} class method
17 16
 \item \code{\link{show,HeatmapList-method}}, \code{\link{HeatmapList-class}} class method
18
-\item \code{\link{show,Heatmap-method}}, \code{\link{Heatmap-class}} class method
17
+\item \code{\link{show,AnnotationFunction-method}}, \code{\link{AnnotationFunction-class}} class method
18
+\item \code{\link{show,ColorMapping-method}}, \code{\link{ColorMapping-class}} class method
19 19
 }
20 20
 }
21 21
 \examples{
22 22
new file mode 100644
... ...
@@ -0,0 +1,377 @@
1
+
2
+context("test annotation size for a single HeatmapAnntoation object with only one annotation.")
3
+ComplexHeatmap:::dev.null()
4
+
5
+size_num = function(ha) {
6
+	s = sapply(ha@anno_list, function(anno) {
7
+		convertHeight(size(anno), "mm", valueOnly = TRUE)
8
+	})
9
+	unname(s)
10
+}
11
+
12
+test_that("a single simple annotation", {
13
+	ha = HeatmapAnnotation(foo = 1:10)
14
+	expect_that(size_num(ha), equals(5))
15
+
16
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1))
17
+	expect_that(size_num(ha), equals(10))
18
+
19
+	ha = HeatmapAnnotation(foo = 1:10)
20
+	expect_that(size_num(ha), equals(5))
21
+
22
+	ha = HeatmapAnnotation(foo1 = 1:10, 
23
+		simple_anno_size = unit(1, "cm")
24
+	)
25
+	expect_that(size_num(ha), equals(10))
26
+
27
+	ha = HeatmapAnnotation(foo1 = 1:10, 
28
+		annotation_height = unit(1, "cm"),
29
+		simple_anno_size_adjust = TRUE
30
+	)
31
+	expect_that(size_num(ha), equals(10))
32
+
33
+	ha = HeatmapAnnotation(foo1 = 1:10, 
34
+		height = unit(1, "cm"),
35
+		simple_anno_size_adjust = TRUE
36
+	)
37
+	expect_that(size_num(ha), equals(10))
38
+
39
+	ha = HeatmapAnnotation(foo1 = 1:10, 
40
+		annotation_height = unit(1, "cm")
41
+	)
42
+	expect_that(size_num(ha), equals(5))
43
+	
44
+	ha = HeatmapAnnotation(foo1 = 1:10, 
45
+		height = unit(1, "cm")
46
+	)
47
+	expect_that(size_num(ha), equals(5))
48
+
49
+	ht_opt$simple_anno_size = unit(1, "cm")
50
+	ha = HeatmapAnnotation(foo1 = 1:10)
51
+	expect_that(size_num(ha), equals(10))
52
+	ht_opt$simple_anno_size = unit(5, "mm")
53
+
54
+})
55
+
56
+test_that("a single complex annotation", {
57
+	ha = HeatmapAnnotation(foo = anno_points(1:10))
58
+	expect_that(size_num(ha), equals(10))
59
+
60
+	ha = HeatmapAnnotation(foo = anno_points(1:10),
61
+		annotation_height = unit(2, "cm"))
62
+	expect_that(size_num(ha), equals(20))
63
+
64
+	ha = HeatmapAnnotation(foo = anno_points(1:10),
65
+		height = unit(2, "cm"))
66
+	expect_that(size_num(ha), equals(20))
67
+})
68
+
69
+test_that("multiple simple annotations", {
70
+	ha = HeatmapAnnotation(foo = 1:10, bar = 10:1)
71
+	expect_that(size_num(ha), equals(c(5, 5)))
72
+
73
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1)
74
+	expect_that(size_num(ha), equals(c(10, 5)))
75
+
76
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1, 
77
+		simple_anno_size = unit(1, "cm")
78
+	)
79
+	expect_that(size_num(ha), equals(c(20, 10)))
80
+
81
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1, 
82
+		annotation_height = unit(c(2, 1), "cm"),
83
+		simple_anno_size_adjust = TRUE
84
+	)
85
+	expect_that(size_num(ha), equals(c(20, 10)))
86
+
87
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1, gap = unit(0, "mm"),
88
+		height = unit(3, "cm"),
89
+		simple_anno_size_adjust = TRUE
90
+	)
91
+	expect_that(size_num(ha), equals(c(20, 10)))
92
+
93
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1, 
94
+		annotation_height = unit(c(2, 1), "cm")
95
+	)
96
+	expect_that(size_num(ha), equals(c(10, 5)))
97
+
98
+	ha = HeatmapAnnotation(foo = cbind(1:10, 10:1), bar = 10:1, gap = unit(0, "mm"),
99
+		height = unit(3, "cm")
100
+	)
101
+	expect_that(size_num(ha), equals(c(10, 5)))
102
+
103
+})
104
+
105
+test_that("multiple complex annotations", {
106
+	ha = HeatmapAnnotation(foo = anno_points(1:10), bar = anno_barplot(10:1))
107
+	expect_that(size_num(ha), equals(c(10, 10)))
108
+
109
+	ha = HeatmapAnnotation(
110
+		foo = anno_points(1:10, height = unit(2, "cm")), 
111
+		bar = anno_barplot(10:1, height =unit(3, "cm")))
112
+	expect_that(size_num(ha), equals(c(20, 30)))
113
+
114
+	ha = HeatmapAnnotation(
115
+		foo = anno_points(1:10, height = unit(2, "cm")), 
116
+		bar = anno_barplot(10:1, height =unit(3, "cm")),
117
+		annotation_height = unit(c(1, 2), "cm"))
118
+	expect_that(size_num(ha), equals(c(10, 20)))
119
+
120
+	ha = HeatmapAnnotation(
121
+		foo = anno_points(1:10, height = unit(2, "cm")), 
122
+		bar = anno_barplot(10:1, height =unit(3, "cm")),
123
+		gap = unit(0, "mm"),
124
+		height = unit(10, "cm"))
125
+	expect_that(size_num(ha), equals(c(40, 60)))
126
+})
127
+
128
+test_that("mix of simple and complex annotations", {
129
+	ha = HeatmapAnnotation(
130
+		foo = 1:10, 
131
+		bar = anno_barplot(10:1))
132
+	expect_that(size_num(ha), equals(c(5, 10)))
133
+
134
+	ha = HeatmapAnnotation(
135
+		foo = 1:10, 
136
+		bar = anno_barplot(10:1),
137
+		simple_anno_size = unit(1, "cm"))
138
+	expect_that(size_num(ha), equals(c(10, 10)))
139
+
140
+	ha = HeatmapAnnotation(
141
+		foo = 1:10, 
142
+		bar = anno_barplot(10:1),
143
+		annotation_height = unit(c(1, 2), "cm"))
144
+	expect_that(size_num(ha), equals(c(10, 20)))
145
+
146
+	ha = HeatmapAnnotation(
147
+		foo = 1:10, 
148
+		bar = anno_barplot(10:1),
149
+		gap = unit(0, "mm"),
150
+		height = unit(3, "cm"))
151
+	expect_that(size_num(ha), equals(c(5, 25)))
152
+
153
+	ha = HeatmapAnnotation(
154
+		foo = 1:10, 
155
+		bar = anno_barplot(10:1),
156
+		gap = unit(0, "mm"),
157
+		height = unit(3, "cm"),
158
+		simple_anno_size_adjust = TRUE)
159
+	expect_that(size_num(ha), equals(c(10, 20)))
160
+
161
+	ha = HeatmapAnnotation(
162
+		foo = 1:10, 
163
+		bar = anno_barplot(10:1),
164
+		gap = unit(0, "mm"),
165
+		height = unit(3, "cm"),
166
+		simple_anno_size_adjust = FALSE)
167
+	expect_that(size_num(ha), equals(c(5, 25)))
168
+
169
+})
170
+
171
+
172
+test_that("annotation_height as fractions", {
173
+	ha = HeatmapAnnotation(foo = 1:10, 
174
+		bar = cbind(1:10, 10:1),
175
+		pt = anno_points(1:10),
176
+		gap = unit(0, "mm"),
177
+		annotation_height = 1,
178
+		height = unit(6, "cm"))
179
+	expect_that(size_num(ha), equals(c(20, 20, 20)))
180
+
181
+	ha = HeatmapAnnotation(foo = 1:10, 
182
+		bar = cbind(1:10, 10:1),
183
+		pt = anno_points(1:10),
184
+		gap = unit(0, "mm"),
185
+		annotation_height = 1:3,
186
+		height = unit(6, "cm"))
187
+	expect_that(size_num(ha), equals(c(10, 20, 30)))
188
+
189
+	ha = HeatmapAnnotation(foo = 1:10, 
190
+		bar = cbind(1:10, 10:1),
191
+		pt = anno_points(1:10),
192
+		gap = unit(0, "mm"),
193
+		annotation_height = unit(c(1, 2, 3), c("null", "null", "cm")),
194
+		height = unit(6, "cm"))
195
+	expect_that(size_num(ha), equals(c(10, 20, 30)))
196
+
197
+	ha = HeatmapAnnotation(foo = 1:10, 
198
+		bar = cbind(1:10, 10:1),
199
+		pt = anno_points(1:10),
200
+		gap = unit(0, "mm"),
201
+		annotation_height = unit(c(2, 2, 3), c("cm", "null", "cm")),
202
+		height = unit(6, "cm"))
203
+	expect_that(size_num(ha), equals(c(20, 10, 30)))
204
+
205
+})
206
+
207
+context("test heatmap annotations on multiple heatmaps")
208
+set.seed(123)
209
+mat1 = matrix(rnorm(80, 2), 8, 10)
210
+mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
211
+rownames(mat1) = paste0("R", 1:12)
212
+colnames(mat1) = paste0("C", 1:10)
213
+
214
+mat2 = matrix(runif(60, max = 3, min = 1), 6, 10)
215
+mat2 = rbind(mat2, matrix(runif(60, max = 2, min = 0), 6, 10))
216
+rownames(mat2) = paste0("R", 1:12)
217
+colnames(mat2) = paste0("C", 1:10)
218
+
219
+ind = sample(12, 12)
220
+mat1 = mat1[ind, ]
221
+mat2 = mat2[ind, ]
222
+
223
+test_that("only one heatmap has annotations", {
224
+	ha = HeatmapAnnotation(foo = 1:10)
225
+	ht = Heatmap(mat1, top_annotation = ha) + Heatmap(mat2)
226
+	ht = draw(ht)
227
+	expect_that(size_num(ht@ht_list[[1]]@top_annotation), equals(5))
228
+
229
+	ha = HeatmapAnnotation(foo = 1:10, bar = anno_points(1:10))
230
+	ht = Heatmap(mat1, top_annotation = ha) + Heatmap(mat2)
231
+	ht = draw(ht)
232
+	expect_that(size_num(ht@ht_list[[1]]@top_annotation), equals(c(5, 10)))
233
+})
234
+
235
+test_that("both heatmaps have annotations", {
236
+	# both heatmaps only have simple annotations
237
+	ha1 = HeatmapAnnotation(foo1 = 1:10)
238
+	ha2 = HeatmapAnnotation(foo1 = 1:10,
239
+	                        foo2 = 1:10,
240
+	                        foo4 = 1:10,
241
+	                        foo5 = 1:10,
242
+	                        gap = unit(0, "mm"))
243
+	ht1 = Heatmap(mat1, top_annotation = ha1)
244
+	ht2 = Heatmap(mat2, top_annotation = ha2)
245
+	ht_list = draw(ht1 + ht2)
246
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(5))
247
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(5, 5, 5, 5)))
248
+
249
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
250
+		simple_anno_size_adjust = TRUE)
251
+	ha2 = HeatmapAnnotation(foo1 = 1:10,
252
+	                        foo2 = 1:10,
253
+	                        foo4 = 1:10,
254
+	                        foo5 = 1:10,
255
+	                        gap = unit(0, "mm"))
256
+	ht1 = Heatmap(mat1, top_annotation = ha1)
257
+	ht2 = Heatmap(mat2, top_annotation = ha2)
258
+	ht_list = draw(ht1 + ht2)
259
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(20))
260
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(5, 5, 5, 5)))
261
+
262
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
263
+		                    simple_anno_size = unit(1, "cm"))
264
+	ha2 = HeatmapAnnotation(foo1 = 1:10,
265
+	                        foo2 = 1:10,
266
+	                        foo4 = 1:10,
267
+	                        foo5 = 1:10,
268
+	                        gap = unit(0, "mm"),
269
+	                        simple_anno_size = unit(6, "mm"))
270
+	ht1 = Heatmap(mat1, top_annotation = ha1)
271
+	ht2 = Heatmap(mat2, top_annotation = ha2)
272
+	ht_list = draw(ht1 + ht2)
273
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(10))
274
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(6, 6, 6, 6)))
275
+
276
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
277
+		                    simple_anno_size = unit(1, "cm"),
278
+		                    simple_anno_size_adjust = TRUE)
279
+	ha2 = HeatmapAnnotation(foo1 = 1:10,
280
+	                        foo2 = 1:10,
281
+	                        foo4 = 1:10,
282
+	                        foo5 = 1:10,
283
+	                        gap = unit(0, "mm"),
284
+	                        simple_anno_size = unit(6, "mm"))
285
+	ht1 = Heatmap(mat1, top_annotation = ha1)
286
+	ht2 = Heatmap(mat2, top_annotation = ha2)
287
+	ht_list = draw(ht1 + ht2)
288
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(24))
289
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(6, 6, 6, 6)))
290
+
291
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
292
+		                    simple_anno_size = unit(4, "cm"))
293
+	ha2 = HeatmapAnnotation(foo1 = 1:10,
294
+	                        foo2 = 1:10,
295
+	                        foo4 = 1:10,
296
+	                        foo5 = 1:10,
297
+	                        gap = unit(0, "mm"),
298
+	                        simple_anno_size_adjust = TRUE)
299
+	ht1 = Heatmap(mat1, top_annotation = ha1)
300
+	ht2 = Heatmap(mat2, top_annotation = ha2)
301
+	ht_list = draw(ht1 + ht2)
302
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(40))
303
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(10, 10, 10, 10)))
304
+
305
+	# both heatmaps have complex annotations
306
+	ha1 = HeatmapAnnotation(foo1 = anno_points(1:10),
307
+		                    foo2 = anno_barplot(10:1, height = unit(2, "cm")),
308
+		                    gap = unit(0, "mm"))
309
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10, height = unit(2, "cm")),
310
+		                    foo4 = anno_barplot(10:1),
311
+		                    gap = unit(0, "mm"))
312
+	ht1 = Heatmap(mat1, top_annotation = ha1)
313
+	ht2 = Heatmap(mat2, top_annotation = ha2)
314
+	ht_list = draw(ht1 + ht2)
315
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(c(10, 20)))
316
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(20, 10)))
317
+
318
+	ha1 = HeatmapAnnotation(foo1 = anno_points(1:10),
319
+		                    foo2 = anno_barplot(10:1),
320
+		                    gap = unit(0, "mm"))
321
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10, height = unit(2, "cm")),
322
+		                    foo4 = anno_barplot(10:1),
323
+		                    gap = unit(0, "mm"))
324
+	ht1 = Heatmap(mat1, top_annotation = ha1)
325
+	ht2 = Heatmap(mat2, top_annotation = ha2)
326
+	ht_list = draw(ht1 + ht2)
327
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(c(15, 15)))
328
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(c(20, 10)))
329
+
330
+	## one heatmap has simpel annotation and the other one has complex annotation
331
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
332
+		                    gap = unit(0, "mm"))
333
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10),
334
+		                    gap = unit(0, "mm"))
335
+	ht1 = Heatmap(mat1, top_annotation = ha1)
336
+	ht2 = Heatmap(mat2, top_annotation = ha2)
337
+	ht_list = draw(ht1 + ht2)
338
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(5))
339
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(10))
340
+
341
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
342
+		                    gap = unit(0, "mm"),
343
+		                    simple_anno_size_adjust = TRUE)
344
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10),
345
+		                    gap = unit(0, "mm"))
346
+	ht1 = Heatmap(mat1, top_annotation = ha1)
347
+	ht2 = Heatmap(mat2, top_annotation = ha2)
348
+	ht_list = draw(ht1 + ht2)
349
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(10))
350
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(10))
351
+
352
+
353
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
354
+							foo2 = anno_points(1:10),
355
+		                    gap = unit(0, "mm"))
356
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10),
357
+		                    gap = unit(0, "mm"))
358
+	ht1 = Heatmap(mat1, top_annotation = ha1)
359
+	ht2 = Heatmap(mat2, top_annotation = ha2)
360
+	ht_list = draw(ht1 + ht2)
361
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(c(5, 10)))
362
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(15))
363
+
364
+	ha1 = HeatmapAnnotation(foo1 = 1:10,
365
+							foo2 = anno_points(1:10),
366
+		                    gap = unit(0, "mm"))
367
+	ha2 = HeatmapAnnotation(foo3 = anno_points(1:10, height = unit(2, "cm")),
368
+		                    gap = unit(0, "mm"))
369
+	ht1 = Heatmap(mat1, top_annotation = ha1)
370
+	ht2 = Heatmap(mat2, top_annotation = ha2)
371
+	ht_list = draw(ht1 + ht2)
372
+	expect_that(size_num(ht_list@ht_list[[1]]@top_annotation), equals(c(5, 15)))
373
+	expect_that(size_num(ht_list@ht_list[[2]]@top_annotation), equals(20))
374
+})
375
+
376
+
377
+ComplexHeatmap:::dev.off2()
0 378
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+ 
2
+mat = matrix(rnorm(40), nr = 4, ncol = 10)
3
+rownames(mat) = letters[1:4]
4
+colnames(mat) = letters[1:10]
5
+
6
+d1 = dist(mat)
7
+d2 = dist2(mat)
8
+
9
+test_that("test dist and dist2", {
10
+	expect_that(all(abs(d1 - d2) < 1e-10), is_identical_to(TRUE))
11
+})
12
+
13
+test_that("test default colors", {
14
+	col = default_col(c("a", "b", "c"))
15
+	expect_that(is.atomic(col), is_identical_to(TRUE))
16
+	col = default_col(factor(c("a", "b", "c")))
17
+	expect_that(is.atomic(col), is_identical_to(TRUE))
18
+	col = default_col(1:10)
19
+	expect_that(is.function(col), is_identical_to(TRUE))
20
+})
21
+
22
+test_that("test ks_dist", {
23
+	m = matrix(rnorm(200), nc = 10)
24
+	d1 = ComplexHeatmap:::ks_dist(m, mc.cores = 1)
25
+	d2 = ComplexHeatmap:::ks_dist(m, mc.cores = 2)
26
+	d3 = ComplexHeatmap:::ks_dist_1(m)
27
+	expect_that(d1, is_identical_to(d2))
28
+	expect_that(d2, is_identical_to(d3))
29
+
30
+	lt = lapply(1:10, function(i) rnorm(runif(1, min = 10, max = 20)))
31
+	d1 = ComplexHeatmap:::ks_dist(lt, mc.cores = 1)
32
+	d2 = ComplexHeatmap:::ks_dist(lt, mc.cores = 2)
33
+	d3 = ComplexHeatmap:::ks_dist_1(lt)
34
+	expect_that(d1, is_identical_to(d2))
35
+	expect_that(d2, is_identical_to(d3))
36
+})
37
+
0 38
similarity index 100%
1 39
rename from tests/testthat/test-AnnotationFunction.R
2 40
rename to tests_not_run/test-AnnotationFunction.R
3 41
similarity index 100%
4 42
rename from tests/testthat/test-ColorMapping-class.R
5 43
rename to tests_not_run/test-ColorMapping-class.R
6 44
similarity index 100%
7 45
rename from tests/testthat/test-Heatmap-class.R
8 46
rename to tests_not_run/test-Heatmap-class.R
9 47
similarity index 100%
10 48
rename from tests/testthat/test-Heatmap-cluster.R
11 49
rename to tests_not_run/test-Heatmap-cluster.R
12 50
old mode 100755
13 51
new mode 100644
14 52
similarity index 77%
15 53
rename from tests/testthat/test-HeatmapAnnotation.R
16 54
rename to tests_not_run/test-HeatmapAnnotation.R
... ...
@@ -141,3 +141,56 @@ ha2 %v% Heatmap(m, name = "mat", cluster_columns = FALSE, column_split = split,
141 141
 
142 142
 
143 143
 
144
+### when there are only simple annotations
145
+col_fun = colorRamp2(c(0, 10), c("white", "blue"))
146
+ha = HeatmapAnnotation(
147
+    foo = cbind(a = 1:10, b = 10:1), 
148
+    bar = sample(letters[1:3], 10, replace = TRUE),
149
+    col = list(foo = col_fun,
150
+               bar = c("a" = "red", "b" = "green", "c" = "blue")
151
+    ),
152
+    simple_anno_size = unit(1, "cm")
153
+)
154
+draw(ha, test = TRUE)
155
+
156
+set.seed(123)
157
+mat1 = matrix(rnorm(80, 2), 8, 10)
158
+mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
159
+rownames(mat1) = paste0("R", 1:12)
160
+colnames(mat1) = paste0("C", 1:10)
161
+
162
+mat2 = matrix(runif(60, max = 3, min = 1), 6, 10)
163
+mat2 = rbind(mat2, matrix(runif(60, max = 2, min = 0), 6, 10))
164
+rownames(mat2) = paste0("R", 1:12)
165
+colnames(mat2) = paste0("C", 1:10)
166
+
167
+ind = sample(12, 12)
168
+mat1 = mat1[ind, ]
169
+mat2 = mat2[ind, ]
170
+
171
+ha1 = HeatmapAnnotation(foo1 = 1:10, 
172
+	                    annotation_height = unit(1, "cm"),
173
+	                    simple_anno_size_adjust = TRUE,
174
+                        annotation_name_side = "left")
175
+ha2 = HeatmapAnnotation(df = data.frame(foo1 = 1:10,
176
+                                        foo2 = 1:10,
177
+                                        foo4 = 1:10,
178
+                                        foo5 = 1:10))
179
+ht1 = Heatmap(mat1, name = "rnorm", top_annotation = ha1)
180
+ht2 = Heatmap(mat2, name = "runif", top_annotation = ha2)
181
+
182
+ht1 + ht2
183
+
184
+##### test size of a single simple annotation
185
+
186
+ha = HeatmapAnnotation(foo1 = 1:10, 
187
+	simple_anno_size = unit(1, "cm")
188
+)
189
+ha = HeatmapAnnotation(foo1 = 1:10, 
190
+	annotation_height = unit(1, "cm"),
191
+	simple_anno_size_adjust = TRUE
192
+)
193
+ha = HeatmapAnnotation(foo1 = 1:10, 
194
+	height = unit(1, "cm"),
195
+	simple_anno_size_adjust = TRUE
196
+)
144 197
similarity index 100%
145 198
rename from tests/testthat/test-HeatmapList-class.R
146 199
rename to tests_not_run/test-HeatmapList-class.R
147 200
similarity index 100%
148 201
rename from tests/testthat/test-Legend.R
149 202
rename to tests_not_run/test-Legend.R
150 203
similarity index 100%
151 204
rename from tests/testthat/test-SingleAnnotation.R
152 205
rename to tests_not_run/test-SingleAnnotation.R
153 206
similarity index 100%
154 207
rename from tests/testthat/test-annotation_axis.R
155 208
rename to tests_not_run/test-annotation_axis.R
156 209
similarity index 100%
157 210
rename from tests/testthat/test-dendrogram.R
158 211
rename to tests_not_run/test-dendrogram.R
159 212
similarity index 100%
160 213
rename from tests/testthat/test-multiple-page.R
161 214
rename to tests_not_run/test-multiple-page.R
162 215
similarity index 100%
163 216
rename from tests/testthat/test-oncoPrint.R
164 217
rename to tests_not_run/test-oncoPrint.R
165 218
similarity index 100%
166 219
rename from tests/testthat/test-upset.R
167 220
rename to tests_not_run/test-upset.R
168 221
similarity index 100%
169 222
rename from tests/testthat/test-utils.R
170 223
rename to tests_not_run/test-utils.R