Sequence Alignment COMPSCI 260 Spring 2016 Why do we - - PowerPoint PPT Presentation

sequence alignment
SMART_READER_LITE
LIVE PREVIEW

Sequence Alignment COMPSCI 260 Spring 2016 Why do we - - PowerPoint PPT Presentation

Sequence Alignment COMPSCI 260 Spring 2016 Why do we want to compare DNA or protein sequences? Find genes similar to known genes IdenGfy


slide-1
SLIDE 1

Sequence ¡Alignment ¡

¡

COMPSCI ¡260 ¡– ¡Spring ¡2016 ¡

slide-2
SLIDE 2

Why ¡do ¡we ¡want ¡to ¡compare ¡DNA ¡or ¡protein ¡sequences? ¡

  • Find ¡genes ¡similar ¡to ¡known ¡genes ¡
  • IdenGfy ¡important ¡(funcGonal) ¡sequences ¡by ¡finding ¡conserved ¡regions ¡
  • As ¡a ¡step ¡in ¡genome ¡assembly, ¡and ¡other ¡sequence ¡analysis ¡tasks ¡ ¡
  • Understand ¡evoluGonary ¡relaGonships ¡and ¡distances ¡(human ¡is ¡closer ¡to ¡

chicken ¡than ¡to ¡zebrafish) ¡

Partial CTCF protein

  • Homologous ¡sequences ¡can ¡be ¡divided ¡into ¡two ¡groups ¡

¡– ¡orthologous ¡sequences: ¡sequences ¡that ¡differ ¡because ¡they ¡are ¡found ¡in ¡ different ¡species ¡ ¡– ¡paralogous ¡sequences: ¡sequences ¡that ¡differ ¡because ¡of ¡a ¡gene ¡ duplicaGon ¡event ¡

slide-3
SLIDE 3

Homology ¡example: ¡evoluGon ¡of ¡globins ¡

  • Human ¡α-­‑globin ¡and ¡human ¡β-­‑

globin ¡are ¡paralogs ¡or ¡orthologs? ¡ ¡

  • Paralogs ¡
  • Human ¡α-­‑globin ¡and ¡mouse ¡α-­‑

globin ¡are ¡homologs ¡or ¡orthologs? ¡

  • Both ¡
slide-4
SLIDE 4

Homology ¡example: ¡sequence ¡comparison ¡can ¡reveal ¡structure ¡

(a) 1dtk (b) 1dtk

5pti

1dtk XAKYCKLPLRIGPCKRKIPSFYYKWKAKQCLPFDYSGCGGNANRFKTIEECRRTCVG- 5pti RPDFCLEPPYTGPCKARIIRYFYNAKAGLCQTFVYGGCRAKRNNFKSAEDCMRTCGGA 1dtk 5pti

slide-5
SLIDE 5

What ¡is ¡the ¡alignment ¡problem? ¡

  • Input: ¡Two ¡protein ¡or ¡DNA ¡sequences ¡ ¡

¡where ¡the ¡xi ¡and ¡yi ¡are ¡chosen ¡from ¡a ¡finite ¡alphabet. ¡ ¡ For ¡DNA ¡sequences ¡the ¡alphabet ¡is ¡{ ¡A,C,G,T}. ¡ ¡ For ¡protein ¡sequences ¡the ¡alphabet ¡is ¡{A, ¡C, ¡D, ¡E, ¡F, ¡G, ¡H, ¡I, ¡K, ¡ L, ¡M, ¡N, ¡P, ¡Q, ¡R, ¡S, ¡T, ¡V, ¡W, ¡Y}. ¡ CTATGCAT-CA GT--GCACCCA X = x1x2…xm Y = y1y2…yn X = CTATGCATCA Y = GTGCACCCA xi yj xi

  • yj
  • r ¡
  • r ¡
  • Output: ¡the ¡opGmal ¡alignment ¡of ¡the ¡two ¡sequences, ¡in ¡the ¡

form ¡of ¡a ¡list ¡of ¡“columns” ¡of ¡the ¡types ¡ ¡

slide-6
SLIDE 6

Sequence ¡variaGons ¡

  • Sequences ¡may ¡have ¡diverged ¡from ¡a ¡common ¡ancestor ¡through ¡

various ¡types ¡of ¡mutaGons: ¡ ¡ – SubsGtuGon ¡(single ¡nucleoGde) ¡ ¡ – DeleGon ¡(single ¡nucleoGde) ¡ ¡ – InserGon ¡(single ¡nucleoGde) ¡ ¡ – Inversion ¡ – TransposiGon ¡(a ¡piece ¡is ¡removed ¡and ¡then ¡inserted ¡somewhere ¡ else) ¡ – DuplicaGon ¡(a ¡piece ¡is ¡put ¡in ¡twice, ¡or ¡perhaps ¡a ¡foreign ¡body ¡might ¡ be ¡inserGng ¡its ¡geneGc ¡material ¡into ¡various ¡places...) ¡

  • What ¡happens ¡if ¡a ¡single ¡nucleoGde ¡dele4on ¡or ¡inser4on ¡occurs ¡in ¡the ¡

coding ¡porGon ¡of ¡the ¡genome? ¡

xi yj xi

  • yj

DeleGon ¡ (in ¡Y ¡rel. ¡to ¡X) ¡ Match/ mismatch ¡ InserGon ¡ (in ¡Y ¡rel. ¡to ¡X) ¡

  • What ¡happens ¡if ¡a ¡single ¡nucleoGde ¡subs4tu4on ¡occurs ¡in ¡the ¡coding ¡

porGon ¡of ¡the ¡genome? ¡ ¡

slide-7
SLIDE 7

What ¡is ¡the ¡alignment ¡problem? ¡

  • Input: ¡Two ¡protein ¡or ¡DNA ¡sequences ¡ ¡

¡where ¡the ¡xi ¡and ¡yi ¡are ¡chosen ¡from ¡a ¡finite ¡alphabet. ¡ ¡ For ¡DNA ¡sequences ¡the ¡alphabet ¡is ¡{ ¡A,C,G,T}. ¡ ¡ For ¡protein ¡sequences ¡the ¡alphabet ¡is ¡{A, ¡C, ¡D, ¡E, ¡F, ¡G, ¡H, ¡I, ¡K, ¡ L, ¡M, ¡N, ¡P, ¡Q, ¡R, ¡S, ¡T, ¡V, ¡W, ¡Y}. ¡ X = x1x2…xm Y = y1y2…yn xi yj xi

  • yj
  • r ¡
  • r ¡
  • Output: ¡the ¡op4mal ¡alignment ¡of ¡the ¡two ¡sequences, ¡in ¡the ¡

