zoukankan      html  css  js  c++  java
  • 怎样在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方法,为后续分析打好基础!

  • 相关阅读:
    python uuid
    linux 修改时区
    Nginx 缓存命中率
    MongoDB oplog 详解
    MongoDB 复本集搭建
    复制集简介
    解决Python2.7的UnicodeEncodeError: 'ascii' codec can't encode异常错误
    MongoDB 介绍
    python virtualenv
    Docker Compose 模板文件 V2
  • 原文地址:https://www.cnblogs.com/foreverycc/p/2730391.html
Copyright © 2011-2022 走看看