Dynamic Programming • Optimal substructure • Last time • Weighted interval scheduling • Segmented least squares • Today Dynamic Programming II • Sequence alignment • Shortest paths with negative weights Inge Li Gørtz KT section 6.6 and 6.8 Thank you to Kevin Wayne for inspiration to slides � 1 � 2 Sequence alignment • How similar are ACAAGTC and CATGT. • Align them such that • all items occurs in at most one pair. • no crossing pairs. • Cost of alignment • gap penalty δ • mismatch cost for each pair of letters α (p,q). Sequence Alignment • Goal: find minimum cost alignment. A C A A G T C A C A A G T C A C A A G T C A C A A - G T C - C A T G T - - C A T G T - - C A - T G T - - C A T G T - 1 mismatch, 2 gaps 0 mismatches, 4 gaps � 3 � 4
Sequence Alignment Sequence alignment • Subproblem property. X i-1 x i j δ if i = 0 y j Y j-1 if j = 0 i δ SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , • SA(X i ,Y j ) = min cost of aligning strings X[1…i] and Y[1…j]. min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } • Case 1. Align x i and y j . • Pay mismatch cost for x i and y j + min cost of aligning X i-1 and Y j-1 . • Case 2. Leave x i unaligned. Penalty matrix A C A A G T C • Pay gap cost + min cost of aligning X i-1 and Y j . A C G T • Case 3. Leave y j unaligned. C • Pay gap cost + min cost of aligning X i and Y j-1 . A 0 1 2 2 δ = 1 A C 1 0 2 3 T SA ( X 5 , Y 3 ) G 2 2 0 1 G T 2 3 1 0 T � 5 � 6 Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } Penalty matrix Penalty matrix A C A A G T C A C A A G T C A C G T A C G T C C A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A A C 1 0 2 3 C 1 0 2 3 T T SA ( X 5 , Y 3 ) SA ( X 5 , Y 3 ) G 2 2 0 1 G 2 2 0 1 Depends on ? Depends on ? G G T 2 3 1 0 T 2 3 1 0 T T � 7 � 8
Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } min( ) 1+0, 1+1, 1+1 Penalty matrix Penalty matrix A C A A G T C A C A A G T C 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 A C G T A C G T C 1 C 1 A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A 2 A 2 C 1 0 2 3 C 1 0 2 3 T 3 T 3 G 2 2 0 1 G 2 2 0 1 G 4 G 4 T 2 3 1 0 T 2 3 1 0 T 5 T 5 � 9 � 10 Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } min( ) 1+0, 1+1, 1+1 min( ) 0+1, 1+2, 1+1 Penalty matrix Penalty matrix A C A A G T C A C A A G T C 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 A C G T A C G T C 1 1 C 1 1 A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A 2 A 2 C 1 0 2 3 C 1 0 2 3 T 3 T 3 G 2 2 0 1 G 2 2 0 1 G 4 G 4 T 2 3 1 0 T 2 3 1 0 T 5 T 5 � 11 � 12
Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } min( ) 0+1, 1+2, 1+1 min(1+2, 1+3, 1+1) Penalty matrix Penalty matrix A C A A G T C A C A A G T C 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 A C G T A C G T C 1 1 1 C 1 1 1 A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A 2 A 2 C 1 0 2 3 C 1 0 2 3 T 3 T 3 G 2 2 0 1 G 2 2 0 1 G 4 G 4 T 2 3 1 0 T 2 3 1 0 T 5 T 5 � 13 � 14 Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } min(1+2, 1+3, 1+1) min(1+3, 1+4, 1+2) Penalty matrix Penalty matrix A C A A G T C A C A A G T C 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 A C G T A C G T C 1 1 1 2 C 1 1 1 2 A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A 2 A 2 C 1 0 2 3 C 1 0 2 3 T 3 T 3 G 2 2 0 1 G 2 2 0 1 G 4 G 4 T 2 3 1 0 T 2 3 1 0 T 5 T 5 � 15 � 16
Sequence alignment Sequence alignment j δ if i = 0 j δ if i = 0 if j = 0 if j = 0 i δ i δ SA ( X i , Y j ) = SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , min δ + SA ( X i , Y j − 1 ) , otherwise min δ + SA ( X i , Y j − 1 ) , otherwise δ + SA ( X i − 1 , Y j ) } δ + SA ( X i − 1 , Y j ) } min(1+3, 1+4, 1+2) min(2+4, 1+5, 1+3) Penalty matrix Penalty matrix A C A A G T C A C A A G T C 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 A C G T A C G T C 1 1 1 2 3 C 1 1 1 2 3 4 A 0 1 2 2 A 0 1 2 2 δ = 1 δ = 1 A 2 A 2 C 1 0 2 3 C 1 0 2 3 T 3 T 3 G 2 2 0 1 G 2 2 0 1 G 4 G 4 T 2 3 1 0 T 2 3 1 0 T 5 T 5 � 17 � 18 Sequence alignment Sequence alignment SA(X[1…m],Y[1…n], δ ,A){ for i=0 to m j δ if i = 0 M[i,0] := i δ if j = 0 i δ for j=0 to n SA ( X i , Y j ) = α ( x i , y j ) + SA ( X i − 1 , Y j − 1 ) , M[0,j] := j δ min δ + SA ( X i , Y j − 1 ) , otherwise for i=1 to m δ + SA ( X i − 1 , Y j ) } for j = 1 to n M[i,j] := min{ A[i,j] + M[i-1,j-1], δ + M[i-1,j], δ + M[i,j-1]} Penalty matrix Return M[m,n] A C A A G T C } 0 1 2 3 4 5 6 7 A C G T C 1 1 1 2 3 4 5 6 A 0 1 2 2 δ = 1 • Time: Ɵ (mn) A 2 1 2 1 2 3 4 5 C 1 0 2 3 • Space: Ɵ (mn) T 3 2 3 2 3 3 3 4 G 2 2 0 1 G 4 3 4 3 4 3 4 5 T 2 3 1 0 T 5 4 5 4 5 4 3 4 � 19 � 20
Recommend
More recommend