基于Pearson距离的微阵列数据热图

基于Pearson距离的微阵列数据热图,r,heatmap,dendrogram,R,Heatmap,Dendrogram,我一直在尝试为一些微阵列数据在R中生成一个热图,并且在很大程度上已经成功地基于在线指令生成了一个热图,但它并没有完全满足我的需要。我想基于皮尔逊距离而不是欧几里得距离对数据进行聚类,但我遇到了一些困难 使用heatmap2(来自gplots包),我使用以下代码制作初始热图: heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue") [data.test.factors],c

我一直在尝试为一些微阵列数据在R中生成一个热图,并且在很大程度上已经成功地基于在线指令生成了一个热图,但它并没有完全满足我的需要。我想基于皮尔逊距离而不是欧几里得距离对数据进行聚类,但我遇到了一些困难

使用heatmap2(来自gplots包),我使用以下代码制作初始热图:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")   [data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"))
Test402是一个包含402行(基因)和31列(患者)的矩阵,data.test.factors是每个患者所属结果组的指标。在这里使用hclustfun效果很好,热图似乎对方法和整体效果的变化做出了响应。问题是,聚类距离都是欧几里得距离,我想把它改成皮尔逊距离。因此,我尝试以下几点:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-cor(x))/2) )
cU = cor(Test402)
heatmap.2(cU,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-x)/2) )
上述命令失败。这是因为Test402,所以在查看一些其他建议时,我尝试了以下方法:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-cor(x))/2) )
cU = cor(Test402)
heatmap.2(cU,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-x)/2) )

这是可行的,但问题出在这里。热图现在只显示相关性,而不是TEST402中的原始表达式值。这不是我想要的!我希望,我只希望树状图以不同的方式聚类,我不想改变热图中实际表示的数据!这可能吗?

好的……我想你只是对
cor
dist
的操作方式感到困惑。从
dist
上的文档中:

This function computes and returns the distance matrix computed by using the specified 
    distance measure to compute the distances between the rows of a data matrix.
cor
上的文档中:

If x and y are matrices then the covariances (or correlations) 
    between the columns of x and the columns of y are computed.
看到区别了吗
dist
(和
dist
对象,这就是热图。2假设它正在变)假设您已经计算了行之间的距离,而使用
cor
则基本上计算了列之间的距离。在距离函数中添加一个简单的转置,可以运行以下(非方形)示例:

TEST <- matrix(runif(100),nrow=20)
heatmap.2(t(TEST), trace="none", density="none", 
            scale="row",
            labRow="",
            hclust=function(x) hclust(x,method="complete"),
            distfun=function(x) as.dist((1-cor(t(x)))/2))

测试Joran就是这样!哇,你完全正确,我没有专注于这方面,我专注于其他事情!非常感谢你指出这样一个愚蠢的错误!也谢谢你花时间帮我回答这个问题!也许是简单的错误,但不是愚蠢的。我唯一的线索是heatmap.2的文档说distfun默认为
dist