660 likes | 670 Views
Understand the concept of sequence alignment and its importance in comparing DNA, RNA, and protein sequences. Discover the scoring and additive scoring rules used in aligning sequences and the dynamic programming algorithm for finding optimal alignments.
E N D
Sequence Alignment AGGCTATCACCTGACCTCCAGGCCGATGCCC TAGCTATCACGACCGCGGTCGATTTGCCCGAC -AGGCTATCACCTGACCTCCAGGCCGA--TGCCC--- TAG-CTATCAC--GACCGC--GGTCGATTTGCCCGAC Definition Given two strings x = x1x2...xM, y = y1y2…yN, an alignment is an assignment of gaps to positions 0,…, N in x, and 0,…, N in y, so as to line up each letter in one sequence with either a letter, or a gap in the other sequence
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
Sequence Comparison • Finding similarity between sequences is important for many biological questions • During evolution biological evolves (mutation, deletion, duplication, addition, move of subsequences…) • Homologous (share a common ancestor) sequences are (relatively) similar • Algorithms try to detect similar sequence that possibly share a common function
g1 g2 Sequence Comparison (cont) 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
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
Alignments -GCGC-ATGGATTGAGCGA TGCGCCATTGAT-GACC-A Three elements: • Matches • Mismatches • Insertions & deletions (indel)
Choosing Alignments There are many possible alignments For example, compare: -GCGC-ATGGATTGAGCGA TGCGCCATTGAT-GACC-A to ------GCGCATGGATTGAGCGA TGCGCC----ATTGATGACCA-- Which one is better?
Scoring Alignments Intuition: • Similar sequences evolved from a common ancestor • Evolution changed the sequences from this ancestral sequence by mutations: • Substitution: 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
Simple Scoring Rule Score each position independently: • Match m: +1 • Mismatch s: -1 • Indel d: -2 Score of an alignment is sum of position scores Scoring Function: Match: m m≥0 Mismatch: s s≤0 Gap: d s≤0 Score F = (#matches)m + (#mismatches)s + (#gaps)d
Example Example: -GCGC-ATGGATTGAGCGA TGCGCCATTGAT-GACC-A Score: (+1x13) + (-1x2) + (-2x4) = 3 ------GCGCATGGATTGAGCGA TGCGCC----ATTGATGACCA-- Score: (+1x5) + (-1x6) + (-2x11) = -23
More General Scores • The choice of +1,-1, and -2 scores is quite arbitrary • Depending on the context, some changes are moreplausible than others • Exchange of an amino-acid by one with similar properties (size, charge, etc.) • Exchange of an amino-acid by one with opposite properties • Probabilistic interpretation: (e.g.) How likely is one alignment versus another ?
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
How do we compute the best alignment? AGTGCCCTGGAACCCTGACGGTGGGTCACAAAACTTCTGGA • Alignment is a path from cell (0,0) to cell (m,n) • Too many possible alignments: • O( 2M+N) AGTGACCTGGGAAGACCCTGACCCTGGGTCACAAAACTC
The Optimal Score • The optimal alignment score between two sequences is the maximal score over all alignments of these sequences: • Computing the maximal score or actually finding an alignment that yields the maximal score are closely related tasks with similar algorithms. • We now address these two problems.
Alignment is additive Observation: The score of aligning x1……xM y1……yN is additive Say that x1…xi xi+1…xM aligns to y1…yj yj+1…yN The two scores add up: V(x[1:M], y[1:N]) = V(x[1:i], y[1:j]) + V(x[i+1:M], y[j+1:N])
Dynamic Programming • We will now describe a dynamic programming algorithm Suppose we wish to align x1……xM y1……yN Let V(i,j) = optimal score of aligning x1……xi y1……yj
Dynamic Programming Notice three possible cases: • xi aligns to yj x1……xi-1 xi y1……yj-1 yj 2. xi aligns to a gap x1……xi-1 xi y1……yj - • yj aligns to a gap x1……xi - y1……yj-1 yj m, if xi = yj V(i,j) = V(i-1, j-1) + s, if not V(i,j) = V(i-1, j) + d V(i,j) = V(i, j-1) + d
Dynamic Programming • How do we know which case is correct? Inductive assumption: V(i, j-1), V(i-1, j), V(i-1, j-1) are optimal Then, V(i-1, j-1) + σ(xi, yj) V(i, j) = max V(i-1, j) + d V( i, j-1) + d Where σ(xi, yj) = m, if xi = yj; s, if not
Recursive Argument Define the notation: • Using our recursive argument, we get the following recurrence for V:
T S Recursive Argument • Of course, we also need to handle the base cases in the recursion: AA - - versus We fill the matrix using the recurrence rule:
T S Dynamic Programming Algorithm We continue to fill the matrix using the recurrence rule
T S +1 -2 -A A- -2 (A- versus -A) Dynamic Programming Algorithm versus
T S Dynamic Programming Algorithm
T S Conclusion: d(AAAC,AGC) = -1 Dynamic Programming Algorithm
T S Reconstructing the Best Alignment • To reconstruct the best alignment, we record which case(s) in the recursive rule maximized the score
T S AAAC AG-C Reconstructing the Best Alignment • We now trace back a path that corresponds to the best alignment
T S AAAC -AGC AAAC AG-C Reconstructing the Best Alignment • Sometimes, more than one alignment has the best score AAAC A-GC
The Needleman-Wunsch Matrix x1 ……………………………… xM Every nondecreasing path from (0,0) to (M, N) corresponds to an alignment of the two sequences y1 ……………………………… yN An optimal alignment is composed of optimal subalignments
The Needleman-Wunsch AlgorithmGlobal Alignment Algorithm • Initialization. • F(0, 0) = 0 • F(0, j) = j d • F(i, 0) = i d • Main Iteration. Filling-in partial alignments • For each i = 1……M For each j = 1……N F(i-1,j-1) + s(xi, yj) [case 1] F(i, j) = max F(i-1, j) + d [case 2] F(i, j-1) + d [case 3] DIAG, if [case 1] Ptr(i,j) = LEFT, if [case 2] UP, if [case 3] • Termination. F(M, N) is the optimal score, and from Ptr(M, N) can trace back optimal alignment
T S Time Complexity Space: O(mn) Time: O(mn) • Filling the matrix O(mn) • Backtrace O(m+n)
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?
A G C 1 2 3 0 0 0 -2 -4 -6 1 -2 1 -1 -3 A 2 -4 -1 0 -2 A 3 -6 -3 -2 -1 A 4 -8 -5 -4 -1 C Why Do We Need So Much Space? To compute V[n,m]=d(s[1..n],t[1..m]), we need only O(min(n,m)) space: • Compute V(i,j), column by column, storing only two columns in memory (or line by line if lines are shorter). Note however that • This “trick” fails when we need to reconstruct the optimizing sequence. • Trace back information requires O(mn) memory bytes.
s t Space Efficient Version: Outline Input: Sequences s[1,n] and t[1,m] to be aligned. Idea: perform divide and conquer • If n=1 align s[1,1] and t[1,m] • Else, find position (n/2, j) at which some best alignment crosses a midpoint • Construct alignments • A=s[1,n/2] vs t[1,j] • B=s[n/2+1,n] vs t[j+1,m] • Return AB
s t Finding the Midpoint The score of the best alignment that goes through j equals: d(s[1,n/2],t[1,j]) + d(s[n/2+1,n],t[j+1,m]) • Thus, we need to compute these two quantities for all values of j
Finding the 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 because there is no need to keep trace back information in this step
Time Complexity Analysis • Time to find a mid-point: cnm (c - a constant) • Size of recursive sub-problems is (n/2,j) and (n/2,m-j-1), hence T(n,m) = cnm + T(n/2,j) + T(n/2,m-j-1) Lemma: T(n,m) 2cnm Proof (by induction): T(n,m) cnm + 2c(n/2)j + 2c(n/2)(m-j-1) 2cnm. Thus, time complexity is linear in size of the problem At worst, twice the cost of the regular solution.
A variant of the NW algorithm: • Maybe it is OK to have an unlimited # of gaps in the beginning and end: ----------CTATCACCTGACCTCCAGGCCGATGCCCCTTCCGGC GCGAGTTCATCTATCAC--GACCGC--GGTCG-------------- • Then, we don’t want to penalize gaps in the ends
The Overlap Detection variant Changes: • Initialization For all i, j, V(i, 0) = 0 V(0, j) = 0 • Termination maxi V(i, N) VOPT = max maxj V(M, j) x1 ……………………………… xM y1 ……………………………… yN
Overlap Alignment Example s =PAWHEAE t =HEAGAWGHEE • Scoring system: • Match: +4 • Mismatch: -1 • Indel: -5
Overlap Alignment • Initialization:V[i,0]=0,V[0,j]=0 • Recurrence: as in global alignment • Score: maximum value at the bottom line and rightmost line in the matrix
Overlap Alignment Example s =PAWHEAE t =HEAGAWGHEE • Scoring system: • Match: +4 • Mismatch: -1 • Indel: -5
Overlap Alignment Example s =PAWHEAE t =HEAGAWGHEE • Scoring system: • Match: +4 • Mismatch: -1 • Indel: -5
Overlap Alignment Example The best overlap is: PAWHEAE------ ---HEAGAWGHEE Pay attention! A different scoring system could yield a different result, such as: ---PAW-HEAE HEAGAWGHEE-
The local alignment problem Given two strings x = x1……xM, y = y1……yN Find substrings x’, y’ whose similarity (optimal global alignment value) is maximum e.g. x = aaaacccccgggg y = cccgggaaccaacc
Why local alignment • Genes are shuffled between genomes • Portions of proteins (domains) are often conserved
Cross-species genome similarity • 98% of genes are conserved between any two mammals • >70% average similarity in protein sequence hum_a : GTTGACAATAGAGGGTCTGGCAGAGGCTC--------------------- @ 57331/400001 mus_a : GCTGACAATAGAGGGGCTGGCAGAGGCTC--------------------- @ 78560/400001 rat_a : GCTGACAATAGAGGGGCTGGCAGAGACTC--------------------- @ 112658/369938 fug_a : TTTGTTGATGGGGAGCGTGCATTAATTTCAGGCTATTGTTAACAGGCTCG @ 36008/68174 hum_a : CTGGCCGCGGTGCGGAGCGTCTGGAGCGGAGCACGCGCTGTCAGCTGGTG @ 57381/400001 mus_a : CTGGCCCCGGTGCGGAGCGTCTGGAGCGGAGCACGCGCTGTCAGCTGGTG @ 78610/400001 rat_a : CTGGCCCCGGTGCGGAGCGTCTGGAGCGGAGCACGCGCTGTCAGCTGGTG @ 112708/369938 fug_a : TGGGCCGAGGTGTTGGATGGCCTGAGTGAAGCACGCGCTGTCAGCTGGCG @ 36058/68174 hum_a : AGCGCACTCTCCTTTCAGGCAGCTCCCCGGGGAGCTGTGCGGCCACATTT @ 57431/400001 mus_a : AGCGCACTCG-CTTTCAGGCCGCTCCCCGGGGAGCTGAGCGGCCACATTT @ 78659/400001 rat_a : AGCGCACTCG-CTTTCAGGCCGCTCCCCGGGGAGCTGCGCGGCCACATTT @ 112757/369938 fug_a : AGCGCTCGCG------------------------AGTCCCTGCCGTGTCC @ 36084/68174 hum_a : AACACCATCATCACCCCTCCCCGGCCTCCTCAACCTCGGCCTCCTCCTCG @ 57481/400001 mus_a : AACACCGTCGTCA-CCCTCCCCGGCCTCCTCAACCTCGGCCTCCTCCTCG @ 78708/400001 rat_a : AACACCGTCGTCA-CCCTCCCCGGCCTCCTCAACCTCGGCCTCCTCCTCG @ 112806/369938 fug_a : CCGAGGACCCTGA------------------------------------- @ 36097/68174 “atoh” enhancer in human, mouse, rat, fugu fish
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
The Smith-Waterman algorithm Idea: Ignore badly aligning regions Modifications to Needleman-Wunsch: Initialization: V(0, j) = V(i, 0) = 0 0 Iteration: V(i, j) = max V(i – 1, j) + d V(i, j – 1) + d V(i – 1, j – 1) + σ(xi, yj)
The Smith-Waterman algorithm Termination: • If we want the best local alignment… VOPT = maxi,j V(i, j) • If we want all local alignments scoring > t ?? For all i, j find V(i, j) > t, and trace back Complicated by overlapping local alignments