form ¡of ¡a ¡list ¡of ¡“columns” ¡of ¡the ¡types ¡ ¡ We ¡need ¡a ¡way ¡to ¡score ¡any ¡given ¡alignment ¡of ¡X ¡and ¡Y

slide-8
SLIDE 8

What ¡is ¡the ¡alignment ¡problem? ¡

  • Input: ¡Two ¡protein ¡or ¡DNA ¡sequences ¡ ¡

¡where ¡the ¡xi ¡and ¡yi ¡are ¡chosen ¡from ¡a ¡finite ¡alphabet. ¡ ¡ For ¡DNA ¡sequences ¡the ¡alphabet ¡is ¡{ ¡A,C,G,T}. ¡ ¡ For ¡protein ¡sequences ¡the ¡alphabet ¡is ¡{A, ¡C, ¡D, ¡E, ¡F, ¡G, ¡H, ¡I, ¡K, ¡ L, ¡M, ¡N, ¡P, ¡Q, ¡R, ¡S, ¡T, ¡V, ¡W, ¡Y}. ¡ ¡And ¡a ¡funcGon ¡Score that ¡assigns ¡a ¡score ¡to ¡any ¡column ¡of ¡the ¡ types ¡ X = x1x2…xm Y = y1y2…yn xi yj xi

  • yj
  • r ¡
  • r ¡
  • Output: ¡the ¡highest ¡scoring ¡alignment ¡of ¡the ¡two ¡sequences, ¡

where ¡an ¡alignment ¡is ¡defined ¡as ¡a ¡list ¡of ¡columns ¡of ¡the ¡ types ¡defined ¡above, ¡and ¡Score(alignment) ¡= ¡Σcol Score(col). ¡

slide-9
SLIDE 9

Alignment ¡scoring ¡scheme ¡ ¡

  • Alignment ¡scoring ¡schemes ¡reflect ¡

biological ¡or ¡staGsGcal ¡observaGons ¡ about ¡the ¡known ¡sequences, ¡and ¡are ¡ frequently ¡represented ¡by ¡scoring ¡ matrices ¡ AAAC A-GC Score(A,A) + g + Score(A,G) + Score(C,C) = -­‑1 ¡

  • Score(xi,yj) = ¡ ¡+1 ¡ ¡ ¡ ¡if ¡xi and ¡yj is ¡a ¡match ¡-­‑> ¡reward ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡−1 ¡ ¡ ¡if ¡xi and ¡yj is ¡a ¡mismatch ¡-­‑> ¡penalty ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡−2 ¡ ¡ ¡if ¡either ¡xi or ¡yj is ¡a ¡gap ¡-­‑> ¡penalty ¡

  • In ¡general, ¡the ¡gap ¡penalty ¡is ¡denoted ¡as ¡g ¡(or ¡−g) ¡

? ¡ AAAC AGC- Score(A,A) + Score(A,G) + Score(A,C) + g = -­‑3 ¡

slide-10
SLIDE 10

Brute-­‑force ¡search ¡for ¡the ¡opGmal ¡alignment ¡

  • Given ¡the ¡two ¡sequences ¡X = x1x2…xm and ¡Y = y1y2…yn ¡we ¡want ¡to ¡

find ¡the ¡alignment ¡that ¡produces ¡the ¡best ¡score ¡according ¡to ¡the ¡ given ¡scoring ¡scheme. ¡

  • Brute-­‑force ¡solu4on: ¡enumerate ¡all ¡the ¡possible ¡alignments, ¡score ¡

each ¡alignment, ¡and ¡select ¡the ¡alignment ¡with ¡the ¡maximal ¡score. ¡

  • What ¡is ¡the ¡total ¡number ¡of ¡possible ¡global ¡alignments ¡between ¡X ¡and ¡Y ? ¡

AAAC---

  • ---AGC

AAAC--

  • --AGC

AAA-C-

  • --AGC

AAA--C

  • --AGC

… ¡

  • Idea: ¡append ¡n gaps ¡to ¡the ¡sequence ¡X ¡ ¡to ¡obtain ¡X’ = x1x2…xm−…− ¡ ¡

Then ¡we ¡can ¡pick ¡n ¡elements ¡from ¡X’ ¡to ¡align ¡with ¡the ¡characters ¡in ¡Y ¡. ¡ … ¡exponenGal ¡Gme ¡ ¡

slide-11
SLIDE 11

Brute-­‑force ¡search ¡for ¡the ¡opGmal ¡alignment ¡

  • Brute ¡force: ¡generate ¡& ¡score ¡all ¡possible ¡alignments ¡
  • Time ¡complexity: ¡

¡

n ¡ Brute ¡force ¡ Today’s ¡lecture ¡ 10 ¡ 184,756 ¡ 100 ¡ 20 ¡ 1.40E+11 ¡ 400 ¡ 100 ¡ 9.00E+58 ¡ 10,000 ¡

slide-12
SLIDE 12

OpGmal ¡substructure ¡property? ¡

  • The score is additive: for a given split (i, j), the best alignment

can be computed as… Best alignment of S1[1..i] and S2[1..j] + Best alignment of S1[ i+1..n] and S2[ j+1..m]

  • Compute best alignment recursively
slide-13
SLIDE 13

Divide ¡and ¡conquer? ¡

IdenGcal ¡sub-­‑problems! ¡ We ¡should ¡reuse ¡our ¡work! ¡

slide-14
SLIDE 14

SoluGon ¡#1 ¡– ¡MemoizaGon ¡ ¡

  • Create ¡a ¡big ¡dicGonary ¡(or ¡table), ¡indexed ¡by ¡aligned ¡

sequences ¡

– When ¡we ¡encounter ¡a ¡new ¡pair ¡of ¡sequences ¡ – If ¡it ¡is ¡in ¡the ¡dicGonary ¡

  • Look ¡up ¡the ¡soluGon ¡

– If ¡it ¡is ¡not ¡in ¡the ¡dicGonary ¡

  • Compute ¡the ¡soluGon ¡
  • Insert ¡the ¡soluGon ¡in ¡the ¡dicGonary ¡
  • Ensures ¡that ¡there ¡is ¡no ¡duplicated ¡work ¡

– Only ¡need ¡to ¡compute ¡each ¡sub-­‑alignment ¡once ¡

slide-15
SLIDE 15

SoluGon ¡#2 ¡– ¡Dynamic ¡programming ¡

  • Strategy: ¡

– reduce ¡problem ¡of ¡best ¡alignment ¡of ¡two ¡sequences ¡to ¡best ¡ alignment ¡of ¡all ¡prefixes ¡of ¡the ¡sequences ¡ ¡ i-­‑prefix ¡of ¡ ¡X is ¡ ¡ ¡x1x2…xi j-­‑prefix ¡of ¡ ¡Y ¡ ¡ ¡is ¡ ¡ ¡y1y2…yj ¡

  • Create ¡a ¡big ¡table, ¡indexed ¡by ¡(i,j) ¡

