2010-06-04 39 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