3

我一直在尝试在 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) )

上述命令失败。那是因为 Test402需要是方阵。因此,查看一些其他建议,我尝试了以下方法:

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 中的原始表达式值。这不是我想要的!我想要这个,我只希望树状图以不同的方式聚类,我不想改变热图中实际表示的数据!这可能吗?

4

1 回答 1

10

好的...我认为您只是对如何操作cordist操作感到困惑。从文档中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对象,这heatmap.2是假设它得到的)假设您已经计算了rows之间的距离,而使用cor您实际上是在计算columns之间的距离。向距离函数添加一个简单的转置允许这个(非方形)示例为我运行:

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))
于 2011-07-16T20:12:36.297 回答