– Fill ¡it ¡from ¡the ¡beginning ¡all ¡the ¡way ¡to ¡the ¡end ¡ – The ¡soluGon ¡is ¡the ¡element ¡(n,m) ¡

  • Guaranteed ¡to ¡explore ¡enGre ¡search ¡space ¡
  • Ensures ¡that ¡there ¡is ¡no ¡duplicated ¡work ¡

– Only ¡need ¡to ¡compute ¡each ¡sub-­‑alignment ¡once! ¡

  • Very ¡simply ¡computaGonally! ¡
slide-16
SLIDE 16

Needleman-­‑Wunsch ¡algorithm ¡

  • Consider ¡last ¡step ¡in ¡compuGng ¡the ¡alignment ¡of ¡AAAC ¡with ¡AGC ¡ ¡
  • Three ¡possible ¡opGons; ¡in ¡each ¡we ¡will ¡choose ¡a ¡different ¡pairing ¡

(or ¡column ¡type) ¡for ¡end ¡of ¡alignment, ¡and ¡add ¡this ¡to ¡best ¡ alignment ¡of ¡previous ¡characters ¡ ¡

slide-17
SLIDE 17

Needleman-­‑Wunsch ¡algorithm ¡

  • Given ¡an ¡m-­‑character ¡sequence ¡X, ¡and ¡an ¡n-­‑character ¡sequence ¡Y ¡ ¡
  • Construct ¡an ¡(m+1) ¡× ¡(n+1) matrix ¡F
  • F ( i, j ) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i ] with ¡y[1...j ]
slide-18
SLIDE 18

Needleman-­‑Wunsch ¡algorithm ¡

  • Given ¡an ¡m-­‑character ¡sequence ¡X, ¡and ¡an ¡n-­‑character ¡sequence ¡Y ¡ ¡
  • Construct ¡an ¡(m+1) ¡× ¡(n+1) matrix ¡F
  • F ( i, j ) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i ] with ¡y[1...j ]

i j

X Y

slide-19
SLIDE 19

Needleman-­‑Wunsch ¡algorithm ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡of ¡matrix ¡ ¡
  • Fill ¡in ¡rest ¡of ¡matrix ¡from ¡top ¡to ¡bo|om, ¡le} ¡to ¡right ¡ ¡
  • F(m, n) holds ¡the ¡opGmal ¡alignment ¡score ¡
  • For ¡each ¡F(i, j), ¡save ¡pointers ¡to ¡cells ¡that ¡resulted ¡in ¡best ¡score ¡ ¡
  • Trace ¡pointers ¡back ¡from ¡F(m, n) ¡to ¡F(0, 0) to ¡recover ¡alignment ¡

i j

X Y

slide-20
SLIDE 20

IniGalizing ¡the ¡DP ¡matrix ¡ ¡

slide-21
SLIDE 21

Global ¡alignment ¡example ¡ ¡

slide-22
SLIDE 22

Needleman-­‑Wunsch ¡algorithm ¡

  • Strategy: ¡

– reduce ¡problem ¡of ¡best ¡alignment ¡of ¡two ¡sequences ¡to ¡best ¡ alignment ¡of ¡all ¡prefixes ¡of ¡the ¡sequences ¡ ¡ i-­‑prefix ¡of ¡ ¡X is ¡ ¡ ¡x1x2…xi j-­‑prefix ¡of ¡ ¡Y ¡ ¡ ¡is ¡ ¡ ¡y1y2…yj

  • Matrix: ¡ ¡

F (i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x1x2…xi with ¡ ¡y1y2…yj

slide-23
SLIDE 23

Needleman-­‑Wunsch ¡algorithm ¡

  • Consider ¡last ¡step ¡in ¡compuGng ¡the ¡alignment… ¡
  • F (i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x1x2…xi with ¡ ¡y1y2…yj
  • Update ¡rule: ¡
slide-24
SLIDE 24

Needleman-­‑Wunsch ¡algorithm ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡of ¡matrix ¡ ¡
  • Fill ¡in ¡rest ¡of ¡matrix ¡from ¡top ¡to ¡bo|om, ¡le} ¡to ¡right ¡ ¡
  • F(m, n) holds ¡the ¡opGmal ¡alignment ¡score ¡
  • For ¡each ¡F(i, j), ¡save ¡pointers ¡to ¡cells ¡that ¡resulted ¡in ¡best ¡score ¡ ¡
  • Trace ¡pointers ¡back ¡from ¡F(m, n) ¡to ¡F(0, 0) to ¡recover ¡alignment ¡
slide-25
SLIDE 25

Global ¡alignment ¡example ¡ ¡

slide-26
SLIDE 26

Global ¡alignment ¡example ¡ ¡

slide-27
SLIDE 27

More ¡than ¡one ¡opGmal ¡alignment? ¡

Graph search algorithms available on course website

slide-28
SLIDE 28

Pairwise ¡alignment ¡via ¡dynamic ¡programming ¡

  • Works ¡for ¡either ¡DNA ¡or ¡protein ¡sequences, ¡although ¡the ¡subsGtuGon ¡

matrices ¡are ¡different ¡

  • Finds ¡all ¡opGmal ¡alignments ¡ ¡
  • Time ¡complexity: ¡
  • O(nm) ¡ ¡
  • Space ¡complexity: ¡
  • O(nm) ¡
  • Can ¡we ¡do ¡this ¡faster? ¡
  • Yes, ¡if ¡we ¡use ¡the ¡Four-­‑Russians ¡Speedup ¡ ¡

– Arlazarov, ¡Dinic, ¡Kronrod, ¡Faradzev ¡(1970) ¡ – Block ¡alignment ¡with ¡blocks ¡of ¡size ¡t ¡= ¡log(n) ¡/ ¡4 ¡ – Running ¡Gme ¡goes ¡from ¡quadraGc, ¡O(n2), ¡to ¡subquadraGc: ¡O(n2/logn) ¡ ¡

slide-29
SLIDE 29

Space ¡complexity ¡

  • CompuGng ¡the ¡alignment ¡requires ¡quadraGc ¡space: ¡O(nm) ¡
  • We ¡need ¡to ¡keep ¡all ¡backtracking ¡references ¡in ¡memory ¡to ¡

reconstruct ¡the ¡path ¡(backtracking) ¡ ¡

slide-30
SLIDE 30

Space ¡complexity ¡

  • CompuGng ¡just ¡the ¡score ¡of ¡the ¡best ¡alignment ¡can ¡be ¡done ¡

in ¡linear ¡space ¡

  • We ¡only ¡need ¡the ¡previous ¡column ¡to ¡calculate ¡the ¡current ¡

column, ¡and ¡we ¡can ¡then ¡throw ¡away ¡that ¡previous ¡column ¡

  • nce ¡we ¡are ¡done ¡using ¡it ¡

How ¡do ¡we ¡recover ¡the ¡path? ¡ We ¡cannot. ¡

X Y X = x1x2…xm Y = y1y2…yn

What ¡is ¡the ¡space ¡complexity? ¡ O(m) ¡or ¡O(n) ¡? ¡ Can ¡we ¡compute ¡the ¡best ¡ alignment ¡in ¡linear ¡space? ¡

slide-31
SLIDE 31

OpGmal ¡global ¡alignment ¡in ¡linear ¡space ¡ ¡

  • The ¡opGmal ¡alignment ¡must ¡

cross ¡the ¡middle ¡line ¡ ¡ ¡

(i, m/2)

  • ¡We ¡want ¡to ¡calculate ¡the ¡best ¡

alignment ¡from ¡(0,0) ¡to ¡(n,m) ¡that ¡ passes ¡through ¡(i,m/2) ¡where ¡i ¡= ¡ 0..n ¡and ¡represents ¡the ¡i-­‑th ¡row ¡ ¡

  • ¡Define ¡score(i) ¡as ¡the ¡score ¡of ¡

the ¡opGmal ¡alignment ¡from ¡(0,0) ¡ to ¡(n,m) ¡that ¡passes ¡through ¡cell ¡ (i, ¡m/2) ¡ ¡

  • ¡Define ¡(mid, ¡m/2) ¡as ¡the ¡cell ¡

where ¡the ¡opGmal ¡alignment ¡ crosses ¡the ¡middle ¡column ¡ ¡ score(mid) ¡= ¡score ¡opGmal ¡ alignment ¡= ¡max0≤i ¡≤n ¡score(i) ¡ ¡ ¡ ¡ ¡

slide-32
SLIDE 32

OpGmal ¡global ¡alignment ¡in ¡linear ¡space ¡ ¡

Prefix(i) ¡is ¡the ¡score ¡of ¡the ¡best ¡ alignment ¡from ¡(0,0) ¡to ¡(i,m/2) ¡ ¡ Compute ¡Prefix(i) ¡by ¡DP ¡in ¡ ¡ the ¡le} ¡half ¡of ¡the ¡matrix ¡ ¡ ¡ Suffix(i) ¡is ¡the ¡score ¡of ¡the ¡best ¡ alignment ¡from ¡(i,m/2) ¡to ¡(n,m) ¡= ¡the ¡ score ¡of ¡the ¡best ¡alignment ¡from ¡ (n,m) ¡to ¡(i,m/2) ¡with ¡all ¡arrows ¡ reversed ¡ ¡ Compute ¡Suffix(i) ¡by ¡DP ¡in ¡the ¡right ¡ half ¡of ¡the ¡“reversed” ¡matrix ¡ ¡ score(i) ¡= ¡Prefix(i) ¡+ ¡Suffix(i) ¡

  • The ¡opGmal ¡alignment ¡must ¡

