Author: bugman Date: Thu Jan 29 15:36:05 2015 New Revision: 27353 URL: http://svn.gna.org/viewcvs/relax?rev=27353&view=rev Log: The Needleman-Wunsch sequence alignment algorithm now calculates and returns an alignment score. This is in the lib.sequence_alignment.needleman_wunsch.needleman_wunsch_align() function. The score is calculated as the sum of the Needleman-Wunsch matrix elements along the traceback path. Modified: trunk/lib/sequence_alignment/needleman_wunsch.py Modified: trunk/lib/sequence_alignment/needleman_wunsch.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/sequence_alignment/needleman_wunsch.py?rev=27353&r1=27352&r2=27353&view=diff ============================================================================== --- trunk/lib/sequence_alignment/needleman_wunsch.py (original) +++ trunk/lib/sequence_alignment/needleman_wunsch.py Thu Jan 29 15:36:05 2015 @@ -63,8 +63,8 @@ @type end_gap_open_penalty: float @keyword end_gap_extend_penalty: The optional penalty for extending a gap at the end of a sequence. @type end_gap_extend_penalty: float - @return: The two alignment strings and the gap matrix. - @rtype: str, str, numpy rank-2 int array + @return: The alignment score, two alignment strings and the gap matrix. + @rtype: float, str, str, numpy rank-2 int array """ # The sequence lengths. @@ -83,6 +83,7 @@ matrix, traceback_matrix = needleman_wunsch_matrix(sequence1, sequence2, sub_matrix=sub_matrix, sub_seq=sub_seq, gap_open_penalty=gap_open_penalty, gap_extend_penalty=gap_extend_penalty, end_gap_open_penalty=end_gap_open_penalty, end_gap_extend_penalty=end_gap_extend_penalty) # Generate the alignment. + score = 0.0 i = M - 1 j = N - 1 alignment1 = "" @@ -115,6 +116,9 @@ if i < 0 and j < 0: break + # Update the total score. + score += matrix[i, j] + # Reverse the alignments. align1 = alignment1[::-1] align2 = alignment2[::-1] @@ -128,7 +132,7 @@ gaps[1, l] = 1 # Return the alignments and gap matrix. - return align1, align2, gaps + return score, align1, align2, gaps def needleman_wunsch_matrix(sequence1, sequence2, sub_matrix=None, sub_seq=None, gap_open_penalty=SCORE_GAP_PENALTY, gap_extend_penalty=1.0, end_gap_open_penalty=0.0, end_gap_extend_penalty=0.0, epsilon=1e-7):