. Sequence Alignment I Lecture #2 This class has been edited from Nir Friedman’s lecture. Changes...
-
date post
22-Dec-2015 -
Category
Documents
-
view
217 -
download
0
Transcript of . Sequence Alignment I Lecture #2 This class has been edited from Nir Friedman’s lecture. Changes...
.
Sequence Alignment ILecture #2
This class has been edited from Nir Friedman’s lecture. Changes made by Dan Geiger, then Shlomo Moran.
Background Readings: The second chapter (pages 12-45) in the text book, Biological Sequence Analysis, Durbin et al., 2001.
2
Sequence Comparison
Much of bioinformatics involves sequences DNA sequences RNA sequences Protein sequences
We can think of these sequences as strings of letters
DNA & RNA: alphabet ∑ of 4 letters Protein: alphabet ∑ of 20 letters
3
Sequence Comparison (cont)
Finding similarity between sequences is important for many biological questions
For example: Find similar proteins
Allows to predict function & structure Locate similar subsequences in DNA
Allows to identify (e.g) regulatory elements Locate DNA sequences that might overlap
Helps in sequence assembly
g1
g2
4
Sequence Alignment
Input: two sequences over the same alphabet
Output: an alignment of the two sequences
Example: GCGCATGGATTGAGCGA TGCGCCATTGATGACCA
A possible alignment:
-GCGC-ATGGATTGAGCGA
TGCGCCATTGAT-GACC-A
5
Alignments
-GCGC-ATGGATTGAGCGA
TGCGCCATTGAT-GACC-A
Three elements: Perfect matches Mismatches Insertions & deletions (indel)
6
Choosing Alignments
There are many possible alignments
For example, compare:
-GCGC-ATGGATTGAGCGA
TGCGCCATTGAT-GACC-A
to
------GCGCATGGATTGAGCGA
TGCGCC----ATTGATGACCA--
Which one is better?
7
Scoring Alignments
Intuition: Similar sequences evolved from a common
ancestor Evolution changed the sequences from this
ancestral sequence by mutations: Replacements: one letter replaced by another Deletion: deletion of a letter Insertion: insertion of a letter
Scoring of sequence similarity should examine how many and which operations took place
8
Simple Scoring Rule
Score each position independently: Match: +1 Mismatch : -1 Indel -2
Score of an alignment is sum of position scores
9
Example
Example:
-GCGC-ATGGATTGAGCGA
TGCGCCATTGAT-GACC-A
Score: (+1x13) + (-1x2) + (-2x4) = 3
------GCGCATGGATTGAGCGA
TGCGCC----ATTGATGACCA--
Score: (+1x5) + (-1x6) + (-2x11) = -23
10
More General Scores
The choice of +1,-1, and -2 scores is quite arbitrary Depending on the context, some changes are more
plausible than others Exchange of an amino-acid by one with similar
properties (size, charge, etc.)
vs. Exchange of an amino-acid by one with opposite
properties Probabilistic interpretation: (e.g.) How likely is one
alignment versus another ?
11
Additive Scoring Rules
We define a scoring function by specifying a function
(x,y) is the score of replacing x by y (x,-) is the score of deleting x (-,x) is the score of inserting x
The score of an alignment is the sum of position scores
}){(}){(:
12
The Optimal Score
The optimal (maximal) score between two sequences is the maximal score of all alignments of these sequences, namely,
Computing the maximal score or actually finding an alignment that yields the maximal score are closely related tasks with similar algorithms.
One more comment before we start...
nment)score(aligmax),d( & of alignment 21 ss21 ss
13
Alternative view: Edit Distance
Instead of speaking about the score of an alignment, one often talks about an edit distance between two sequences, defined to be the “cost” of the “cheapest” set of edit operations needed to transform one sequence into the other. Cheapest operation is “no change” Next cheapest operation is “replace” The most expensive operations are “add space/delete”.
Our goal is now to minimize the cost of operations.
14
Computing Optimal Score
How can we compute the optimal score ? If |s| = m and |t| = n, the number A(m,n) of
possible “legal” alignments is large!
Exercise: Show that
The additive form of the score allows us to perform dynamic programming to compute optimal score efficiently.
2
( , )m n m n
A m nm m
15
Recursive Argument (Needleman Wunsch, 1970)
Suppose we have two sequences:s[1..m+1] and t[1..n+1]
The last column in a best alignment must be one of :
1. Last column is (s[m+1],t[n +1] )2. Last column is (s[m +1],-)3. Last column is (-, t[n +1] )
1 1 1 1 1 1
1 1
( [ .. ], [ .. ]) ( [ .., ], [ .. ])
( [ ], [ ])
d s m t n d s m t n
s m t n
16
Recursive Argument
Suppose we have two sequences:s[1..n+1] and t[1..m+1]
The best alignment must be one of three cases:
1. Last match is (s[m+1],t[n +1] )2. Last match is (s[m +1],-)3. Last match is (-, t[n +1] )
1 1 1 1 1 1 1
1
( [ .. ], [ .. ]) ( [ .., ], [ .. ])
( [ ], )
d s m t n d s m t n
s m
17
Recursive Argument
Suppose we have two sequences:s[1..n+1] and t[1..m+1]
The best alignment must be one of three cases:
1. Last match is (s[m+1],t[n +1] )2. Last match is (s[m +1],-)3. Last match is (-, t[n +1] )
1 1 1 1 1 1 1
1
( [ .. ], [ .. ]) ( [ .., ], [ .. ])
( , [ ])
d s m t n d s m t n
t n
18
Recursive Argument
Define the notation:
Using our recursive argument, we get the following recurrence for V:
])[,(],[
)],[(],[
])[],[(],[
max],[
1jtj1iV
1is1jiV
1jt1isjiV
1j1iV
])..[],..[(],[ j1ti1sdjiV
V[i,j] V[i+1,j]
V[i,j+1] V[i+1,j+1]
19
Recursive Argument
Of course, we also need to handle the base cases in the recursion:
])[,(],[],[
)],[(],[],[
],[
1jtj0V1j0V
1is0iV01iV
000V
0 A 1
G 2
C 3
0 0 -2 -4 -6
A 1 -2
A 2 -4
A 3 -6
C 4 -8
AA- -
We fill the matrix using the recurrence rule:
ST
versus
20
Dynamic Programming Algorithm
We continue to fill the matrix using the recurrence rule
0
A 1
G 2
C 3
0 0 -2 -4 -6
A 1 -2
A 2 -4
A 3 -6
C 4 -8
ST
21
Dynamic Programming Algorithm
0
A 1
G 2
C 3
0 0 -2 -4 -6
A 1 -2 1
A 2 -4
A 3 -6
C 4 -8
V[0,0] V[0,1]
V[1,0] V[1,1]
+1-2 -A A-
-2 (A- versus -A)
versus
ST
22
Dynamic Programming Algorithm
0
A 1
G 2
C 3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0
A 3 -6 -3
C 4 -8 -5
ST
23
Dynamic Programming Algorithm
0
A 1
G 2
C 3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0 -2
A 3 -6 -3 -2 -1
C 4 -8 -5 -4 -1
Conclusion: d(AAAC,AGC) = -1
ST
24
Reconstructing the Best Alignment
To reconstruct the best alignment, we record which case(s) in the recursive rule maximized the score
0A1
G2
C3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0 -2
A 3 -6 -3 -2 -1
C 4 -8 -5 -4 -1
ST
25
Reconstructing the Best Alignment
We now trace back a path that corresponds to the best alignment
0A1
G2
C3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0 -2
A 3 -6 -3 -2 -1
C 4 -8 -5 -4 -1
AAACAG-C
ST
26
Reconstructing the Best Alignment
Sometimes, more than one alignment has the best score
0A1
G2
C3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0 -2
A 3 -6 -3 -2 -1
C 4 -8 -5 -4 -1
ST
AAACA-GC
AAAC-AGC
AAACAG-C
27
Time Complexity
Space: O(mn)Time: O(mn) Filling the matrix O(mn) Backtrace O(m+n)
0A1
G2
C3
0 0 -2 -4 -6
A 1 -2 1 -1 -3
A 2 -4 -1 0 -2
A 3 -6 -3 -2 -1
C 4 -8 -5 -4 -1
ST
28
Space Complexity
In real-life applications, n and m can be very large The space requirements of O(mn) can be too
demanding If m = n = 1000, we need 1MB space If m = n = 10000, we need 100MB space
We can afford to perform extra computation to save space Looping over million operations takes less than
seconds on modern workstations
Can we trade space with time?
29
Why Do We Need So Much Space?
Compute V(i,j), column by column, storing only two columns in memory (or row by row if rows are shorter). 0
-2
-4
-6
-8
-2
1
-1
-3
-5
-4
-1
0
-2
-4
-6
-3
-2
-1
-1
0A1
G2
C3
0
A 1
A 2
A 3
C 4
Note however that This “trick” fails when we
need to reconstruct the optimizing sequence.
Trace back information requires O(mn) memory bytes.
To compute V[m,n]=d(s[1..m],t[1..n]), we need only O(min(m,n)) space:
30
Space Efficient Version: Outline
If m=1 align s[1,1] and t[1,m] Else, find position (i,n/2) at which some best
alignment crosses a midpoint s
t
Construct alignments A=s[1,n/2] vs t[1,i] B=s[n/2+1,m] vs
t[i+1,n] Return AB
Input: Sequences s[1,m] and t[1,n] to be aligned.
Idea: perform divide and conquer
31
Finding a Midpoint
The score of the best alignment that goes through j equals:
d(s[1,m/2],t[1,i]) + d(s[m/2+1,n],t[i+1,m])
Thus, we need to compute these two quantities for all values of i
s
t
32
Finding a Midpoint (Algorithm)
Define F[i,j] = d(s[1,i],t[1,j]) B[i,j] = d(s[i+1,n],t[j+1,m])
F[i,j] + B[i,j] = score of best alignment through (i,j)
We compute F[i,j] as we did before We compute B[i,j] in exactly the same manner,
going “backward” from B[n,m]
Requires linear space complexity
33
Time Complexity Analysis Time to find a mid-point: cnm (c - a constant) Size of recursive sub-problems is
(n/2,i) and (n/2,m-i), hence
T(n,m) = cnm + T(n/2,i) + T(n/2,m-i)
Lemma: T(n,m) 2cnmProof (by induction):
T(n,m) cnm + 2c(n/2)i + 2c(n/2)(m-i) = 2cnm.
Thus, time complexity is linear in size of the problem
At worst, twice the cost of the regular solution.
34
Local Alignment
Consider now a different question: Can we find similar substrings of s and t Formally, given s[1..m] and t[1..n] find i,j,k, and l
such that d(s[i..j],t[k..l]) is maximal
35
Local Alignment
As before, we use dynamic programming We now want to setV[i,j] to record the best
alignment of a suffix of s[1..i] and a suffix of t[1..j]
How should we change the recurrence rule? Same as before but with an option to start afresh
The result is called the Smith-Waterman algorithm
36
Local Alignment
New option: We can start a new match instead of extending a
previous alignment
0
1jtj1iV1is1jiV
1jt1isjiV
1j1iV])[,(],[)],[(],[
])[],[(],[
max],[
Alignment of empty suffixes
]))1[,(],0[,0max(]1,0[
))],1[(]0,[,0max(]0,1[
0]0,0[
jtjVjV
isiViV
V
37
Local Alignment Example
0
A 1
T 2
C 3
T 4
A 5
A 6
0 0 0 0 0 0 0 0
T 1 0
A 2 0
A 3 0
T 4 0
A 5 0
s = TAATAt = TACTAA
ST
38
Local Alignment Example
0
T 1
A 2
C 3
T 4
A 5
A 6
0 0 0 0 0 0 0 0
T 1 0 1 0 0 1 0 0
A 2 0 0 2 0 0 2 1
A 3 0
T 4 0
A 5 0
s = TAATAt = TACTAA
ST
39
Local Alignment Example
0T1
A2
C3
T4
A5
A6
0 0 0 0 0 0 0 0
T 1 0 1 0 0 1 0 0
A 2 0 0 2 0 0 2 1
A 3 0 0 1 1 0 1 3
T 4 0 0 0 0 2 0 1
A 5 0 0 1 0 0 3 1
s = TAATAt = TACTAA
ST
40
Local Alignment Example
0T1
A2
C3
T4
A5
A6
0 0 0 0 0 0 0 0
T 1 0 1 0 0 1 0 0
A 2 0 0 2 0 0 2 1
A 3 0 0 1 1 0 1 3
T 4 0 0 0 0 2 0 1
A 5 0 0 1 0 0 3 1
s = TAATAt = TACTAA
ST
41
Local Alignment Example
0T1
A2
C3
T4
A5
A6
0 0 0 0 0 0 0 0
T 1 0 1 0 0 1 0 0
A 2 0 0 2 0 0 2 1
A 3 0 0 1 1 0 1 3
T 4 0 0 0 0 2 0 1
A 5 0 0 1 0 0 3 1
s = TAATAt = TACTAA
ST
42
Alignment in Real Life
One of the major uses of alignments is to find sequences in a “database.”
Today’s protein database contains more than 108 residues! So searching a 103 long target sequence requires to evaluate about 1011 matrix cells which will take about three hours in the rate of 10 millions evaluations per second.
Quite annoying when, say, one thousand target sequences need to be searched because it will take about four months to run.