Browse code

check 'col' in HeatmapAnnotation()

Zuguang Gu authored on 13/09/2016 20:00:44
Showing 3 changed files

... ...
@@ -3,6 +3,7 @@ CHANGES in VERSION 1.11.7
3 3
 * SingleAnnotation: if `col` is a vector with no names, it will be assigned
4 4
   as `level(value)` or `unique(value)`
5 5
 * HeatmapAnnotation: give warnings if color is defined while with no annotations
6
+* HeatmapAnnotation: check `col`, if it is not valid, give warnings
6 7
 
7 8
 ==========================
8 9
 
... ...
@@ -184,7 +184,7 @@ setMethod(f = "map_to_colors",
184 184
 
185 185
 		if(is.numeric(x)) x = as.character(x)
186 186
 		if(any(! x[!lna] %in% object@levels)) {
187
-			msg = paste0(object@name, ": cannot map some of the levels:\n", paste(setdiff(x[!lna], object@levels), sep = ", ", collapse = ", "))
187
+			msg = paste0(object@name, ": cannot map colors to some of the levels:\n", paste(setdiff(x[!lna], object@levels), sep = ", ", collapse = ", "))
188 188
 			stop(msg)
189 189
 		}
190 190
 		
... ...
@@ -177,6 +177,20 @@ HeatmapAnnotation = function(df, name, col, na_col = "grey",
177 177
     }
178 178
     annotation_name_gp = recycle_gp(annotation_name_gp, n_total_anno)
179 179
 
180
+    if(!missing(col)) {
181
+    	if(is.null(names(col))) {
182
+    		stop("`col` should be a named list.")
183
+    	}
184
+    	if(any(is.na(names(col)))) {
185
+    		stop("`col` should be a named list.")
186
+    	}
187
+    	if(any(sapply(col, function(x) is.null(names(x))))) {
188
+    		stop("elements in `col` should be named vectors.")
189
+    	}
190
+    	if(any(sapply(col, function(x) any(is.na(names(x)))))) {
191
+    		stop("elements in `col` should be named vectors.")
192
+    	}
193
+    }
180 194
 	i_simple = 0
181 195
 	i_anno = 0
182 196
 	simple_length = NULL