fork download
  1. def global_alignment_score(v, w, scoring_matrix, sigma):
  2. '''Return the global alignment score of v and w subject to the given scoring matrix and indel penalty sigma.'''
  3.  
  4. # Initialize the scoring matrix.
  5. S = [[0 for j in xrange(len(w)+1)] for i in xrange(len(v)+1)]
  6.  
  7. # Initialize the edges with the given penalties.
  8. for i in xrange(1, len(v)+1):
  9. S[i][0] = -i*sigma
  10. for j in xrange(1, len(w)+1):
  11. S[0][j] = -j*sigma
  12.  
  13. # Fill in the Score and Backtrack matrices.
  14. for i in xrange(1, len(v)+1):
  15. for j in xrange(1, len(w)+1):
  16. scores = [S[i-1][j] - sigma, S[i][j-1] - sigma, S[i-1][j-1] + scoring_matrix[v[i-1], w[j-1]]]
  17. S[i][j] = max(scores)
  18.  
  19. return S[len(v)][len(w)]
  20.  
  21. if __name__ == '__main__':
  22. from scripts import BLOSUM62, ReadFASTA
  23.  
  24. # Parse the two input protein strings.
  25. s, t = [fasta[1] for fasta in ReadFASTA('rosalind_fibd.txt')]
  26.  
  27. # Get the alignment score.
  28. score = str(global_alignment_score(s, t, BLOSUM62(), 5))
  29.  
  30. # Print and save the answer.
  31. print score
  32. with open('011_FIBD.txt', 'w') as output_data:
  33. output_data.write(score)
  34.  
Runtime error #stdin #stdout #stderr 0s 23352KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 22, in <module>
ImportError: No module named scripts