review of dynamic programming
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
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 1
SE
QU
EN
CE
2
Review of Dynamic Programming
Dynamic Programming
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)1. The score in the box at position
i-1, j-12. The highest score in the row i-x, j-1
(where 2<=x<i)3. The highest score in the column
i-1, j-y (where 2<=y<j)
i-4 i-3 i-2 i-1 i
j
j-1
j-2
j-3
j-4
Fill in the Table from the top left hand corner!
Dynamic Programming – Filling in the Table!
1The 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 B C D
A B C
C C
FILL in the Table from the top left hand corner!
Dynamic Programming – Filling in the Table!
1 0Moving 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 B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00000
We can filled in the rest of the first column and first row
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2000
Let’s move to the 2nd row
Score = Sum of MatchScore + MAX
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. 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 = 1MAX = 1
Score = 1 + 1 = 2
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2000
Moving across the row
Score = Sum of MatchScore + MAX
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. The highest score in the column i-1, j-y (where
2<=y<j)
MatchScore = 1MAX = 1
Score = 1 + 1 = 2
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 1000
Moving across the row again!
Score = Sum of MatchScore + MAX
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. The highest score in the column i-1, j-y (where
2<=y<j)
MatchScore = 0MAX = 1
Score = 0 + 1 = 1
We can fill in the last square using the same method = 1
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 10 100
Moving to the next row
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. The highest score in the column i-1, j-y (where
2<=y<j)
MatchScore = 0MAX = 1
Score = 0 + 1 = 1
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 10 1 200
Moving to the next row
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. The highest score in the column i-1, j-y (where
2<=y<j)
MatchScore = 0MAX = 2
Score = 0 + 2 = 2
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 10 1 2 3 200
Moving to the next row
MAX (the highest of the following three)1. The score in the box at position i-1, j-12. The highest score in the row i-x, j-1 (where
2<=x<i)3. The highest score in the column i-1, j-y (where
2<=y<j)
MatchScore = 1MAX = 2 OR 2
Score = 1 + 2 = 3
We can fill in the last square in similar fashion
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 10 1 2 3 20 1 2 3 30 1 2 3
We can fill in the remaining squares!
A B B C D
A B C
C C
Dynamic Programming – Filling in the Table!
1 0 0 0 00 2 2 1 10 1 2 3 20 1 2 3 30 1 2 3 3
The LAST Square!
MATCH = 0MAX = 3
Score = 0+3 = 3
A B B C D
A B C
C C
QUESTIONS?
1 0 0 0 0
0 2 2 1 1
0 1 2 3 2
0 1 2 3 3
0 1 2 3 3
A B B C D
A B C
C C
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
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.
DD
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
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.
VDVD
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
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.
TVDVVD
ATVDV-VD
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
These are the 3 possible paths through the matrix, in other words, the 3 possible alignments.
AATVD-AVVD
AATVDAV-VD
AATVDA-VVD
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
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
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
AATVD-AVVD
AATVDAV-VD
AATVDA-VVD
Traceback Protocol
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
Is this possible??
AATV-D-A-VVD
Optimal alignment??
QUESTIONS??
A A T V D
A 1 1 0 0 0
V 0 1 1 2 1
V 0 1 1 2 2
D 0 1 1 1 3
AATVD-AVVD
AATVDAV-VD
AATVDA-VVD