cross ¡the ¡middle ¡line ¡ ¡ ¡

(i, m/2)

slide-33
SLIDE 33

Finding ¡the ¡middle ¡point ¡

slide-34
SLIDE 34

Finding ¡the ¡middle ¡point ¡again ¡

slide-35
SLIDE 35

And ¡again… ¡

slide-36
SLIDE 36

Space ¡is ¡linear. ¡But ¡how ¡about ¡Gme ¡complexity? ¡

On ¡first ¡pass, ¡the ¡ algorithm ¡covers ¡the ¡ enGre ¡area ¡nm ¡ ¡ ¡ CompuGng ¡ ¡ Prefix(i) ¡ CompuGng ¡ Suffix(i) ¡ On ¡second ¡pass, ¡the ¡ algorithm ¡covers ¡only ¡ ¡ half ¡of ¡the ¡area: ¡nm/2 ¡ ¡ ¡

slide-37
SLIDE 37

Space ¡is ¡linear. ¡But ¡how ¡about ¡Gme ¡complexity? ¡

On ¡third ¡pass, ¡only ¡1/4th ¡ ¡ is ¡covered ¡(nm/4) ¡ ¡ ¡ When ¡referring ¡to ¡the ¡ longest ¡common ¡ subsequence: ¡ Hirschberg’s ¡algorithm ¡ ¡ ¡ ¡ Geometric ¡reducGon ¡ ¡ at ¡each ¡iteraGon ¡ nm ¡+ ¡nm/2 ¡+ ¡nm/4 ¡+ ¡… ¡ Running ¡Gme: ¡O(nm) ¡ Space: ¡O(n+m) ¡ ¡ < ¡2nm ¡

slide-38
SLIDE 38

Alignment ¡

  • Global alignment: find best match of both sequences in

their entirety

  • Semi-global alignment: find best match without

penalizing gaps on the ends of the alignment

  • Local alignment: find best subsequence match
slide-39
SLIDE 39

Semi-­‑global ¡alignment ¡

  • We ¡are ¡aligning ¡the ¡following ¡sequences ¡ ¡

CAGCACTTGGATTCTCGG CAGCGTGG

  • One ¡possible ¡alignment ¡ ¡

CAGCACTTGGATTCTCGG CAGC-----G-T----GG ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Score: ¡8(1)+0(-­‑1)+10(-­‑2) ¡= ¡-­‑12 ¡ ¡

  • We ¡might ¡prefer ¡the ¡alignment ¡ ¡

CAGCA-CTTGGATTCTCGG

  • --CAGCGTGG-------- ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Score: ¡6(1)+1(-­‑1)+12(-­‑2) ¡= ¡-­‑19 ¡ ¡

  • We ¡need ¡a ¡new ¡scoring ¡scheme ¡

¡IntuiGvely, ¡we ¡do ¡not ¡penalize ¡“missing” ¡ends ¡of ¡the ¡sequence ¡ ¡ ¡We ¡would ¡like ¡to ¡model ¡this ¡intuiGon ¡ ¡

slide-40
SLIDE 40

Semi-­‑global ¡alignment ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡according ¡

to ¡gap ¡penalty ¡

  • Fill ¡in ¡the ¡matrix ¡
  • Report ¡F(m,n) ¡as ¡the ¡opGmal ¡score ¡

Global ¡alignment ¡ Semi-­‑global ¡alignment ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡with ¡0 ¡
  • Fill ¡in ¡the ¡matrix, ¡as ¡above ¡
  • Report ¡max ¡over ¡last ¡row ¡and ¡last ¡column ¡as ¡the ¡opGmal ¡score ¡
slide-41
SLIDE 41

Semi-­‑global ¡alignment ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡according ¡

