Error in function heatmap: 'x' must be a numeric matrix
0
0
Entering edit mode
4.3 years ago
f.morgana • 0

Hi all,

I have been struggling with the heatmap function for which I continuously receive the error: 'x' must be a numeric matrix. I have been trying to perform section 4 ("Identifying temporally expressed genes") of the following slingshot vignette: http://www.bioconductor.org/packages/devel/bioc/vignettes/slingshot/inst/doc/vignette.html

I have executed the following lines of code, where "thymus_sce" is my SCE object:

library(tradeSeq)

# fit negative binomial GAM
sim <- fitGAM(thymus_sce)

# test for dynamic expression
ATres <- associationTest(thymus_sce)

topgenes <- rownames(ATres[order(ATres$pvalue), ])[1:250]
pst.ord <- order(thymus_sce$slingPseudotime_1, na.last = NA)
heatdata <- assays(thymus_sce)$counts[topgenes, pst.ord]
heatclus <- thymus_sce$GMM[pst.ord]

All of the above I got to work, until I get to:

heatmap(log1p(heatdata), Colv = NA,
        ColSideColors = brewer.pal(9,"Set1")[heatclus])

Here, I get:

Error in heatmap(log1p(heatdata), Colv = NA, ColSideColors = brewer.pal(9, : 'x' must be a numeric matrix

I checked the class of heatdata:

class(heatdata)

which gives me

[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

So I suppose it is a matrix, right? At least, a sparse one... Is that the problem? What am I doing wrong and how could I get this to work?

Your help would be much appreciated, if any more information is needed, please let me know!

Kind regards, Florencia

heatmap slingshot tradeseq • 4.9k views
ADD COMMENT
0
Entering edit mode

some R variables are not a matrix, could be a list, dataset or object, try to enforce matrix format with:

heatmap(as.matrix(log1p(heatdata)), Colv = NA,
    ColSideColors = brewer.pal(9,"Set1")[heatclus])
ADD REPLY
0
Entering edit mode

Hi JC,

Many thanks for your rapid response! I tried your suggestion, it seems to fix my previous error but now I get another one stating:

Error in heatmap(as.matrix(log1p(heatdata)), Colv = NA, ColSideColors = brewer.pal(9,  : 
  'ColSideColors' must be a character vector of length ncol(x)

To be honest, I just copy/pasted the lines of code from the vignette, so not entirely sure how to modify the ColSideColors argument... Any idea?

ADD REPLY
0
Entering edit mode

you can either remove the entire argument (remove ColSideColors = ....) or you can make sure that heatclus is the same value as ncol(log1p(heatdata))

ADD REPLY
0
Entering edit mode

that part is defining the colors, so you need a vector with one value per column, you can change it as:

ColSideColors = brewer.pal(9,"Set1")(ncol(as.matrix(heatdata)))
ADD REPLY

Login before adding your answer.

Traffic: 1718 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6