Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pheatmap:Error in annotation_colors[[colnames(annotation)[i]]] : subscript out of bounds

library(pheatmap)

another<-read.table("~/Desktop/tcga3dcategorized.csv",sep=',',header=FALSE)
test<-another[1:3]
labels<-another[4]
colnames(test)=c("Dim 1","Dim 2","Dim 3")

annotation_row=data.frame(CancerType=factor(labels))
ann_colors=list(CancerType=c(KIRC="red", UCEC="#B2509E",LUSC="#D49DC7",
    LGG="#C1A72F",PCPG="#E8C51D",HNSC="#F9ED32",CESC="#104A7F",ESCA="#9EDDF9",
    BRCA="#007EB5",THCA="#CACCDB",PRAD="#6E7BA2",MESO="#DAF1FC",PAAD="#00AEEF",
    LUAD="#F6B667",LAML="#D97D25",UVM="#FBE3C7",GBM="#F89420",READ="#97D1A9",
    SKCM="#009444",KIRP="#754C29",COAD="#CEAC8F",LIHC="#3953A4",SARC="#BBD642",
    OV="#00A99D",BLCA="#D3C3E0",STAD="#A084BD",TGCT="#542C88",ACC="#FAD2D9",
    THYM="#ED1C24",KICH="#F8AFB3",DLBC="#EA7075",UCS="#7E1918",CHOL="#BE1E2D"))

pheatmap(test,annotation_row=annotation_row,annotation_colors=ann_colors,main="title")
```

The error is:

Error in annotation_colors[[colnames(annotation)[i]]] : 
  subscript out of bounds
like image 709
Greenhand001 Avatar asked Mar 04 '23 06:03

Greenhand001


2 Answers

You should force your data frame to have row names.

# after read.table
rownames(another) <- paste0("row_", seq(nrow(another)))

Look at Something weird in pheatmap (a bug?)

like image 158
SamGG Avatar answered May 05 '23 19:05

SamGG


Check your data structures - they are not correct. Your structure another , produced by read.table and test which is a subset of it are dataframes. And you are trying to feed them into pheatmap function which uses matrix - which is different structure from dataframe. You can convert your object to matrix like this:

test_matrix <- data.matrix(test, rownames.force=NA) # change the rownames.force -argument if you want rownames

Then you can feed it to pheatmap. If it doesn´t work, you could check the dimensions of objects being fed to pheatmap.

like image 25
Oka Avatar answered May 05 '23 20:05

Oka