to ¡gap ¡penalty ¡

  • Fill ¡in ¡the ¡matrix ¡
  • Report ¡F(m,n) ¡as ¡the ¡opGmal ¡score ¡

Global ¡alignment ¡ Semi-­‑global ¡alignment ¡

  • IniGalize ¡first ¡row ¡and ¡column ¡with ¡0 ¡
  • Fill ¡in ¡the ¡matrix, ¡as ¡above ¡
  • Report ¡max ¡over ¡last ¡row ¡and ¡last ¡column ¡as ¡the ¡opGmal ¡score ¡
slide-42
SLIDE 42

Semi-­‑global ¡alignment ¡

  • One ¡possible ¡alignment ¡ ¡ ¡

CAGCACTTGGATTCTCGG CAGC-----G-T----GG ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Score: ¡8(1)+0(-­‑1)+10(-­‑2) ¡= ¡-­‑12 ¡ ¡

  • We ¡might ¡prefer ¡the ¡alignment ¡ ¡

CAGCA-CTTGGATTCTCGG

  • --CAGCGTGG-------- ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Score: ¡6(1)+1(-­‑1)+12(-­‑2) ¡= ¡-­‑19 ¡ ¡

  • With ¡the ¡new ¡scoring ¡scheme ¡(semi-­‑global ¡alignment) ¡

CAGCA-CTTGGATTCTCGG


  • --CAGCGTGG-------- ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Score: ¡6(1)+1(-­‑1)+1(-­‑2)+11(-­‑0) ¡= ¡3 ¡ ¡ ¡

slide-43
SLIDE 43

Semi-­‑global ¡alignments ¡

  • ApplicaGons: ¡ ¡

¡– ¡Finding ¡a ¡gene ¡in ¡a ¡genome ¡ – ¡Aligning ¡a ¡read ¡onto ¡an ¡assembly ¡ – ¡Finding ¡the ¡best ¡alignment ¡of ¡a ¡PCR ¡primer ¡ ¡ ¡

  • These ¡situaGons ¡have ¡in ¡common ¡ ¡

¡– ¡One ¡sequence ¡is ¡much ¡shorter ¡than ¡the ¡other ¡ ¡ ¡– ¡Alignment ¡should ¡span ¡the ¡enGre ¡length ¡of ¡the ¡smaller ¡sequence ¡ ¡ ¡– ¡No ¡need ¡to ¡align ¡the ¡enGre ¡length ¡of ¡the ¡longer ¡sequence ¡ ¡

query target

  • Local ¡sequence ¡alignment: ¡best ¡alignment ¡between ¡subsequences ¡
  • f ¡X ¡and ¡Y ¡
slide-44
SLIDE 44

Local ¡alignment ¡problem: ¡definiGon ¡

  • Input: ¡Two ¡protein ¡or ¡DNA ¡sequences ¡ ¡

¡where ¡the ¡xi ¡and ¡yi ¡are ¡chosen ¡from ¡a ¡finite ¡alphabet. ¡ ¡ For ¡DNA ¡sequences ¡the ¡alphabet ¡is ¡{ ¡A,C,G,T}. ¡ ¡ For ¡protein ¡sequences ¡the ¡alphabet ¡is ¡{A, ¡C, ¡D, ¡E, ¡F, ¡G, ¡H, ¡I, ¡K, ¡ L, ¡M, ¡N, ¡P, ¡Q, ¡R, ¡S, ¡T, ¡V, ¡W, ¡Y}. ¡ ¡And ¡a ¡funcGon ¡Score that ¡assigns ¡a ¡score ¡to ¡any ¡column ¡of ¡the ¡ types ¡ X = x1x2…xm Y = y1y2…yn xi yj xi

  • yj
  • r ¡
  • r ¡
  • Output: ¡the ¡highest ¡scoring ¡alignment ¡between

subsequences of X and Y, ¡where ¡an ¡alignment ¡is ¡defined ¡as ¡ a ¡list ¡of ¡columns ¡of ¡the ¡types ¡defined ¡above, ¡and ¡ Score(alignment) ¡= ¡Σcol Score(col). ¡

slide-45
SLIDE 45

Local ¡alignment ¡

  • Example: ¡aligning ¡two ¡protein ¡sequences ¡that ¡have ¡a ¡common ¡

domain ¡but ¡are ¡otherwise ¡different ¡

  • Compared ¡to ¡global ¡alignment, ¡the ¡local ¡alignment ¡problem ¡

appears ¡to ¡be ¡significantly ¡more ¡complex ¡

  • Naïve ¡approach: ¡ ¡

– given ¡that ¡we ¡know ¡how ¡to ¡compute ¡the ¡global ¡alignment ¡between ¡two ¡ sequences ¡in ¡O(mn) ¡Gme ¡ – we ¡can ¡take ¡all ¡possible ¡combinaGons ¡of ¡substrings ¡of ¡X ¡and ¡substrings ¡

  • f ¡Y, ¡and ¡run ¡Needleman-­‑Wunsch ¡ ¡
  • Running ¡Gme? ¡
  • O(m3n3) ¡
  • We ¡can ¡improve ¡this ¡significantly ¡by ¡using ¡a ¡DP ¡approach ¡
  • Local ¡alignment ¡is ¡much ¡more ¡

common ¡than ¡global ¡alignment ¡

Smith-Waterman algorithm - Smith, T.F. & Waterman, M.S. (1981) Identification

  • f common molecular subsequences.
  • J. Mol. Biol. 147:195-197.
slide-46
SLIDE 46

Global ¡vs. ¡local ¡alignment ¡

Global ¡alignment ¡ X Y

F (i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡ ¡ ¡ ¡ ¡ ¡ ¡of ¡ ¡x[1...i ] with ¡y[1...j ]

Local ¡alignment ¡

If ¡the ¡best ¡alignment ¡ ¡up ¡to ¡some ¡ point ¡has ¡a ¡negaGve ¡score, ¡it ¡is ¡be|er ¡ to ¡start ¡a ¡new ¡alignment ¡(score ¡0) ¡

slide-47
SLIDE 47

If ¡the ¡best ¡alignment ¡ ¡up ¡to ¡some ¡ point ¡has ¡a ¡negaGve ¡score, ¡it ¡is ¡be|er ¡ to ¡start ¡a ¡new ¡alignment ¡(score ¡0) ¡

Global ¡vs. ¡local ¡alignment ¡

Global ¡alignment ¡ X Y

F(i, j) = ¡score ¡of ¡the ¡best ¡ alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ]

Local ¡alignment ¡

