Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Project 3: Dynamic Programming Optimal String Alignment Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Development of a Dynamic Programming Algorithm 1. Characterize the structure of a solution 2. Recursively define the value of a solution 3. Compute the value of a solution in a bottom-up fashion(using a table) 4. Construct a solution from computed information Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment Images taken from http://www.sbc.su.se/~per/molbioinfo2001/dynprog/dynamic.html • Want to find optimal (best) alignment between two strings where matches count as 1, mismatches count as 0, and “gaps” count as 0. Example: G A A T T C A G T T A G G A T C G A G _ A A T T C A G T T A G G _ A _ T C _ G _ _ A Score == 6 • Notice that every alignment can start in exactly one of three ways: (1) Two non-gap characters (2) Non-gap above, gap below (3) Gap above, non-gap below Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment • Notice in an optimal alignment of (s1,s2,…,sn) with (t1,t2,…,tm) one of these must be true: (1) S2..n must be optimally aligned with T2..m (2) S2..n must be optimally aligned with T1..m (3) S1..n must be optimally aligned with T2..m • The score of each is then (1) Score(S2..n, T2..m) + Score(S1,T1) (2) Score(S2..n, T1..m) + Score(S1,gap) (3) Score(S1..n, T2..m) + Score(T1,gap) • We want to select the maximum of these, giving Score(S1..n, T1..m) = max(Score(S2..n, T2..m) + Score(S1,T1), Only gives score of optimal, Score(S2..n, T1..m) + Score(S1,gap), not actual alignment Score(S1..n, T2..m) + Score(gap,T1)) base case given by scoring function Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment • Let’s build a table, M, of values such that M[i][j] is the optimal score for S1..i aligned with T1..j. • If we have this, M[n][m] is the overall optimal score • M is zero-indexed to allow for beginning gap • Notice by our recurrence relation, M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment Base Case M[i][0] = Score(Si,gap) M[0][j] = Score(gap,Sj) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment M[i][j] = max(M[i-1][j-1] + Score(Si,Tj), M[i][j-1] + Score(gap,Tj), M[i-1][j] + Score(Si,gap)) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Optimal String Alignment • Still need to find actual alignment that results in maximum score • Can be done by tracing back from optimal value to find where it must have originated representing earlier optimal alignment G _ A A T T C A G T T A G G _ A _ T C _ G _ _ A
© Copyright 2026 Paperzz