gpar element must not be length zero - pheatmap error
1
0
Entering edit mode
4.2 years ago
ccha97 ▴ 60

Hello, I am getting the gpar element must not equal zero error when I run the code for my pheatmap.

   Error in check.length("fill") : 
  'gpar' element 'fill' must not be length 0

I understand it's something to do with matching the annotation columns of the matrix to the row names of the rownames of the dataframe, however am not sure how to go about it in my situation?

Here is my current code for my kmeans clustered heatmap:

resSigind = res[ which(res$padj < 0.05 & res$log2FoldChange > 0), ]
resSigrep = res[ which(res$padj < 0.05 & res$log2FoldChange < 0), ]
resSig = rbind(resSigind, resSigrep)

allSig_genes <- rownames(resSig)

library("pheatmap")
library(cluster)

rld <- rlog(dds)

rld_sign <- assay(rld)[allSig_genes,] 
topVarGenes <- head(order(rowVars(rld_sign), decreasing = TRUE), 100)

set.seed(1234)
k <-   pheatmap(rld_sign[topVarGenes,], scale="row",kmeans_k = 3)
clusterDF <- as.data.frame(factor(k$kmeans$cluster))
colnames(clusterDF) <- "Cluster"

OrderByCluster <- rld_sign[topVarGenes,][order(clusterDF$Cluster),]

pheatmap(OrderByCluster,
         scale="row",annotation_row = clusterDF,
         show_rownames = FALSE,cluster_rows = FALSE)
heatmap pheatmap DESeq2 RNA-Seq • 4.6k views
ADD COMMENT
0
Entering edit mode
4.2 years ago
jkkbuddika ▴ 200

I can run this code using a DESeqDataSet object of my own. Are you certain that you make DESeqDataSet object and result tables properly?

ADD COMMENT
0
Entering edit mode

Yes, the DESeqDataSet and results seem to be fine, I have made a similar heatmap using them before.

ADD REPLY
0
Entering edit mode

Output of the following, please:

str(OrderByCluster)
str(clusterDF)

If I recall correctly, these two objects have to be synchronised, with rownames(clusterDF) == colnames(OrderByCluster)

ADD REPLY
0
Entering edit mode
 > str(OrderByCluster)
 num [1:100, 1:6] 9.51 9.51 9.51 9.14 9.14 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:100] "231507" "231507" "231507" "100041546" ...
  ..$ : chr [1:6] "CD23_WE1" "CD23_WE2" "CD23_Doc1" "CD23_Doc2" ...
> str(clusterDF)
'data.frame':   100 obs. of  1 variable:
 $ Cluster: Factor w/ 3 levels "1","2","3": 2 2 2 2 2 2 1 1 1 2 ...

I tried to make the rownames equal the colnames, but get this error:

 rownames(clusterDF) = colnames(OrderByCluster)
Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length
ADD REPLY
0
Entering edit mode

Sorry, my apologies, this is row annotation; so, it would have to be:

rownames(clusterDF) == rownames(OrderByCluster)

Note also the two equals signs, ==, i.e., this is just a conditional statement, not a blind assign command, which we should not do.

Essentially, your clusterDF object needs rownames so that it can be aligned to OrderByCluster. Here is the entry from the pheatmap docs:

annotation_row

data frame that specifies the annotations shown on left side of the heatmap. Each row defines the features for a specific row. The rows in the data and in the annotation are matched using corresponding row names. Note that color schemes takes into account if variable is continuous or discrete.

ADD REPLY
0
Entering edit mode

It seems to run, but outputs false and leaves me with the same error.

rownames(clusterDF) == rownames(OrderByCluster) [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [18] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [35] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [52] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [69] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [86] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

> pheatmap(OrderByCluster,
+          scale="row",annotation_row = clusterDF,
+          show_rownames = FALSE,cluster_rows = FALSE)
Error in check.length("fill") : 
  'gpar' element 'fill' must not be length 0

I'm not sure why it isn't working, as it seems to work fine when I originally I used rld instead of rld_sign? For context my OrderByCluster and clusterDF looks like this: enter image description here enter image description here

ADD REPLY
1
Entering edit mode

Thanks, so, the rownames of clusterDF need to be set, and they should align with those rownames of OrderByCluster. In your screenshot, the rownames of clusterDF are just 1, 2, 3, 4, 5, et cetera.

This probably occurred in this situation because you just have a single column in your annotation, but i'm not sure.

If you are 100% certain that clusterDF is already perfectly aligned with OrderByCluster, then, to solve this, you probably just need to do:

rownames(clusterDF) <- rownames(OrderByCluster)
ADD REPLY
0
Entering edit mode

It seems like there's duplicate row names (genes) in my OrderByCluster non-unique values when setting 'row.names': �100041546�, �110257�, �110612�, �11656�, �11826�, �12346�, �12349�, �12516�, �14934�, �15122�, �15129�, �17067�, �17105�, �17523�, �18054�, �18854�, �19746�, �20194�, �20343�, �20533�, �21349�, �216197�, �231507�, �238447�, �246727�, �246730�, �27028�, �328563�, �328780�, �435784�, �620017�, �66141�, �668139�, �72289�, �76933�, �777780�Error in .rowNamesDF<-(x, value = value) : duplicate 'row.names' are not allowed

This is strange because these should be the top 100 variable genes - I've tried running unique(rld_sign) and distinct(rld_sign), but the problem still persists (not sure why considering these duplicates seem to have the same values as one another)

EDIT: I was able to fix the duplicated row name issue (realised the duplicates were contained in my allSig_genes, however now my issue is that rows which are not in the same cluster are not grouped together

enter image description here

ADD REPLY
1
Entering edit mode

Glad that you got it working at last; however, this issue:

however now my issue is that rows which are not in the same cluster are not grouped together

...will require some debugging of your general workflow.

I would just implore that you ensure 100% that your annotation objects are always perfectly aligned with your main expression data, i.e., in both length and order. Many functions are not intelligent enough to align them for you, and may just assume that they are aligned.

ADD REPLY
0
Entering edit mode

Hi Kevin, thanks for that - you were right in the sense that they weren't aligned. Upon closer inspection, I realised that when I ran rownames(clusterDF) <- rownames(OrderByCluster), it overwrites the rownames (ENTREZ IDs) of clusterDF in the same order as they are in OrderByCluster.

However, the other column - the cluster number (e.g. 1, 2, 3) does not change accordingly with those rownames (that is, the cluster numbers are associated with the original rownames of clusterDF). Therefore the genes aren't being assigned to the correct cluster (e.g. gene 20343 is meant to be in cluster 1, however after changing rownames is in cluster 2).

enter image description here enter link description here

I've tried to look up what function to use, e.g. the match function but I don't think it's quite what I need? Another idea is to have rownames of clusterDF and OrderByCluster in the same order (e.g. ascending or descending), but a lot of the forum posts I've been looking at only specify how to order dfs by columns, rather than the actual rowname.

ADD REPLY
0
Entering edit mode

match() should work here, but there are also new functions that you could use in dplyr: https://www.r-bloggers.com/how-to-perform-merges-joins-on-two-or-more-data-frames-with-base-r-tidyverse-and-data-table/.

ADD REPLY

Login before adding your answer.

Traffic: 1750 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