2
Copyright (c) 2007 David Ellinghaus <d.ellinghaus@ikmb.uni-kiel.de>
3
Copyright (c) 2007 Center for Bioinformatics, University of Hamburg
5
Permission to use, copy, modify, and distribute this software for any
6
purpose with or without fee is hereby granted, provided that the above
7
copyright notice and this permission notice appear in all copies.
9
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
int integermax, integermin, i , /* index i */
23
end_k = ulen - vlen, /* diagonal of endpoint (ulen, vlen) */
24
lbound = 0, /* diagonal lower bound */
25
ubound = 0, /* diagonal upper bound */
28
tmprow; /* temporary row index */
30
Myfrontvalue tmpfront;
31
Arbitrarydistances arbitdistances;
32
int d = 0, /* distance */
33
d_pre = 0, /* distance previous */
35
Xdropscore bigt_tmp; /* best score T' seen already */
36
GtArrayXdropscore big_t; /* array T[d] of best score T for each d */
37
bool alwaysMININFINITYINT = true;
38
int allowedMININFINITYINTgenerations = 0,
39
currentMININFINITYINTgeneration = 0;
41
gt_calculatedistancesfromscores(arbitscores, &arbitdistances);
42
gt_calculateallowedMININFINITYINTgenerations(
43
&allowedMININFINITYINTgenerations,
46
dback = SETDBACK(xdropbelowscore);
48
GT_INITARRAY (&big_t, Xdropscore);
49
integermax = MAX (ulen, vlen);
50
integermin = -integermax;
53
for (i = 0; i < MIN(ulen,vlen); i++)
55
COMPARESYMBOLSSEP(i,i);
58
/* alignment already finished */
59
if (i >= ulen || i >= vlen )
65
tmpfront.dptabrow = i;
66
tmpfront.dptabdirection = (GtUchar) 0; /* no predecessor */
68
STOREINARRAYFRONTS (fronts, 0, Myfrontvalue, tmpfront);
69
xdropbest->score = bigt_tmp = S (i + i, 0);
70
xdropbest->ivalue = xdropbest->jvalue = (unsigned int) i;
72
GT_STOREINARRAY (&big_t, Xdropscore, 10, bigt_tmp);
75
while (lbound <= ubound)
80
/* calculate fronts */
81
for (k = lbound - 1; k <= ubound + 1; k++)
85
/* case 1 : DELETION-EDGE */
87
(d - arbitdistances.del >= 0) &&
88
(( -(d - arbitdistances.del) <= k - 1) &&
89
(k - 1 <= d - arbitdistances.del)))
92
fronts->spaceMyfrontvalue[ACCESSTOFRONT(d - arbitdistances.del,
94
tmpfront.dptabdirection = MYDELETIONBIT;
96
/* case 2: REPLACEMENT-EDGE */
97
if ((lbound <= k) && (k <= ubound) && (d - arbitdistances.mis >= 0) &&
98
(( -(d - arbitdistances.mis) <= k) && (k <= d - arbitdistances.mis)))
100
/* test, if case 1 has happened. */
101
if (tmpfront.dptabdirection & MYDELETIONBIT)
104
fronts->spaceMyfrontvalue[ACCESSTOFRONT(d - arbitdistances.mis,
109
tmpfront.dptabdirection = MYREPLACEMENTBIT;
115
fronts->spaceMyfrontvalue[ACCESSTOFRONT(d - arbitdistances.mis, k)]
117
tmpfront.dptabdirection = MYREPLACEMENTBIT;
121
/* case 3: INSERTION-EDGE */
122
if ((k < ubound) && (d - arbitdistances.ins >= 0) &&
123
(( -(d - arbitdistances.ins) <= k + 1) &&
124
(k + 1 <= d - arbitdistances.ins)))
126
if ((tmpfront.dptabdirection & MYDELETIONBIT)
127
|| (tmpfront.dptabdirection & MYREPLACEMENTBIT))
130
fronts->spaceMyfrontvalue[ACCESSTOFRONT (d - arbitdistances.ins,
135
tmpfront.dptabdirection = MYINSERTIONBIT;
141
fronts->spaceMyfrontvalue[ACCESSTOFRONT (d - arbitdistances.ins,
143
tmpfront.dptabdirection = MYINSERTIONBIT;
149
/* if i = MINUSINFINITYINY or MINUSINFINITYINY + 1 */
152
if (tmpfront.dptabdirection == (GtUchar) 0)
154
alwaysMININFINITYINT = false;
156
tmpfront.dptabrow = MINUSINFINITYINT;
158
/* alignment score smaller than T - X */
159
else if ( d_pre > 0 &&
160
big_t.spaceXdropscore != NULL &&
161
(S (i + j, d) < big_t.spaceXdropscore[d_pre] - xdropbelowscore)
164
tmpfront.dptabrow = MINUSINFINITYINT;
166
else if (( k <= -d || k >= d ) || /* not correct boundaries for
167
ACCESTOFRONT(d-1,k) */
168
((fronts->spaceMyfrontvalue[ACCESSTOFRONT(d-1, k)].dptabrow < i)
169
&& (i <= MIN(ulen,vlen + k))))
171
while (i < ulen && j < vlen)
173
COMPARESYMBOLSSEP(i,j);
178
alwaysMININFINITYINT = false;
179
tmpfront.dptabrow = i;
181
/* MAX(bigt_tmp, S(i+j,d)); */
182
if (S (i + j, d) > bigt_tmp)
184
xdropbest->score = bigt_tmp = S (i + j, d);
185
xdropbest->ivalue = (unsigned int) i;
186
xdropbest->jvalue = (unsigned int) j;
192
alwaysMININFINITYINT = false;
194
fronts->spaceMyfrontvalue[ACCESSTOFRONT(d - 1, k)].dptabrow;
197
STOREINARRAYFRONTS (fronts, ACCESSTOFRONT (d, k), Myfrontvalue,
200
/* delete value for test for */
201
/* INSERTIONBIT/REPLACEMENTBIT/DELETIONBIT above
202
tmpfront.dptabdirection = (GtUchar) 0; */
206
/* if all front values are MINUSINFINITYINT,
207
aligment prematurely finished if allowedMININFINITYINTgenerations
209
(full front has already ended at d - currentMININFINITYINTgeneration). */
210
if (alwaysMININFINITYINT)
212
currentMININFINITYINTgeneration++;
213
if (currentMININFINITYINTgeneration > allowedMININFINITYINTgenerations)
215
d = d - currentMININFINITYINTgeneration;
221
currentMININFINITYINTgeneration = 0;
222
alwaysMININFINITYINT = true;
224
GT_STOREINARRAY (&big_t, Xdropscore, 10, bigt_tmp);
226
/* fill out of bounds values of MINUSINFINITYINT
227
needed for gt_showmatrix function */
228
for (k = -d; k < lbound - 1; k++)
230
tmpfront.dptabrow = MINUSINFINITYINT;
231
STOREINARRAYFRONTS (fronts, ACCESSTOFRONT (d, k), Myfrontvalue,
234
for (k = ubound + 2; k <= d; k++)
236
tmpfront.dptabrow = MINUSINFINITYINT;
237
STOREINARRAYFRONTS (fronts, ACCESSTOFRONT (d, k), Myfrontvalue,
241
/* alignment finished */
242
if ((-d <= end_k && end_k <= d) &&
243
fronts->spaceMyfrontvalue[ACCESSTOFRONT (d, end_k)].dptabrow == ulen)
248
/* pruning lower bound
249
lbound may decrease by one or increase/stays the same */
250
for (k = lbound - 1; k <= ubound + 1; k++)
252
if (fronts->spaceMyfrontvalue[ACCESSTOFRONT (d, k)].dptabrow >
260
/* pruning upper bound
261
ubound may increase by one or decrease/stays the same */
262
for (k = ubound + 1; k >= lbound - 1; k--)
264
if (fronts->spaceMyfrontvalue[ACCESSTOFRONT (d, k)].dptabrow >
272
/* handling boundaries lower bound */
274
for (k = 0; k >= lbound; k--)
276
if (fronts->spaceMyfrontvalue[ACCESSTOFRONT (d, k)].dptabrow == vlen + k)
278
/* debugging 12.11.06, vorher:
279
lboundtmp = k + 2; bei Zhang so */
285
/* handling boundaries upper bound */
287
for (k = 0; k <= ubound; k++)
289
if (fronts->spaceMyfrontvalue[ACCESSTOFRONT (d, k)].dptabrow == ulen)
291
/* debugging 12.11.06, vorher:
292
uboundtmp = k - 2; bei Zhang so */
298
lbound = MAX (lbound, lboundtmp);
299
ubound = MIN (ubound, uboundtmp);
302
GT_FREEARRAY (&big_t, Xdropscore);