Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. from Bio.SubsMat import MatrixInfo
  2. from Bio import SeqIO
  3.  
  4. def global_alignment_score(input):
  5. return tmp(input)[1]
  6.  
  7. def tmp(input):
  8. blosum = MatrixInfo.blosum62
  9. fasta_sequences = SeqIO.parse(open(input), 'fasta')
  10. first = str(next(fasta_sequences).seq)
  11. second = str(next(fasta_sequences).seq)
  12. sigma = 5
  13.  
  14. matr = [[]]
  15. start = 0
  16. startstr = ""
  17.  
  18. #1 = rechts 0 = schuin 2 = onder
  19. # init randen
  20. for i in range(0, len(first) + 1):
  21. matr[0].append((startstr, start))
  22. start -= sigma
  23. startstr += "1"
  24. start = -5
  25. startstr = "2"
  26. for i in range(1, len(second) + 1):
  27. matr.append([(startstr, start)])
  28. start -= sigma
  29. startstr += "2"
  30.  
  31. for lengt in range(1, len(second) + 1):
  32. for width in range(1, len(first) + 1):
  33. count = matr[lengt - 1][width - 1][1]
  34. tmp = matr[lengt - 1][width - 1][0]
  35. if (first[width - 1], second[lengt - 1]) in blosum:
  36. count += blosum[(first[width - 1], second[lengt - 1])]
  37. else:
  38. count += blosum[(second[lengt - 1], first[width - 1])]
  39.  
  40.  
  41.  
  42. if matr[lengt - 1][width][1] - sigma > count:
  43. count = (matr[lengt - 1][width][1])
  44. tmp+='2'
  45. elif matr[lengt][width - 1][1] - sigma > count:
  46. count = (matr[lengt][width - 1][1])
  47. tmp+='1'
  48. else :
  49. tmp += "0"
  50. matr[lengt].append((tmp,count))
  51.  
  52.  
  53. code = matr[-1][-1][0]
  54. fi = []
  55. se = []
  56. index1 = 0
  57. index2 = 0
  58. for i in range(0, len(code)):
  59. if code[i] == '0':
  60. fi.append(first[index1])
  61. se.append(second[index2])
  62. index1 += 1
  63. index2 += 1
  64. elif code[i] == '1':
  65. fi.append(first[index1])
  66. se.append('-')
  67. index1 += 1
  68. else:
  69. fi.append('-')
  70. se.append(second[index2])
  71. index2 += 1
  72.  
  73. return [(''.join(fi),''.join(se)), matr[-1][-1][1]]
  74.  
  75. def global_alignment(input):
  76. return tmp(input)[0]
  77.  
  78.  
  79.  
  80. print(global_alignment('data01.faa'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement