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", density.info="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.