1 | /*** |
---|
2 | Needleman-Wunch recursions |
---|
3 | |
---|
4 | Notation: i,j are prefix lengths so are in |
---|
5 | ranges i = [0,|A|] and j = [0,|B|]. |
---|
6 | |
---|
7 | Profile positions are in ranges [0,|A|-1] |
---|
8 | and [0,|B|-1] so prefix length i corresponds |
---|
9 | to position (i-1) in the profile, and similarly |
---|
10 | for j. |
---|
11 | |
---|
12 | Terminal gap scoring |
---|
13 | -------------------- |
---|
14 | Terminal gaps are scored as with open [close] |
---|
15 | penalties only at the left [right] terminal, |
---|
16 | as follows: |
---|
17 | |
---|
18 | 0 i |
---|
19 | | | |
---|
20 | A XXXXX... |
---|
21 | B ---XX... |
---|
22 | |
---|
23 | i |A|-1 |
---|
24 | | | |
---|
25 | A ...XXXXX |
---|
26 | B ...XX--- |
---|
27 | |
---|
28 | In these examples, open / close penalty at position |
---|
29 | i is included, but close / open penalty at |A|-1 / |
---|
30 | 0 is not included. |
---|
31 | |
---|
32 | This is implemented by setting the open [close] |
---|
33 | penalty to zero in the first [last] position of |
---|
34 | each profile. |
---|
35 | |
---|
36 | Consider adding a column to a sub-alignment. After the |
---|
37 | column is added, there are i letters from A and j letters |
---|
38 | from B. |
---|
39 | |
---|
40 | The column starts a left-terminal gap if: |
---|
41 | Delete with i=1, j=0 or |
---|
42 | Insert with i=0, j=1. |
---|
43 | |
---|
44 | The column ends a left-terminal gap if: |
---|
45 | Match following Delete with j=1, or |
---|
46 | Match following Insert with i=1. |
---|
47 | |
---|
48 | The column starts a right-terminal gap if: |
---|
49 | Delete following a Match and i=|A|, or |
---|
50 | Insert following a Match and j=|B|. |
---|
51 | |
---|
52 | The column ends a right-terminal gap if: |
---|
53 | Match with i=|A|, j=|B| following Delete or Insert. |
---|
54 | |
---|
55 | RECURSION RELATIONS |
---|
56 | =================== |
---|
57 | |
---|
58 | i-1 |
---|
59 | | |
---|
60 | DD A ..X X |
---|
61 | B ..- - |
---|
62 | |
---|
63 | MD A ..X X |
---|
64 | B ..X - |
---|
65 | |
---|
66 | D(i,j) = max |
---|
67 | D(i-1,j) + e |
---|
68 | M(i-1,j) + goA(i-1) |
---|
69 | Valid for: |
---|
70 | i = [1,|A|-1] |
---|
71 | j = [1,|B|] |
---|
72 | |
---|
73 | I(i,j) By symmetry with D(i,j). |
---|
74 | |
---|
75 | i-2 |
---|
76 | | i-1 |
---|
77 | | | |
---|
78 | MM A ..X X |
---|
79 | B ..X X |
---|
80 | |
---|
81 | DM A ..X X |
---|
82 | B ..- X |
---|
83 | |
---|
84 | IM A ..- X |
---|
85 | B ..X X |
---|
86 | | | |
---|
87 | | j-1 |
---|
88 | j-2 |
---|
89 | |
---|
90 | M(i,j) = L(i-1,j-1) + max |
---|
91 | M(i-1,j-1) |
---|
92 | D(i-1,j-1) + gcA(i-2) |
---|
93 | I(i-1,j-1) + gcB(j-2) |
---|
94 | Valid for: |
---|
95 | i = [2,|A|] |
---|
96 | j = [2,|B|] |
---|
97 | |
---|
98 | Equivalently: |
---|
99 | |
---|
100 | M(i+1,j+1) = L(i,j) + max |
---|
101 | M(i,j) |
---|
102 | D(i,j) + gcA(i-1) |
---|
103 | I(i,j) + gcB(j-1) |
---|
104 | |
---|
105 | Valid for: |
---|
106 | i = [1,|A|-1] |
---|
107 | j = [1,|B|-1] |
---|
108 | |
---|
109 | Boundary conditions |
---|
110 | =================== |
---|
111 | |
---|
112 | A XXXX |
---|
113 | B ---- |
---|
114 | D(0,0) = -infinity |
---|
115 | |
---|
116 | D(i,0) = ie |
---|
117 | i = [1,|A|] |
---|
118 | |
---|
119 | D(0,j) = -infinity |
---|
120 | j = [0,|B|] |
---|
121 | |
---|
122 | I(0,0), I(0,j) and I(i,0) by symmetry with D. |
---|
123 | |
---|
124 | M(0,0) = 0 |
---|
125 | M(i,0) = -infinity, i > 0 |
---|
126 | M(0,j) = -infinity, j > 0 |
---|
127 | |
---|
128 | A X |
---|
129 | B - |
---|
130 | D(1,0) = e |
---|
131 | D(1,j) = -infinity, j = [1,|B|] |
---|
132 | (assuming no I-D allowed). |
---|
133 | |
---|
134 | D(0,1) = -infinity |
---|
135 | D(1,1) = -infinity |
---|
136 | D(i,1) = max. |
---|
137 | ***/ |
---|