# utility: pretty print alignment def pprint(L,s1,s2): N = len(s1)+1 # row length pad = 5 # print title row using s1 print ' '*pad*2, for c in s1: print c.rjust(pad), print print i = 0 L = L[:] while L: # print col 1 using chars from s2 if i == 0: print ' '.rjust(pad), else: print s2[i-1].rjust(pad), i += 1 sub = L[:N] L = L[N:] for D in sub: if D: score = str(D['score']) path = D['path'] if path: print (score+path).rjust(pad), else: print score.rjust(pad), else: print '.'.rjust(pad), print print #=============================================== # for debugging def report(r,c,i,up,left,diag): print 'r', r, 'c' ,c, print 'i',i if up: print 'up', up if left: print 'left', left if diag: print 'diag', diag print s1[c-2] print s2[r-2]
def printAlignment(t): print L1,L2,L3 = t SZ = 50 for i in range(0,len(L1),SZ): print L1[i:i+SZ] print L2[i:i+SZ] print L3[i:i+SZ] print def load(fn): FH = open(fn,'r') data = FH.read() FH.close() if not data.strip()[0] == '>': return 'data is not FASTA' sys.exit() try: s1,s2 = data.strip().split('\n\n') except ValueError: return 'need two sequences to compare' sys.exit() s1 = s1.split('\n',1)[1] s2 = s2.split('\n',1)[1] s1 = s1.replace('\n','') s2 = s2.replace('\n','') return s1,s2 |