220 likes | 365 Views
Review of Dynamic Programming. SEQUENCE 1. We want to calculate the score for the yellow box. The final score that we fill in the yellow box will be the SUM of two other scores, we’ll call them MATCH and MAX . Let’s try it…. SEQUENCE 2. Score = Sum of MatchScore + MAX Match Score
E N D
Review of Dynamic Programming SEQUENCE 1 We want to calculate the score for the yellow box. The final score that we fill in the yellow box will be the SUM of two other scores, we’ll call them MATCH and MAX. Let’s try it… SEQUENCE 2
Score = Sum of MatchScore+MAX • Match Score • whether the sequence matches at that location • 1 for match / 0 for non match • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) j-4 Dynamic Programming j-3 j-2 j-1 j i-4 i-3 i-2 i-1 i Fill in the Table from the top left hand corner!
FILL in the Table from the top left hand corner! Dynamic Programming – Filling in the Table! A B B C D The MATCH score is assigned based on whether the residues at position i, j (i.e. yellow box) matches. In this case, the residues at i, j are A and A which matches. Therefore, the MATCH score would be 1. Since there are no i-1 or j-1 (i.e no column/rows on top) we don’t have to worry about the MAX part of the score. A B C C C
Dynamic Programming – Filling in the Table! A B B C D Moving one square to the right. In this case, the residues at i, j are B and A and match. Therefore, the MATCH score would be 0. Again there are no i-1 or j-1 (i.e no column/rows on top) we don’t have to worry about the MAX part of the score. A B C C C
Dynamic Programming – Filling in the Table! A B B C D We can filled in the rest of the first column and first row A B C C C
Let’s move to the 2nd row • Score = Sum of MatchScore+MAX • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • In this case there is no 2 or 3 to consider • MatchScore = 1 • MAX = 1 • Score = 1 + 1 = 2 Dynamic Programming – Filling in the Table! A B B C D A B C C C
Moving across the row • Score = Sum of MatchScore+MAX • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • MatchScore = 1 • MAX = 1 • Score = 1 + 1 = 2 Dynamic Programming – Filling in the Table! A B B C D A B C C C
Moving across the row again! • Score = Sum of MatchScore+MAX • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • MatchScore = 0 • MAX = 1 • Score = 0 + 1 = 1 • We can fill in the last square using the same method = 1 Dynamic Programming – Filling in the Table! A B B C D A B C C C
Moving to the next row • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • MatchScore = 0 • MAX = 1 • Score = 0 + 1 = 1 Dynamic Programming – Filling in the Table! A B B C D A B C C C
Moving to the next row • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • MatchScore = 0 • MAX = 2 • Score = 0 + 2 = 2 Dynamic Programming – Filling in the Table! A B B C D A B C C C
Moving to the next row • MAX (the highest of the following three) • The score in the box at position i-1, j-1 • The highest score in the row i-x, j-1 (where 2<=x<i) • The highest score in the column i-1, j-y (where 2<=y<j) • MatchScore = 1 • MAX = 2 OR2 • Score = 1 + 2 = 3 • We can fill in the last square in similar fashion Dynamic Programming – Filling in the Table! A B B C D A B C C C
Dynamic Programming – Filling in the Table! A B B C D We can fill in the remaining squares! A B C C C
The LAST Square! MATCH = 0 MAX = 3 Score = 0+3 = 3 Dynamic Programming – Filling in the Table! A B B C D A B C C C
QUESTIONS? A B B C D A B C C C
Traceback Protocol Used to get the alignment from the filled in table. Start in the lower right corner. You can only move to the largest number that is UP and TO THE LEFT. D D
Traceback Protocol All 3 paths start like this. But, moving up and to the left from the square with score 2, we have two possible choices, both of which are up and to the left, and contain equal values. VD VD
Traceback Protocol We now have two possible alignments – red and yellow. Yellow has only one more square it can access. The red alignment can branch off again, however. ATVD V-VD TVD VVD
Traceback Protocol These are the 3 possible paths through the matrix, in other words, the 3 possible alignments. AATVD -AVVD AATVD AV-VD AATVD A-VVD
Traceback Protocol Every time a diagonal line “skips” a box (i.e does not lead into the box immediately to the upper left (i-1, j-1), we insert a gap into the alignment.
Traceback Protocol AATVD -AVVD AATVD AV-VD AATVD A-VVD
Traceback Protocol Is this possible?? AATV-D -A-VVD Optimal alignment??
QUESTIONS?? AATVD -AVVD AATVD AV-VD AATVD A-VVD