F (i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡ ¡ ¡ ¡ ¡ ¡ ¡of ¡ ¡x[1...i ] with ¡y[1...j ]

slide-48
SLIDE 48
  • Previously ¡(global ¡alignment) ¡we ¡

iniGalized ¡with ¡gap ¡penalGes ¡

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡ alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ]

  • Update ¡rule: ¡
  • Now ¡(local ¡alignment) ¡we ¡iniGalize ¡

the ¡first ¡row ¡and ¡column ¡with ¡0 ¡

  • Ini4aliza4on? ¡
slide-49
SLIDE 49

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡ alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ]

  • Update ¡rule: ¡
  • Global: ¡F(m,n) ¡
  • Semi-­‑global: ¡maximum ¡over ¡last ¡

row ¡F(m,j) ¡and ¡column ¡F(i,n) ¡

  • Local: ¡??? ¡
  • Op4mal ¡alignment ¡score? ¡
slide-50
SLIDE 50

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡ alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ]

  • Update ¡rule: ¡
  • Global: ¡F(m,n) ¡
  • Semi-­‑global: ¡maximum ¡over ¡last ¡

row ¡F(m,j) ¡and ¡column ¡F(i,n) ¡

  • Local: ¡maximum ¡F(i,j) ¡over ¡all

i=1..m and ¡j=1..n ¡

  • Op4mal ¡alignment ¡score? ¡
slide-51
SLIDE 51

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡ alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ]

  • Update ¡rule: ¡
  • Ini4aliza4on: ¡we ¡iniGalize ¡the ¡first ¡

row ¡and ¡column ¡with ¡0 ¡

  • Op4mal ¡alignment ¡score: ¡maximum ¡

F(i,j) ¡over ¡all i=1..m and ¡j=1..n

  • Traceback: ¡
  • Start ¡from ¡the ¡cell ¡containing ¡the ¡
  • pGmal ¡score ¡
  • Stop ¡when ¡we ¡reach ¡the ¡value ¡0 ¡
slide-52
SLIDE 52

Local ¡alignment ¡example ¡ ¡

slide-53
SLIDE 53

Local ¡alignment ¡example ¡ ¡

slide-54
SLIDE 54

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

  • Time ¡complexity: ¡
  • O(mn) ¡
  • Space ¡complexity: ¡
  • O(mn), ¡can ¡be ¡brought ¡to ¡O(m+n) ¡ ¡
  • Is ¡the ¡soluGon ¡opGmal? ¡Have ¡we ¡searched ¡the ¡enGre ¡space ¡of ¡

alignments ¡between ¡substrings ¡of ¡X ¡and ¡Y ? ¡

  • Yes. ¡Because ¡a ¡substring ¡of ¡a ¡string ¡is ¡the ¡suffix ¡of ¡a ¡prefix. ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ] SoluGon: ¡maximum ¡F(i,j) ¡over ¡all i=1..m and ¡j=1..n

  • MulGple ¡opGmal ¡alignments ¡
slide-55
SLIDE 55

Local ¡alignment ¡– ¡Smith-­‑Waterman ¡algorithm ¡

  • Time ¡complexity: ¡
  • O(mn) ¡
  • Space ¡complexity: ¡
  • O(mn), ¡can ¡be ¡brought ¡to ¡O(m+n) ¡ ¡
  • Is ¡the ¡soluGon ¡opGmal? ¡Have ¡we ¡searched ¡the ¡enGre ¡space ¡of ¡

alignments ¡between ¡substrings ¡of ¡X ¡and ¡Y ? ¡

  • Yes. ¡Because ¡a ¡substring ¡of ¡a ¡string ¡is ¡the ¡suffix ¡of ¡a ¡prefix. ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡a ¡suffix ¡of ¡x[1...i ] with ¡a ¡suffix ¡of ¡y[1...j ] SoluGon: ¡maximum ¡F(i,j) ¡over ¡all i=1..m and ¡j=1..n

  • MulGple ¡opGmal ¡alignments ¡
slide-56
SLIDE 56

Global ¡and ¡local ¡alignment ¡

Global ¡alignment ¡ Local ¡alignment ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡ ¡ ¡ ¡ ¡ ¡ ¡of ¡ ¡x[1...i ] with ¡y[1...j ] Match/mismatch ¡score ¡ Gap ¡penalty ¡

slide-57
SLIDE 57

Scoring ¡matches/mismatches ¡-­‑ ¡revisited ¡

  • Alignment ¡scoring ¡schemes ¡reflect ¡

biological ¡or ¡staGsGcal ¡observaGons ¡about ¡ the ¡known ¡sequences, ¡and ¡are ¡frequently ¡ ¡ represented ¡by ¡scoring ¡matrices ¡

Purines

Guanine (G) Adenine (A)

Pyrimidines

Cytosine (C) Thymine (T)

slide-58
SLIDE 58

Scoring ¡matches/mismatches ¡-­‑ ¡revisited ¡

  • DNA ¡mutaGons ¡

– Transi4ons: ¡ ¡subsGtuGons ¡that ¡occur ¡between ¡the ¡two-­‑ring ¡ purines ¡(A ¡→ ¡G ¡and ¡G ¡→ ¡A) ¡or ¡between ¡the ¡one-­‑ring ¡ ¡ pyrimidines ¡(C ¡→ ¡T ¡and ¡T ¡→ ¡C). ¡ ¡ Because ¡these ¡subsGtuGons ¡do ¡not ¡ ¡ require ¡a ¡change ¡in ¡the ¡number ¡of ¡ ¡ rings, ¡they ¡occur ¡more ¡frequently ¡ ¡ than ¡the ¡other ¡subsGtuGons. ¡ – Transversions: ¡ ¡slower-­‑rate ¡ ¡ subsGtuGons ¡that ¡change ¡ ¡ a ¡purine ¡to ¡a ¡pyrimidine ¡ ¡

  • r ¡vice ¡versa ¡(A ¡↔ ¡C, ¡ ¡

A ¡↔ ¡T, ¡G ¡↔ ¡C, ¡and ¡G ¡↔ ¡T). ¡

Purines

Guanine (G) Adenine (A)

Pyrimidines

Cytosine (C) Thymine (T)

slide-59
SLIDE 59

Scoring ¡matches/mismatches ¡-­‑ ¡revisited ¡

  • For ¡protein ¡sequence ¡alignment, ¡some ¡amino ¡acids ¡have ¡

similar ¡structures ¡and ¡can ¡be ¡more ¡easily ¡subsGtuted ¡in ¡ nature ¡

Tryptophan (W) Aspartic acid (D) Glutamic acid (D)

slide-60
SLIDE 60

Chemical ¡structures ¡of ¡the ¡20 ¡common ¡amino ¡acids ¡ ¡

slide-61
SLIDE 61

Protein ¡subsGtuGon ¡matrices ¡

  • A ¡biologist ¡with ¡good ¡intuiGon ¡could ¡come ¡up ¡with ¡

