Clustering distance matrix Python

def TMclstr(fp):
import scipy.cluster.hierarchy as sch
import scipy.spatial.distance as ssd
#read represent id list
replist=read_clstr_represent(fp)
lenlist=len(replist)
#read TMscore matrix
vec=[]
f=file(‘TM.txt’)
for i in range(0,lenlist):
for j in range(i+1,lenlist):
a = f.readline().strip().split()
t=1-float(a[2])
vec.append(t)
f.close()
#Clustering
linkage_matrix=sch.linkage(ssd.squareform(vec))
#print linkage_matrix
ind=sch.fcluster(linkage_matrix,0.95)
inx=range(0,lenlist)
data=zip(ind,inx)
data.sort()
for i,j in data:
print replist[j],i
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s