2010-06-04 38 views
3

如何在Python中以一种显示基因表达值矩阵和树状图的方式对层次聚类(在这种情况下用于基因表达数据)进行操作?我的意思是像这里的例子:使用python中的基因表达矩阵进行层次聚类

http://www.mathworks.cn/access/helpdesk/help/toolbox/bioinfo/ug/a1060813239b1.html

子弹点之后如图6(图1),其中,所述树形图绘制到基因表达矩阵,其中的行已被重新排序,以反映的左侧集群。

如何在Python中使用numpy/scipy或其他工具来做到这一点?此外,使用欧氏距离作为度量,用大约11,000个基因的矩阵做这个计算是否可行?

编辑:许多人都建议集群包,但我仍然不确定如何绘制我在Python中与上面链接的图像类型。例如,如何使用Matplotlib将树状图覆盖在热图矩阵的旁边?

谢谢。

回答

2

你可以用scipy的cluster.hierarchy模块做到这一点。这些命令实际上甚至非常相似。但是,您将不得不使用correlation而不是corr作为参数pdist而不是cluster函数scipy的群集模块的名称是fcluster。此外,对于树状图,功能是dendrogram scipy而不是clustergram在Matlab中。

您绝对可以使用欧几里得指标(认为它是pdist的默认值)。我认为用11,000个基因来做这件事应该是可行的,因为这将是11000 *(11000-1)/ 2 = 60494500(11000选择2)要计算的距离。这是一个很大的数字,但我认为是可行的。

+0

是否有阴谋在SciPy的所产生的树状图工具? – user248237dfsf 2010-06-05 18:10:21

+0

您还需要'matplotlib'模块。它可能有助于查看此文档:http://www.cs.swarthmore.edu/~turnbull/cs67/s09/labs/lab05.pdf它使用我很确定的scipy-cluster软件包(hcluster)在scipy.cluster.hierarchy模块中放置了什么。 – 2010-06-05 18:15:01

4

许多聚类方法,包括scipy.cluster开始排序所有成对距离, 〜6000万在你的情况下,不是太大。
以下内容需要多长时间?

import scipy.cluster.hierarchy as hier 
import pylab as pl 

def fcluster(pts, ncluster, method="average", criterion="maxclust"): 
    """ -> (pts, Y pdist, Z linkage, T fcluster, clusterlists) 
     ncluster = n1 + n2 + ... (including n1 singletons) 
     av cluster size = len(pts)/ncluster 
    """ 
    pts = np.asarray(pts) 
    Y = scipy.spatial.distance.pdist(pts) # ~ N^2/2 
    Z = hier.linkage(Y, method) # N-1       
    T = hier.fcluster(Z, ncluster, criterion=criterion) 
     # clusters = clusterlists(T) 
    return (pts, Y, Z, T) 

hier.dendrogram(Z) 

如何置换矩阵和情节很好地被要求 here 在在3月左右,有部分答案。

2

一对夫妇的人都在使用SciPy的和matplotlib创建层次聚类和热图可视化原型模块取得了一些进展体面:

How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

我已经适应这个代码做一个全它可以集成到我的一个转录组分析软件包中。我对使用各种聚类度量方法和着色梯度生成热图的最终产品感到非常满意。代码和输出示例如下所示:

http://altanalyze.blogspot.com/2012/06/hierarchical-clustering-heatmaps-in.html