a ¡decent ¡scoring ¡scheme ¡(invent ¡210 ¡scores) ¡

  • But ¡we ¡would ¡like ¡to ¡have ¡some ¡theory ¡

behind ¡these ¡scores, ¡that ¡reflects ¡the ¡ similarity ¡between ¡the ¡residues ¡

  • SubsGtuGon ¡scores ¡can ¡be ¡

derived ¡from ¡probabilisGc ¡ models ¡of ¡evoluGon ¡

Durbin et al. – Biological Sequence Analysis

slide-62
SLIDE 62

SubsGtuGon ¡matrices ¡for ¡protein ¡sequences ¡

  • Two ¡popular ¡sets ¡of ¡matrices ¡for ¡protein ¡sequences ¡

– ¡PAM ¡matrices ¡[Dayhoff ¡et ¡al., ¡1978] ¡ – ¡BLOSUM ¡matrices ¡[Henikoff ¡& ¡Henikoff, ¡1992] ¡ ¡

  • Both ¡try ¡to ¡capture ¡the ¡relaGve ¡subsGtutability ¡of ¡amino ¡acid ¡

pairs ¡in ¡the ¡context ¡of ¡evoluGon ¡ ¡

Point ¡Accepted ¡MutaGon ¡

  • 1 ¡PAM ¡unit ¡= ¡PAM1 ¡= ¡one ¡mutaGon ¡per ¡100 ¡amino ¡acids ¡
  • A}er ¡100 ¡PAMs ¡of ¡evoluGon, ¡not ¡every ¡residue ¡will ¡have ¡

changed ¡ ¡ – some ¡residues ¡may ¡have ¡mutated ¡several ¡Gmes ¡ ¡ – some ¡residues ¡may ¡have ¡returned ¡to ¡their ¡original ¡state ¡ ¡ – some ¡residues ¡may ¡not ¡have ¡changed ¡at ¡all ¡ ¡

slide-63
SLIDE 63

SubsGtuGon ¡matrices ¡for ¡protein ¡sequences ¡

  • PAM250 ¡is ¡a ¡widely ¡used ¡matrix: ¡
slide-64
SLIDE 64

SubsGtuGon ¡matrices ¡for ¡protein ¡sequences ¡

BLOSUM ¡

  • Blocks ¡SubsGtuGon ¡Matrix ¡ ¡
  • Scores ¡derived ¡from ¡observaEons ¡of ¡the ¡frequencies ¡of ¡

subsGtuGons ¡in ¡blocks ¡of ¡local ¡alignments ¡in ¡related ¡proteins ¡ ¡

  • Accounts ¡for ¡evoluGonarily ¡divergent ¡sequences ¡
  • Matrix ¡name ¡indicates ¡evoluGonary ¡distance ¡ ¡

– BLOSUM62 ¡was ¡created ¡using ¡sequences ¡sharing ¡no ¡more ¡ than ¡62% ¡idenGty ¡ ¡

slide-65
SLIDE 65

SubsGtuGon ¡matrices ¡for ¡protein ¡sequences ¡– ¡BLOSUM50 ¡

Positive for chemically similar amino-acids Common amino- acids have low weights Rare amino-acids have high weights

slide-66
SLIDE 66

Global ¡and ¡local ¡alignment ¡

Global ¡alignment ¡ Local ¡alignment ¡

F(i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡ ¡ ¡ ¡ ¡ ¡ ¡of ¡ ¡x[1...i ] with ¡y[1...j ] Match/mismatch ¡score ¡ Gap ¡penalty ¡

slide-67
SLIDE 67

Gap ¡penalGes ¡ ¡

  • These ¡have ¡the ¡same ¡score ¡
  • But ¡the ¡second ¡one ¡is ¡o}en ¡more ¡plausible ¡
  • A ¡single ¡inserGon ¡of ¡GAAT ¡into ¡the ¡first ¡string ¡could ¡change ¡it ¡into ¡

the ¡second ¡

  • Current ¡scoring ¡scheme ¡assumes ¡the ¡gaps ¡occurred ¡

independently ¡

vs.

slide-68
SLIDE 68

Gap ¡penalGes ¡ ¡

  • Current ¡scoring ¡scheme: ¡the ¡

cost ¡associated ¡with ¡a ¡gap ¡of ¡ length ¡k ¡is ¡g*k ¡

  • This ¡is ¡a ¡linear ¡gap ¡penalty ¡
  • We ¡would ¡like ¡to ¡have ¡a ¡gap ¡penalty ¡funcGon ¡where ¡long ¡gaps ¡

are ¡not ¡penalized ¡that ¡heavily ¡

  • This ¡is ¡an ¡affine ¡gap ¡penalty ¡
  • OpGon: ¡ ¡ ¡
  • penalty ¡for ¡opening ¡a ¡gap: ¡h
  • penalty ¡for ¡extending ¡a ¡gap: ¡g < h ¡
  • The ¡cost ¡associated ¡with ¡a ¡gap ¡of ¡length ¡k: ¡
slide-69
SLIDE 69

Linear ¡vs. ¡affine ¡gap ¡penalty ¡

Linear ¡gap: ¡ Affine ¡gap: ¡ i j

X Y

F(i, j) = ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡ ¡ ¡ ¡x[1...i ] with ¡y[1...j ]

slide-70
SLIDE 70

Linear ¡vs. ¡affine ¡gap ¡penalty ¡

Linear ¡gap: ¡ Affine ¡gap: ¡ i j

X Y

i j

X Y

slide-71
SLIDE 71

Linear ¡vs. ¡affine ¡gap ¡penalty ¡

Linear ¡gap: ¡ Affine ¡gap: ¡ i j

X Y

F(i, j) = max F(i −1, j −1)+ s(xi,yj) F(i −1, j)+ w(1) F(i − 2, j)+ w(2) ... F(i, j −1)+ w(1) F(i, j − 2)+ w(2) ... " # $ $ $ $ % $ $ $ $

slide-72
SLIDE 72

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case? ¡

Affine ¡gap: ¡ i j

X Y

F(i, j) = max F(i −1, j −1)+ s(xi,yj) F(i −1, j)+ w(1) F(i − 2, j)+ w(2) ... F(i, j −1)+ w(1) F(i, j − 2)+ w(2) ... " # $ $ $ $ % $ $ $ $

  • We ¡can ¡use ¡the ¡same ¡approach ¡we ¡used ¡for ¡the ¡linear ¡gap, ¡but… ¡
  • Running ¡Gme ¡increases ¡from ¡O(mn) ¡to ¡O(mn(m+n)) ¡
  • For ¡m=n, ¡the ¡increase ¡is ¡from ¡O(n2) ¡to ¡O(n3) ¡
