clusterExperiment icon indicating copy to clipboard operation
clusterExperiment copied to clipboard

plotHeatmap breaks when sampleData is ordered factor

Open epurdom opened this issue 9 years ago • 2 comments

I opened this as separate issue (submitted by @allonw); was previously combined with another issue.

When one of the sampleData metadata has spaces, plotHeatmap breaks with an error that doesn't report what's wrong

library(clusterExperiment)

aaa = matrix(runif(100), nrow = 10)
anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = TRUE)
levels(anno) = c("low activity", "medium activity", "high activity")

#Error in cut.default(a, breaks = 100) : 'x' must be numeric
plotHeatmap(data = aaa, sampleData = as.data.frame(anno))

#works, but ignores the order of the factor
plotHeatmap(data = aaa, sampleData = as.data.frame(make.names(anno)))

epurdom avatar Nov 30 '16 07:11 epurdom

This is something to do with how aheatmap treats ordered factors. If the factor is not ordered, the spaces are okay:

anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = FALSE)
levels(anno) = c("low activity", "medium activity", "high activity")
plotHeatmap(data = aaa, sampleData = as.data.frame(anno))

The annCol object that is being passed to aheatmap is exactly the same as as.data.frame(anno).

The following code works in aheatmap:

anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = FALSE)
levels(anno) = c("low activity", "medium activity", "high activity")
NMF::aheatmap(aaa,annCol=as.data.frame(anno))

But I get errors with this:

anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = TRUE)
levels(anno) = c("low activity", "medium activity", "high activity")
NMF::aheatmap(aaa,annCol=as.data.frame(anno))
Error in Math.factor(c(1L, 3L), 0) : ‘round’ not meaningful for factors
In addition: Warning messages:
1: In if (class(annotation[[i]]) %in% c("character", "factor")) { :
  the condition has length > 1 and only the first element will be used
2: In if (class(annotation[[i]]) %in% c("character", "factor")) { :
  the condition has length > 1 and only the first element will be used

Interestingly, not the same error.

epurdom avatar Nov 30 '16 08:11 epurdom

I have added a sensible error message to plotHeatmap and submitted the issue to NMF: renozao/NMF#83

epurdom avatar May 11 '17 20:05 epurdom