Sequence Alignment problem
Given as an input two strings, = , and = , output the alignment of the strings, character by character, so that the net penalty is minimised. The penalty is calculated as:
1. A penalty of occurs if a gap is inserted between the string.
2. A penalty of occurs for mis-matching the characters of and .
Input : X = CG, Y = CA, p_gap = 3, p_xy = 7 Output : X = CG_, Y = C_A, Total penalty = 6 Input : X = AGGGCT, Y = AGGCA, p_gap = 3, p_xy = 2 Output : X = AGGGCT, Y = A_GGCA, Total penalty = 5 Input : X = CG, Y = CA, p_gap = 3, p_xy = 5 Output : X = CG, Y = CA, Total penalty = 5
A brief Note on the history of the problem
The Sequence Alignment problem is one of the fundamental problems of Biological Sciences, aimed at finding the similarity of two amino-acid sequences. Comparing amino-acids is of prime importance to humans, since it gives vital information on evolution and development. Saul B. Needleman and Christian D. Wunsch devised a dynamic programming algorithm to the problem and got it published in 1970. Since then, numerous improvements have been made to improve the time complexity and space complexity, however these are beyond the scope of discussion in this post.
Solution We can use dynamic programming to solve this problem. The feasible solution is to introduce gaps into the strings, so as to equalise the lengths. Since it can be easily proved that the addition of extra gaps after equalising the lengths will only lead to increment of penalty.
It can be observed from an optimal solution, for example from the given sample input, that the optimal solution narrows down to only three candidates.
1. and .
2. and gap.
3. gap and .
Proof of Optimal Substructure.
We can easily prove by contradiction. Let be and be . Suppose that the induced alignment of , has some penalty , and a competitor alignment has a penalty , with .
Now, appending and , we get an alignment with penalty . This contradicts the optimality of the original alignment of .
Let be the penalty of the optimal alignment of and . Then, from the optimal substructure, .
The total minimum penalty is thus, .
Reconstructing the solution
1. Trace back through the filled table, starting .
…..2a. if it was filled using case 1, go to .
…..2b. if it was filled using case 2, go to .
…..2c. if it was filled using case 3, go to .
3. if either i = 0 or j = 0, match the remaining substring with gaps.
Below is the implementation of the above solution.
Minimum Penalty in aligning the genes = 5 The aligned genes are : AGGGCT A_GGCA
Time Complexity :
Space Complexity :