Question: How to get the order of the gene list and indivdual cluster from the big heatmap made by heatmap2.0?
gravatar for shuvadeep.maity
9 months ago by
shuvadeep.maity0 wrote:

I hav a data set with expression of around ~8000 genes with 2 replictes and two conditions Now I plotted the heatmap using heatmap2 with row clusterring (see below)

> y <- read.csv('test.CSV', row.names = 'Gene_name', header = T)
> head(y)
                    R1_12      R2_12       R1_36        R2_36
1110004E09Rik  0.02448855  0.1928913  0.10312804 -0.243083469
2010300C02Rik  0.03967733  0.1089108  0.23843350  0.589653327
2210016F16Rik -0.01678531 -0.1019228 -0.31759875 -0.282965985
2410002F23Rik -0.05737916 -0.1057968 -0.07236606 -0.005287509
2700097O09Rik  0.07958317  0.1220447  0.22541512 -0.004510939
4931406P16Rik -0.07985068 -0.1200976 -0.05551624 -0.030421710

> hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete")
> my_palette <- colorRampPalette(c("blue", "white", "red"))(n = 299)
> mycl <- cutree(hr, k=25)#define the number of cluster
> mycolhc <- rainbow(length(unique(mycl)), start=0.1, end=0.9)
> mycolhc <- mycolhc[as.vector(mycl)]
> heatmap.2(as.matrix(y), Rowv=as.dendrogram(hr), Colv= NULL, scale="row","none", trace="none",col=my_palette, margins =c(10,6),RowSideColors=mycolhc)

and it successfully plotted nice heatmap.

I used RowSideColors to define my cluster and I can extract the clusters using cuttree.

How do I know/ extract the name and order of the genes similar to the order as displayed in the heatmap? The ordering is important for further analysis.

annotation heatmap • 174 views
ADD COMMENTlink modified 9 months ago by James W. MacDonald51k • written 9 months ago by shuvadeep.maity0
Answer: How to get the order of the gene list and indivdual cluster from the big heatmap
gravatar for James W. MacDonald
9 months ago by
United States
James W. MacDonald51k wrote:

The function heatmap.2 isn't part of Bioconductor, so this isn't the right venue for your question. In future, please ask about CRAN packages at

And you could have already answered your own question by simply reading the help page for this function! From ?heatmap.2:


     Invisibly, a list with components

  rowInd: row index permutation vector as returned by

  colInd: column index permutation vector.

And the only trick here is to know that something returned invisibly isn't normally returned unless you capture it in an object:

> z <- heatmap.2(matrix(rnorm(100), 10))
> z$rowInd
 [1]  2  6  3  5  7  8  1  4  9 10
ADD COMMENTlink written 9 months ago by James W. MacDonald51k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 275 users visited in the last hour