Browse code

give warning if color is defined while no annotations

Zuguang Gu authored on 12/09/2016 21:19:43
Showing 2 changed files

... ...
@@ -2,6 +2,7 @@ CHANGES in VERSION 1.11.7
2 2
 
3 3
 * SingleAnnotation: if `col` is a vector with no names, it will be assigned
4 4
   as `level(value)` or `unique(value)`
5
+* HeatmapAnnotation: give warnings if color is defined while with no annotations
5 6
 
6 7
 ==========================
7 8
 
... ...
@@ -180,6 +180,7 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
180 180
 	i_simple = 0
181 181
 	i_anno = 0
182 182
 	simple_length = NULL
183
+	col_name_defined = NULL
183 184
     for(ag in anno_args) {
184 185
 		if(ag == "df") {
185 186
 			if(is.null(colnames(df))) {
... ...
@@ -215,6 +216,7 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
215 216
 		        			which = which, show_legend = show_legend[i_simple + i], gp = gp, legend_param = annotation_legend_param[[i_simple + i]],
216 217
 		        			show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
217 218
 		        			name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
219
+		        		col_name_defined = c(col_name_defined, anno_name[i])
218 220
 		        	}
219 221
 		        }
220 222
 		    }
... ...
@@ -248,6 +250,7 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
248 250
 			        		which = which, show_legend = show_legend[i_simple + 1], gp = gp, legend_param = annotation_legend_param[[i_simple + 1]],
249 251
 			        		show_name = show_annotation_name[i_anno], name_gp = subset_gp(annotation_name_gp, i_anno), 
250 252
 		        			name_offset = annotation_name_offset[i_anno], name_side = annotation_name_side[i_anno], name_rot = annotation_name_rot[i_anno])))
253
+			        	col_name_defined = c(col_name_defined, ag)
251 254
 			        }
252 255
 			    }
253 256
 			    i_simple = i_simple + 1
... ...
@@ -257,6 +260,11 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
257 260
 		}
258 261
 	}
259 262
 
263
+	unused_col_name = setdiff(names(col), col_name_defined)
264
+	if(length(unused_col_name)) {
265
+		warn(paste0("Following are defined in `col` while have no corresponding annotations:", paste(unused_col_name, collapse = ", ")))
266
+	}
267
+
260 268
 	n_total_anno = length(anno_list)
261 269
 
262 270
 	if(is.null(gap)) gap = unit(0, "mm")