Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3.6 Space-Saving Strategies 53<br />
score-only pass over the dynamic-programming matrix to locate the first and last<br />
nodes of an optimal local alignment, then delivering a global alignment between<br />
these two nodes by applying Hirschberg’s approach.<br />
Algorithm LINEAR ALIGN(A = a 1 a 2 ...a m , B = b 1 b 2 ...b n , i 1 , j 1 , i 2 , j 2 )<br />
begin<br />
if i 1 + 1 ≤ i 2 or j 1 + 1 ≤ j 2 then<br />
Output the aligned pairs for the maximum-score path from (i 1 , j 1 ) to (i 2 , j 2 )<br />
else<br />
i mid ←⌊(i 1 + i 2 )/2⌋<br />
// Find the maximum scores from (i 1 , j 1 )<br />
S − [ j 1 ] ← 0<br />
for j ← j 1 + 1 to j 2 do S − [ j] ← S − [ j − 1] − β<br />
for i ← i 1 + 1 to i mid do<br />
s ← S − [ j 1 ]<br />
c ← S − [ j 1 ] − β<br />
S − [ j 1 ] ← c<br />
for j ← j 1 + ⎧1 to j 2 do<br />
⎨ S − [ j] − β<br />
c ← max c − β<br />
⎩<br />
s + σ(a i ,b j )<br />
s ← S − [ j]<br />
S − [ j] ← c<br />
// Find the maximum scores to (i 2 , j 2 )<br />
S + [ j 2 ] ← 0<br />
for j ← j 2 − 1 down to j 1 do S + [ j] ← S + [ j + 1] − β<br />
for i ← i 2 − 1 down to i mid do<br />
s ← S + [ j 2 ]<br />
c ← S + [ j 2 ] − β<br />
S + [ j 2 ] ← c<br />
for j ← j 2 −⎧<br />
1 down to j 1 do<br />
⎨ S + [ j] − β<br />
c ← max c − β<br />
⎩<br />
s + σ(a i+1 ,b j+1 )<br />
s ← S + [ j]<br />
S + [ j] ← c<br />
// Find where maximum-score path crosses row i mid<br />
j mid ← value j ∈ [ j 1 , j 2 ] that maximizes S − [ j]+S + [ j]<br />
LINEAR ALIGN(A,B, i 1 , j 1 , i mid , j mid )<br />
LINEAR ALIGN(A,B, i mid , j mid , i 2 , j 2 )<br />
end<br />
Fig. 3.18 Computation of an optimal global alignment in linear space.