Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Bio.SubsMat import MatrixInfo
- from Bio import SeqIO
- def global_alignment_score(input):
- return tmp(input)[1]
- def tmp(input):
- blosum = MatrixInfo.blosum62
- fasta_sequences = SeqIO.parse(open(input), 'fasta')
- first = str(next(fasta_sequences).seq)
- second = str(next(fasta_sequences).seq)
- sigma = 5
- matr = [[]]
- start = 0
- startstr = ""
- #1 = rechts 0 = schuin 2 = onder
- # init randen
- for i in range(0, len(first) + 1):
- matr[0].append((startstr, start))
- start -= sigma
- startstr += "1"
- start = -5
- startstr = "2"
- for i in range(1, len(second) + 1):
- matr.append([(startstr, start)])
- start -= sigma
- startstr += "2"
- for lengt in range(1, len(second) + 1):
- for width in range(1, len(first) + 1):
- count = matr[lengt - 1][width - 1][1]
- tmp = matr[lengt - 1][width - 1][0]
- if (first[width - 1], second[lengt - 1]) in blosum:
- count += blosum[(first[width - 1], second[lengt - 1])]
- else:
- count += blosum[(second[lengt - 1], first[width - 1])]
- if matr[lengt - 1][width][1] - sigma > count:
- count = (matr[lengt - 1][width][1])
- tmp+='2'
- elif matr[lengt][width - 1][1] - sigma > count:
- count = (matr[lengt][width - 1][1])
- tmp+='1'
- else :
- tmp += "0"
- matr[lengt].append((tmp,count))
- code = matr[-1][-1][0]
- fi = []
- se = []
- index1 = 0
- index2 = 0
- for i in range(0, len(code)):
- if code[i] == '0':
- fi.append(first[index1])
- se.append(second[index2])
- index1 += 1
- index2 += 1
- elif code[i] == '1':
- fi.append(first[index1])
- se.append('-')
- index1 += 1
- else:
- fi.append('-')
- se.append(second[index2])
- index2 += 1
- return [(''.join(fi),''.join(se)), matr[-1][-1][1]]
- def global_alignment(input):
- return tmp(input)[0]
- print(global_alignment('data01.faa'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement