20 1 Introduction
each s(i, j), the backward pathway is recorded in the process of calculating
Table 1.1. For example, if s(i, j)=s(i−1,j−1)+s(a
i
,b
j
), then the backward
pathway is (i, j) −→ (i − 1,j− 1). Proceeding from s(n, m)backtotheend
s(0, 0), we find the backward pathway. We may then recover the alignment of
the sequences according to the backward pathway as follows: For the element
s(i, j) on the backward pathway:
1. Record the corresponding pairs of nucleic acids a
i
,b
i
if the backward di-
rection is from a
i
,b
i
to its upper left corner.
2. Insert a virtual symbol in the vertical sequence and record (a
i
, −)ifthe
direction is horizontal.
3. Insert a virtual symbol in the horizontal sequence and record (−,b
i
)ifthe
direction is vertical.
4. Finally, we obtain the optimal alignment of the two sequences.
The reader should note that sometimes the backward pathway may not be
unique since the backward method itself may not be unique. In fact, it is
possible to have several optimal alignments with the same optimal score.
Example 3. Consider the sequences
A = aaattagc ,
B = gtatatact .
We will use the dynamic programming-based algorithm to obtain the align-
ment. If the penalty score is 5 for matching, −3 for not matching, and −7for
inserting a virtual symbol, that is,
s
a
i
,b
j
=
5 , if a
i
= b
j
,
−3 , otherwise ,
and d = 7, then:
1. Build a two-dimensional table and calculate the value of each element.
The values of the elements in the first row are defined by s(i, 0) = −i ×d
and the values of the elements in the first column are defined by s(0,j)=
−j×d. According to the steps to calculate s(i, j), we may obtain the values
of all s(i, j) and record the backward direction. For example, s(1, 1) =
max(0-3, −7 − 7, −7 − 7) = −3 and the backward direction is (1, 1) −→
(0, 0). The results are shown in Table 1.2.
Following from Table 1.2, the value of the last element is 1, so the score
of the optimal alignment of sequences A, B is 1.
2. Traceback: We go backward from s(9, 8). As the value of s(8, 9) = 1 is
obtained from its top left element s(7, 8), s(8, 9) = s(7, 8) + s(c, t)=
4−3 = 1, we first backtrack to the top left element s(7, 8), (8, 9) −→
(7, 8).
This is repeated until the backtracking path reaches s(0, 0).