使用Pearson距离的微阵列数据热图

Ana*_*Ana 3 r dendrogram heatmap

我一直试图在R中为一些微阵列数据生成热图,并且大部分已经成功地生成了一个基于在线指令的热图,但它并没有完全符合我的要求.我想要的是基于Pearson距离而不是欧几里德距离来聚类数据,但我遇到了一些困难.

使用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"))
Run Code Online (Sandbox Code Playgroud)

Test402是具有402行(基因)和31列(患者)的矩阵,data.test.factors是每个患者所属的结果组的指标.使用hclustfun在这里工作正常,热图似乎对方法和整体工作的变化做出响应.问题是,聚类距离都是欧几里德距离,我想把它改为Pearson距离.所以我尝试以下方法:

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) )
Run Code Online (Sandbox Code Playgroud)

上面的命令失败.那是因为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) )
Run Code Online (Sandbox Code Playgroud)

这是有效的,但这是问题所在.热图,而不是在TEST402中具有原始表达式值,现在仅显示相关性.这不是我想要的!我想要这个,我只希望树形图以不同的方式聚类,我不想改变热图中实际表示的数据!这可能吗?

jor*_*ran 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.
Run Code Online (Sandbox Code Playgroud)

并从以下文档cor:

If x and y are matrices then the covariances (or correlations) 
    between the columns of x and the columns of y are computed.
Run Code Online (Sandbox Code Playgroud)

看到不同?dist(和dist对象,这是heatmap.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))
Run Code Online (Sandbox Code Playgroud)