Package obitools :: Package distances :: Module phylip
[hide private]
[frames] | no frames]

Source Code for Module obitools.distances.phylip

 1  import sys 
 2   
 3  from itertools import imap,count 
 4   
5 -def writePhylipMatrix(matrix):
6 names = [x.id for x in matrix.aligment] 7 pnames= [x[:10] for x in names] 8 unicity={} 9 redundent=[] 10 for n in pnames: 11 unicity[n]=unicity.get(n,0)+1 12 redundent.append(unicity[n]) 13 14 for i,n,r in imap(None,count(),pnames,redundent): 15 alternate = n 16 if r > 1: 17 while alternate in pnames: 18 lcut = 9 - len(str(r)) 19 alternate = n[:lcut]+ '_%d' % r 20 r+=1 21 pnames[i]='%-10s' % alternate 22 23 firstline = '%5d' % len(matrix.aligment) 24 rep = [firstline] 25 for i,n in imap(None,count(),pnames): 26 line = [n] 27 for j in xrange(i): 28 line.append('%5.4f' % matrix[(j,i)]) 29 rep.append(' '.join(line)) 30 return '\n'.join(rep)
31