slide-73
SLIDE 73

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡

  • We ¡can ¡reduce ¡the ¡Gme ¡to ¡O(mn), ¡but ¡we ¡need ¡3 ¡matrices ¡

instead ¡of ¡1 ¡ ¡ M(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to y[j] Ix(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to a gap Iy(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that y[j] is aligned to a gap xi yj xi

  • yj
slide-74
SLIDE 74

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡

Ix(i, j) = max M(i −1, j)+ h + g Ix(i −1, j)+ g Iy(i −1, j)+ h + g " # $ $ % $ $ Iy(i, j) = max M(i, j −1)+ h + g Ix(i, j −1)+ h + g Iy(i, j −1)+ g " # $ $ % $ $ M(i, j) = max M(i −1, j −1)+ s(xi,yj) Ix(i −1, j −1)+ s(xi,yj) Iy(i −1, j −1)+ s(xi,yj) " # $ $ % $ $

xi yj xi

  • yj
slide-75
SLIDE 75

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡-­‑ ¡iniGalizaGon ¡

M(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to y[j] Ix(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to a gap Iy(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that y[j] is aligned to a gap

xi yj xi

  • yj

M(0,j) = ¡ ¡the ¡score ¡of ¡best ¡alignment ¡between ¡0 ¡characters ¡of ¡X ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡j ¡characters ¡of ¡Y ¡that ¡ends ¡in ¡a ¡match ¡ M(0,0) = 0 = ¡-­‑∞ ¡because ¡no ¡such ¡alignment ¡can ¡exist ¡ Ix(i,0) = h + g*i Iy(0,j) = h + g*j = M(i,0) ¡ Ix(0,j) = -­‑∞ Iy(i,0) = -­‑∞

slide-76
SLIDE 76

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡-­‑ ¡traceback ¡

M(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to y[j] Ix(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that x[i] is aligned to a gap Iy(i,j) ¡= ¡score ¡of ¡the ¡best ¡alignment ¡of ¡ ¡x[1...i] with ¡y[1...j] given that y[j] is aligned to a gap

xi yj xi

  • yj
  • Start ¡at ¡largest ¡of ¡ ¡M(m,n), ¡Ix(m,n), ¡Iy(m,n) ¡
  • Stop ¡at ¡any ¡of ¡M(0,0), ¡Ix(0,0), ¡Iy(0,0) ¡
  • Note ¡that ¡pointers ¡may ¡traverse ¡all ¡three ¡matrices ¡ ¡
slide-77
SLIDE 77

3-­‑leveled ¡Manha|an ¡grid ¡

slide-78
SLIDE 78

Global ¡alignment ¡example ¡– ¡affine ¡gap ¡penalty ¡

slide-79
SLIDE 79

Global ¡alignment ¡example ¡– ¡affine ¡gap ¡penalty ¡

slide-80
SLIDE 80

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡ ¡

M(i, j) = max M(i −1, j −1)+ s(xi,yj) Ix(i −1, j −1)+ s(xi,yj) Iy(i −1, j −1)+ s(xi,yj) " # $ $ % $ $

Global ¡alignment ¡

Ix(i, j) = max M(i −1, j)+ h + g Ix(i −1, j)+ g Iy(i −1, j)+ h + g " # $ $ % $ $ Iy(i, j) = max M(i, j −1)+ h + g Ix(i, j −1)+ h + g Iy(i, j −1)+ g " # $ $ % $ $

xi yj xi

  • yj
slide-81
SLIDE 81

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡ ¡

Ix(i, j) = max M(i −1, j)+ h + g Ix(i −1, j)+ g Iy(i −1, j)+ h + g " # $ $ % $ $ Iy(i, j) = max M(i, j −1)+ h + g Ix(i, j −1)+ h + g Iy(i, j −1)+ g " # $ $ % $ $ M(i, j) = max M(i −1, j −1)+ s(xi,yj) Ix(i −1, j −1)+ s(xi,yj) Iy(i −1, j −1)+ s(xi,yj) " # $ $ % $ $

xi yj xi

  • yj

Local ¡alignment ¡

slide-82
SLIDE 82

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡ ¡

Ix(i,0) = h + g*i Iy(0,j) = h + g*j Ix(i,0) = 0 Iy(0,j) = 0 M(i,0) = M(0,j) = ¡-­‑∞ ¡ ¡ M(0,0) = 0 IniGalizaGon ¡ Traceback ¡ Start ¡at ¡largest ¡of: ¡ ¡ ¡ M(m,n), ¡Ix(m,n), ¡Iy(m,n) ¡ Stop ¡at ¡any ¡of: ¡ M(0,0), ¡Ix(0,0), ¡Iy(0,0) ¡ Start ¡at ¡largest ¡M(i,j) ¡ ¡ ¡ Stop ¡at ¡any ¡M(i,j)=0 ¡

Local ¡alignment ¡ Global ¡alignment ¡

M(i,0) = M(0,j) = ¡0 ¡ M(0,0) = 0

slide-83
SLIDE 83

DP ¡for ¡the ¡affine ¡gap ¡penalty ¡case ¡– ¡Complexity ¡

  • Fill ¡in ¡thee ¡m ¡x ¡n ¡matrices ¡-­‑> ¡3mn ¡subproblems ¡
  • Each ¡one ¡takes ¡constant ¡Gme ¡ ¡
  • Total ¡runGme ¡O(mn) ¡
  • Space ¡complexity ¡O(mn) ¡
slide-84
SLIDE 84

Gap ¡penalty ¡funcGons ¡

  • Linear ¡gap ¡penalty: ¡
  • Affine ¡gap ¡penalty: ¡
  • Concave ¡gap ¡penalty ¡funcGon: ¡ ¡

h

Time: ¡O(n2) ¡ Space: ¡O(n2) ¡ Time: ¡O(n2) ¡ Space: ¡O(n2) ¡ Time: ¡O(n3) ¡ Space: ¡O(n2) ¡

slide-85
SLIDE 85

Pairwise ¡sequence ¡alignment ¡

  • What ¡type ¡of ¡alignment ¡should ¡we ¡consider? ¡ ¡

(global, ¡semi-­‑global, ¡local) ¡

  • Can ¡be ¡done ¡in ¡O(nm) ¡Gme ¡using ¡dynamic ¡programming, ¡with ¡

either ¡linear ¡or ¡affine ¡gap ¡penalGes ¡

  • Can ¡be ¡done ¡in ¡O(nm) ¡space, ¡or ¡even ¡O(n+m) ¡space ¡
  • We ¡can ¡find ¡all ¡alignments ¡that ¡have ¡the ¡best ¡score ¡
  • Works ¡for ¡either ¡DNA ¡or ¡protein ¡sequences, ¡with ¡different ¡

subsGtuGon ¡matrices ¡