怎样在heatmap中使用多种cluster方法

生物信息学中经常使用R 来画图,而R画heatmap的功能是非常强大的。通常,我的习惯是使用gplots包中的heatmap.2函数来进行画图。不过这个函数中不能对聚类分析(clustering)到方法进行调整,于是,小小写一段代码即能使用不同的聚类分析方法来对heatmap进行聚类整合。

 1 # There are 7 methods to make cluster in the function hclust in R
 2 Cluster_Method<-c( "ward", "single", "complete", "average", "mcquitty", "median", "centroid")
 3 
 4 for (i in 1:length(Cluster_Method)){
 5   #make a function to extract the cluster method
 6   myclust<-function(x){
 7     hclust(x,method=Cluster_Method[i])
 8   }
 9   #make heatmap by jpeg
10   jpeg(filename=paste(Cluster_Method[i],'.jpg'),width=1024,height=728)
11   heatmap.2(as.matrix(Data_Top1k_Var),
12             trace='none',
13             hclustfun=myclust,labRow=NA,
14             ColSideColors=c('black',grey(0.4),'lightgrey')[as.factor(CellLine_Anno$Type)],
15             xlab='CellLines',
16             ylab='Probes',
17             main=Cluster_Method[i],
18             col=greenred(64))
19   dev.off()
20 }

这样就可以一下子把七种cluster的方法依次用到heatmap上面来。而且通过对cluster树的比较,我们可以从中挑选出最好、最稳定到cluster方法,为后续分析打好基础!

 

posted on 2012-10-19 08:22  Forever_YCC  阅读(6562)  评论(0编辑  收藏  举报

导航