Docsity

Bioinformatic Algorithms: Dynamic Programming for Inexact String Alignment, Study notes of Computer Science

Partial preview of the text

Download Bioinformatic Algorithms: Dynamic Programming for Inexact String Alignment and more Study notes Computer Science in PDF only on Docsity!

CMSC423: Bioinformatic Algorithms,

Databases and Tools

Lecture 10

inexact alignment

dynamic programming, gapped

alignment

Intuition

• What is the best way to align strings S1 and S2?

• just look at last character for now – what is it aligned

to?

S1[n]

S2[m]

S1[n]

S2[m]

S1[n]

S2[m]

AG-C-GTAG

-GTCAG-A-

The dynamic programming table

Score[i,j] is the maximum of:

  1. Score[i-1, j-1] + Value(S1[i],S2[j]) (S1[i-1], S2[j-1] aligned)
  2. Score[i – 1, j] + Value(S1[i], -) (S1[i] aligned to gap)
  3. Score[i, j – 1] + Value(-, S2[j]) (S2[j] aligned to gap)

A

G

A

C

T

G

A

G

C G T A G Value (A, A) = 10 Value (A, G) = - Value (A, -) = -

Note: we only look at 3 adjacent boxes

How do you output the result?

• Goal: produce the “nice” string with gaps that is shown

in the examples

• Idea: create the string backwards – starting from the

right

• As you follow backtrack pointers:

  • if you follow diagonal pointer – add characters to both output strings (aligned versions of original strings)
  • if you move up – add gap character to string represented on the y axis, add string character to string represented on x axis
  • if you move left – gap goes in string on x axis and character in string on y axis

• When you reach (0,0) output the two aligned strings

Sub-string alignment

T

G

C

A G

C G T A G

AGCGTAG

CGT

Local alignment

• What if we just want a region of similarity?

ACAGTTGACCCGTGCAT

GTCATG-CC-GAGATCG

• First row and column set to 0s

• Allow alignment to start anywhere:

Score[i,j] = max{0, case 1, case 2, case 3}

• Answer is location in matrix with highest score

Various flavors of alignment

• Alignment problem also called "edit distance" – how

many changes do you have to make to a string to

convert it into another one.

• Edit distance also called Levenshtein distance

• Local alignment – Smith-Waterman

• Global alignment – Needleman-Wunsch

11

Gap penalties

Dynamic programming solution

• Traditional 1-table approach doesn't work anymore

• Instead, use 4 tables:

  • V – stores value of best alignment between S1[1..i], S2[1..j]
  • G – best alignment between S1[1..i], S2[1..j] s.t. S1[i] aligned with S2[j]
  • E – best alignment between S1[1..i], S2[1..j], s.t. alignment ends with gap in S
  • F – best alignment between S1[1..i], S2[1..j], s.t. alignment ends with gap in S

• V[i,j] = max(E[i,j], F[i,j], G[i,j])

• As in traditional approach, find box in V matrix where

V[i,j] is maximal.

Affine gap recurrences

• V[i,j] = max[E[i,j], F[i,j], G[i,j] ]

• G[i,j] = V[i-1, j-1] + Value(S1[i], S2[j])

  • irrespective how we got here (hence use of V), S1[i] and S2[j] are matched

• E[i,j] = max{E[i, j-1], V[i, j-1] – GapOpen} – GapExtend

  • either we add a gap in S1 to an existing one (E-GapExtend)
  • or we add a gap in S1 when there was none (V-GapOpen- GapExtend)

• F[i,j] = max{F[i-1, j], V[i-1, j] – GapOpen} – GapExtend

  • either we add a gap in S2 to an existing one (F–GapExtend)
  • or we add a gap in S2 when there was none (V-GapOpen- GapExtend)