Debian Codegraph @

atac-driver/matchExtender/matchExtender-func.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/matchExtender/matchExtender-func.C`/
2 // Copyright (c) 2005 J. Craig Venter Institute
3 // Author: Brian Walenz
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received (LICENSE.txt) a copy of the GNU General Public
16 // License along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include <vector>
24 #include <algorithm>
25
26 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
27 #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/
28 #include "match.H"cxx . . $ `<file>/atac-driver/matchExtender/match.H`/
29
30 using namespace std;
31
32
33 extern uint32cxx . . $ uint32# minEndRunLencxx . . $ minEndRunLen.;
34 extern uint32cxx . . $ uint32# maxMMBlockcxx . . $ maxMMBlock.;
35 extern uint32cxx . . $ uint32# minBlockSepcxx . . $ minBlockSep.;
36 extern double minIdentitycxx . . $ minIdentity.;
37 extern uint32cxx . . $ uint32# maxNbrSepcxx . . $ maxNbrSep.;
38 extern uint32cxx . . $ uint32# maxNbrPathMMcxx . . $ maxNbrPathMM.;
39
40
41 //#define DEBUG_TRACE
42 //#define DEBUG_TRIMTOPERCENT
43 //#define DEBUG_EXTEND
44 //#define DEBUG_EXTEND_CONSUME
45 //#define DEBUG_EXTEND_BACK
46 //#define DEBUG_EXTEND_FORWARD
47
48
49
50 // Return true if c1 and c2 are identities, false otherwise.
51 //
52 bool
53 isIdentitycxx . . $ isIdentity(613193827d93b5e7).(char c1, char c2) {
54 return((letterToBits[(int)c1] != 0xff) &&
55 (letterToBits[(int)c2] != 0xff) &&
56 IUPACidentity[(int)c1][(int)c2]);
57 }
58
59
60
61 // Finds the largest block >= 'pct' (95%) identity.
62 //
63 bool
64 trim_to_pctcxx . . $ trim_to_pct(1c8cd03981c76a54).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# midx, double pct) {
65 #ifdef DEBUG_TRACE
66 fprintf(stderr, "trim_to_pct()\n");
67 #endif
68
69 uint32cxx . . $ uint32# best_start = 0;
70 uint32cxx . . $ uint32# best_len = 0;
71 match_scxx . . $ match_s# *m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).midx];
72
73 FastAAccessorcxx . . $ FastAAccessor# &A = *m->_acc1cxx . . $ match_s#_acc1.;
74 FastAAccessorcxx . . $ FastAAccessor# &B = *m->_acc2cxx . . $ match_s#_acc2.;
75
76 A.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos1cxx . . $ match_s#pos1(db52760e79bf9054).());
77 B.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos2cxx . . $ match_s#pos2(db52760e79bf9054).());
78
79 #ifdef DEBUG_TRIMTOPERCENT
80 //m->dump(stderr, "TrimToPercent", false);
81 #endif
82
83 // For all starting positions:
84 //
85 // We could short-circuit here - once (m->len() - start) becomes
86 // shorter than our best_len, we have no hope in finding a better
87 // one.
88 //
89 for (uint32cxx . . $ uint32# start=0;
90 (start< m->lencxx . . $ match_s#len(db52760e79bf9054).()) && (m->lencxx . . $ match_s#len(db52760e79bf9054).() - start > best_len);
91 ++start) {
92 uint32cxx . . $ uint32# best_run_len = 0;
93 uint32cxx . . $ uint32# sum = 0;
94
95 A.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos1cxx . . $ match_s#pos1(db52760e79bf9054).() + start);
96 B.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos2cxx . . $ match_s#pos2(db52760e79bf9054).() + start);
97
98 // And all ending positions:
99 //
100 // Compute the number of identities we've seen, and remember the
101 // length of the highest identity.
102 //
103 for (uint32cxx . . $ uint32# len = 1; start + len <= m->lencxx . . $ match_s#len(db52760e79bf9054).(); ++len) {
104 char c1 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A;
105 char c2 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).B;
106
107 // We just extend the last result by one, rather than recompute
108 // the whole value for our new range (start, len).
109 //
110 if (isIdentitycxx . . $ isIdentity(613193827d93b5e7).(c1, c2))
111 sum++;
112
113 // If the sum is more than 'pct' identities, we are by
114 // construction the longest run at this starting point, so
115 // remember it.
116 //
117 if (sum >= pct * len)
118 best_run_len = len;
119
120 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A;
121 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).B;
122 }
123
124 // Special case: if the whole string is okay, don't check any
125 // subranges
126 //
127 if ((start == 0) && (best_run_len == m->lencxx . . $ match_s#len(db52760e79bf9054).()))
128 return(false);
129
130 // If we've just found a longer subrange, remember it.
131 //
132 if (best_run_len > best_len) {
133 best_start = start;
134 best_len = best_run_len;
135 }
136 }
137
138 if (best_len < m->lencxx . . $ match_s#len(db52760e79bf9054).()) {
139 #ifdef DEBUG_TRIMTOPERCENT
140 fprintf(stderr, "============================================================\n");
141 fprintf(stderr, "Trimming to substring with start="uint32FMT" and len="uint32FMT" for percent identity\n",
142 best_start, best_len);
143 m->dump(stderr, "BEFORE", true);
144 #endif
145
146 m->extendLeftcxx . . $ match_s#extendLeft(d4f767463ce0a6b3).(-(int32cxx . . $ int32#)best_start);
147 m->extendRightcxx . . $ match_s#extendRight(d4f767463ce0a6b3).(-(int32cxx . . $ int32#)(m->lencxx . . $ match_s#len(db52760e79bf9054).() - best_len));
148
149 #ifdef DEBUG_TRIMTOPERCENT
150 m->dump(stderr, "AFTER", true);
151 fprintf(stderr, "============================================================\n");
152 #endif
153
154 return(true);
155 }
156
157 return(false);
158 }
159
160
161 void
162 extend_match_backwardcxx . . $ extend_match_backward(d93cdad5b6b3ddbf).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches,
163 uint32cxx . . $ uint32# midx,
164 uint32cxx . . $ uint32# min_start_pos) {
165 #ifdef DEBUG_TRACE
166 fprintf(stderr, "extend_match_backward()-- min_start_pos="uint32FMT"\n", min_start_pos);
167 #endif
168
169 // Assumes when traveling backwards that we will never run into
170 // another match (otherwise, that match would have been forward
171 // extended previously).
172
173 uint32cxx . . $ uint32# num_recent_mismatches = 0;
174 match_scxx . . $ match_s# *m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).midx];
175 uint32cxx . . $ uint32# good_run_len = (int) m->lencxx . . $ match_s#len(db52760e79bf9054).();
176 uint32cxx . . $ uint32# num_pending = 0;
177
178 FastAAccessorcxx . . $ FastAAccessor# &A = *m->_acc1cxx . . $ match_s#_acc1.;
179 FastAAccessorcxx . . $ FastAAccessor# &B = *m->_acc2cxx . . $ match_s#_acc2.;
180
181 A.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->_acc1cxx . . $ match_s#_acc1.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).());
182 B.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->_acc2cxx . . $ match_s#_acc2.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).());
183
184 // Decrement, instead of subtract one from the position above, to
185 // avoid any issues with overflow (e.g., 0 - 1).
186 //
187 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A;
188 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).B;
189
190 while ((A.getPositioncxx . . $ FastAAccessor#getPosition(db52760e79bf9054).() > min_start_pos) && A.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && B.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).()) {
191 char c1 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A;
192 char c2 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).B;
193
194 if (isIdentitycxx . . $ isIdentity(613193827d93b5e7).(c1, c2)) {
195 good_run_len++;
196
197 // If we've gone long enough, erase our mismatch record
198 //
199 if (good_run_len == minBlockSepcxx . . $ minBlockSep.) // 20 by default
200 num_recent_mismatches = 0;
201
202 // If we're in the middle of a long good run, add the character
203 // to the match (END_RUN_LEN=10)
204 //
205 // Otherwise, if we just made the minimum extension length, add
206 // all of the pending characters.
207 //
208 // Otherwise, this character is pending. However, still do
209 // output if we're run out of sequence.
210 //
211 if (good_run_len > minEndRunLencxx . . $ minEndRunLen.) {
212 m->extendLeftcxx . . $ match_s#extendLeft(d4f767463ce0a6b3).(1);
213 } else if (good_run_len == minEndRunLencxx . . $ minEndRunLen.) {
214 m->extendLeftcxx . . $ match_s#extendLeft(d4f767463ce0a6b3).(num_pending + 1);
215 num_pending = 0;
216 } else {
217 num_pending++;
218 }
219 } else {
220 good_run_len = 0;
221 num_pending++;
222 num_recent_mismatches++;
223 if (num_recent_mismatches > maxMMBlockcxx . . $ maxMMBlock.) // 3 by default
224 break;
225 }
226
227 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A;
228 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).B;
229 }
230
231 // If we hit the end of the sequence, and are good, do extension
232 //
233 // if ((A.getPosition() == min_start_pos) || (B.getPosition() == 0))
234 //
235 if (!A.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() || !B.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() || (A.getPositioncxx . . $ FastAAccessor#getPosition(db52760e79bf9054).() <= min_start_pos))
236 m->extendLeftcxx . . $ match_s#extendLeft(d4f767463ce0a6b3).(num_pending);
237
238
239 #ifdef DEBUG_EXTEND_BACK
240 fprintf(stderr, "extend_back()-- M u %s . %s %d %d 1 %s %d %d 1\n",
241 m->_matchId,
242 m->_id1, m->_acc1->getRangeBegin(), m->_acc1->getRangeLength(),
243 m->_id2, m->_acc2->getRangeBegin(), m->_acc2->getRangeLength());
244 #endif
245 }
246
247
248 bool
249 can_reach_nearby_matchcxx . . $ can_reach_nearby_match(4128224f31867dc7).(match_scxx . . $ match_s# *src, match_scxx . . $ match_s# *dest) {
250 #ifdef DEBUG_TRACE
251 fprintf(stderr, "can_reach_nearby_match()\n");
252 #endif
253
254 if (dest->pos1cxx . . $ match_s#pos1(db52760e79bf9054).() - (src->pos1cxx . . $ match_s#pos1(db52760e79bf9054).() + src->lencxx . . $ match_s#len(db52760e79bf9054).()) > (uint32cxx . . $ uint32#) maxNbrSepcxx . . $ maxNbrSep.) // 100
255 return false;
256
257 #if 0
258 src->dump(stderr, "src:");
259 dest->dump(stderr, "dst:");
260 #endif
261
262 FastAAccessorcxx . . $ FastAAccessor# &A = *src->_acc1cxx . . $ match_s#_acc1.;
263 FastAAccessorcxx . . $ FastAAccessor# &B = *src->_acc2cxx . . $ match_s#_acc2.;
264
265 A.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(A.getRangeEndcxx . . $ FastAAccessor#getRangeEnd(db52760e79bf9054).() - 1);
266 B.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(B.getRangeEndcxx . . $ FastAAccessor#getRangeEnd(db52760e79bf9054).() - 1);
267
268 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A;
269 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).B;
270
271 uint32cxx . . $ uint32# num_mismatch = 0;
272
273 while ((num_mismatch <= maxNbrPathMMcxx . . $ maxNbrPathMM.) && // 5
274 (A.getPositioncxx . . $ FastAAccessor#getPosition(db52760e79bf9054).() < dest->pos1cxx . . $ match_s#pos1(db52760e79bf9054).()) &&
275 (A.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).()) &&
276 (B.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).())) {
277 if (!isIdentitycxx . . $ isIdentity(613193827d93b5e7).(*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A, *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).B))
278 num_mismatch++;
279
280 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A;
281 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).B;
282 }
283
284 #if 0
285 fprintf(stderr, "num_mismatch=%d pos: %d %d valid: A:%d B:%d\n",
286 num_mismatch, A.getPosition(), dest->pos1(), A.isValid(), B.isValid());
287 #endif
288
289 return(num_mismatch <= maxNbrPathMMcxx . . $ maxNbrPathMM.); // 5
290 }
291
292
293
294 // Stops and returns true if we hit the next match
295 //
296 bool
297 extend_match_forwardcxx . . $ extend_match_forward(ef06361883eeef5d).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# midx, match_scxx . . $ match_s# *target) {
298 #ifdef DEBUG_TRACE
299 fprintf(stderr, "extend_match_forward()\n");
300 #endif
301
302 match_scxx . . $ match_s# *m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).midx];
303 uint32cxx . . $ uint32# num_recent_mismatches = 0;
304 uint32cxx . . $ uint32# num_pending = 0;
305
306 uint32cxx . . $ uint32# good_run_len = (int) m->lencxx . . $ match_s#len(db52760e79bf9054).();
307
308 FastAAccessorcxx . . $ FastAAccessor# &A = *m->_acc1cxx . . $ match_s#_acc1.;
309 FastAAccessorcxx . . $ FastAAccessor# &B = *m->_acc2cxx . . $ match_s#_acc2.;
310
311 #ifdef DEBUG_EXTEND_FORWARD
312 fprintf(stderr, "extend_match_forward()-- A:%4d-%4d B:%4d-%4d\n",
313 A.getRangeBegin(), A.getRangeLength(),
314 B.getRangeBegin(), B.getRangeLength());
315 #endif
316
317 // Set our position to the last valid base in the range, then move
318 // to the next one.
319 //
320 A.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(A.getRangeEndcxx . . $ FastAAccessor#getRangeEnd(db52760e79bf9054).() - 1);
321 B.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(B.getRangeEndcxx . . $ FastAAccessor#getRangeEnd(db52760e79bf9054).() - 1);
322
323 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A;
324 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).B;
325
326 while (A.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() && B.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).()) {
327 char c1 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A;
328 char c2 = *cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).B;
329
330 if (isIdentitycxx . . $ isIdentity(613193827d93b5e7).(c1, c2)) {
331 good_run_len++;
332
333 //fprintf(stderr, "extend-forward %c %c\n", c1, c2);
334
335 // Pass Go and collect $200
336 //
337 if (good_run_len == minBlockSepcxx . . $ minBlockSep.)
338 num_recent_mismatches = 0;
339
340 // If not enough good characters yet, increase the length
341 // pending. We used to check for the hitting the end of the
342 // sequence here.
343 //
344 // Otherwise, if we have just made the minumum good run length,
345 // do the extension.
346 //
347 // Otherwise, if we're above the minimum good length, extend by
348 // another character.
349 //
350 if (good_run_len < minEndRunLencxx . . $ minEndRunLen.) {
351 num_pending++;
352 } else if (good_run_len == minEndRunLencxx . . $ minEndRunLen.) {
353 m->extendRightcxx . . $ match_s#extendRight(d4f767463ce0a6b3).(num_pending + 1);
354 num_pending = 0;
355 } else if (good_run_len > minEndRunLencxx . . $ minEndRunLen.) {
356 m->extendRightcxx . . $ match_s#extendRight(d4f767463ce0a6b3).(1);
357 }
358
359 // If we've run into (and possibly over) another seed match,
360 // return so the main loop can consume and restart.
361 //
362 if (m->canMergeWithcxx . . $ match_s#canMergeWith(5f4dd92e41231ccc).(target))
363 return(true);
364 } else {
365 good_run_len = 0;
366 num_pending++;
367 num_recent_mismatches++;
368
369 if (num_recent_mismatches > maxMMBlockcxx . . $ maxMMBlock.)
370 return(false);
371 }
372
373 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A;
374 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).B;
375 }
376
377 // If we've got a short good run but have hit the end of
378 // a sequence, do extension.
379 //
380 if ((!A.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() || !B.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).()) && (good_run_len < minEndRunLencxx . . $ minEndRunLen.))
381 m->extendRightcxx . . $ match_s#extendRight(d4f767463ce0a6b3).(num_pending);
382
383 #ifdef DEBUG_EXTEND_FORWARD
384 fprintf(stderr, "extend_match_forward(finish)-- A:%4d-%4d B:%4d-%4d\n",
385 A.getRangeBegin(), A.getRangeLength(),
386 B.getRangeBegin(), B.getRangeLength());
387 #endif
388
389 return(false);
390 }
391
392
393
394
395
396
397
398 uint32cxx . . $ uint32#
399 extend_matches_on_diagonalcxx . . $ extend_matches_on_diagonal(d7a89b59e50aea78).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# diag_start) {
400 #ifdef DEBUG_TRACE
401 fprintf(stderr, "extend_matches_on_diagonal()\n");
402 #endif
403
404 uint32cxx . . $ uint32# diag_id = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).diag_start]->_diagonalcxx . . $ match_s#_diagonal.;
405 uint32cxx . . $ uint32# idx;
406 uint32cxx . . $ uint32# prev_end = 0;
407 match_scxx . . $ match_s# *m;
408 match_scxx . . $ match_s# *next_m = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
409
410 // Back extend each match as far as possible (but never over the
411 // preceding match
412 //
413 for (idx = diag_start;
414 (idx < matches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) && (matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).idx]->_diagonalcxx . . $ match_s#_diagonal. == diag_id);
415 ++idx) {
416
417 m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).idx];
418
419 #ifdef DEBUG_EXTEND_BACK
420 m->dump(stderr, "Before back extension:", true);
421 #endif
422
423 extend_match_backwardcxx . . $ extend_match_backward(d93cdad5b6b3ddbf).(matches, idx, prev_end);
424
425 #ifdef DEBUG_EXTEND_BACK
426 m->dump(stderr, "After back extension:", true);
427 #endif
428
429 #ifdef DEBUG_EXTEND
430 fprintf(stderr, "1M u %s . %s %d %d 1 %s %d %d 1\n",
431 matches[idx]->_matchId,
432 matches[idx]->_id1, matches[idx]->_acc1->getRangeBegin(), matches[idx]->_acc1->getRangeLength(),
433 matches[idx]->_id2, matches[idx]->_acc2->getRangeBegin(), matches[idx]->_acc2->getRangeLength());
434 #endif
435
436 prev_end = m->pos1cxx . . $ match_s#pos1(db52760e79bf9054).() + m->lencxx . . $ match_s#len(db52760e79bf9054).();
437
438 if ((m->pos1cxx . . $ match_s#pos1(db52760e79bf9054).() > m->seq1cxx . . $ match_s#seq1(3b3b07432ed6dd5c).()->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).()) || (m->pos2cxx . . $ match_s#pos2(db52760e79bf9054).() > m->seq2cxx . . $ match_s#seq2(3b3b07432ed6dd5c).()->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).()))
439 m->dumpcxx . . $ match_s#dump(29bc4bd13aa9ae2e).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "NEGATIVE after back extend!\n", true), abortcxx . . $ abort(15d318a79ddce9e0).();
440 }
441
442
443 // Now forward extend each match
444
445
446 idx = diag_start;
447 while ((idx < matches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) &&
448 (matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).idx]->_diagonalcxx . . $ match_s#_diagonal. == diag_id)) {
449
450 if (matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).idx]->isDeletedcxx . . $ match_s#isDeleted(c9857a73d68e59ba).()) {
451 idx++;
452 continue;
453 }
454
455 #ifdef DEBUG_EXTEND
456 fprintf(stderr, "2M u %s . %s %d %d 1 %s %d %d 1\n",
457 matches[idx]->_matchId,
458 matches[idx]->_id1, matches[idx]->_acc1->getRangeBegin(), matches[idx]->_acc1->getRangeLength(),
459 matches[idx]->_id2, matches[idx]->_acc2->getRangeBegin(), matches[idx]->_acc2->getRangeLength());
460 #endif
461
462 m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).idx];
463 next_m = 0L;
464
465 for (uint32cxx . . $ uint32# next_idx=idx+1; ((next_idx < matches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) &&
466 (matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).next_idx]->_diagonalcxx . . $ match_s#_diagonal. == diag_id) &&
467 (next_m == 0L)); next_idx++)
468 if (matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).next_idx]->isDeletedcxx . . $ match_s#isDeleted(c9857a73d68e59ba).() == false)
469 next_m = matches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).next_idx];
470
471 // First, try to reach the next match with the simple "maximum of
472 // k mismatches" rule. If we made it, consume the next match and
473 // start the loop again with the same match (now extended)
474 //
475 if (next_m && can_reach_nearby_matchcxx . . $ can_reach_nearby_match(4128224f31867dc7).(m, next_m)) {
476 #ifdef DEBUG_EXTEND_CONSUME
477 m->dump(stderr, "I can_reach_nearby_match and extend this", true);
478 next_m->dump(stderr, "with this", true);
479 #endif
480 m->consumecxx . . $ match_s#consume(d2902acdbd6bbc02).(next_m);
481 next_m->setDeletedcxx . . $ match_s#setDeleted(49f6e7a06ebc5aa8).();
482 #ifdef DEBUG_EXTEND_CONSUME
483 m->dump(stderr, "Extended through next match via neighbor search:", true);
484 #endif
485 continue;
486 }
487
488 // Otherwise, try to make it to the next match with the
489 // character-at- a-time extension rules. If we make it, restart
490 // the loop with the same match (now extended). Otherwise, trim
491 // the extended match as necessary and move on to the next
492 // match.
493 //
494 if (extend_match_forwardcxx . . $ extend_match_forward(ef06361883eeef5d).(matches, idx, next_m)) {
495 #ifdef DEBUG_EXTEND_CONSUME
496 m->dump(stderr, "I extend_match_forward and extend this", true);
497 next_m->dump(stderr, "with this", true);
498 #endif
499 m->consumecxx . . $ match_s#consume(d2902acdbd6bbc02).(next_m);
500 next_m->setDeletedcxx . . $ match_s#setDeleted(49f6e7a06ebc5aa8).();
501 #ifdef DEBUG_EXTEND_CONSUME
502 m->dump(stderr, "Extended through next match via forward extension:", true);
503 #endif
504 continue;
505 }
506
507 #ifdef DEBUG_EXTEND
508 //m->dump(stderr, "Failed to make next match. Final extended version:", true);
509 #endif
510
511 #ifdef DEBUG_EXTEND
512 fprintf(stderr, "3M u %s . %s %d %d 1 %s %d %d 1\n",
513 matches[idx]->_matchId,
514 matches[idx]->_id1, matches[idx]->_acc1->getRangeBegin(), matches[idx]->_acc1->getRangeLength(),
515 matches[idx]->_id2, matches[idx]->_acc2->getRangeBegin(), matches[idx]->_acc2->getRangeLength());
516 #endif
517
518 // Didn't make it, so trim and move on
519 //
520 if (trim_to_pctcxx . . $ trim_to_pct(1c8cd03981c76a54).(matches, idx, minIdentitycxx . . $ minIdentity.)) {
521 #ifdef DEBUG_EXTEND_TRIMMING
522 m->dump(stderr, "After trimming:", true);
523 #endif
524 } else {
525 #ifdef DEBUG_EXTEND_TRIMMING
526 fprintf(stderr, "No trimming done.\n");
527 #endif
528 }
529
530 #ifdef DEBUG_EXTEND
531 fprintf(stderr, "4M u %s . %s %d %d 1 %s %d %d 1\n",
532 matches[idx]->_matchId,
533 matches[idx]->_id1, matches[idx]->_acc1->getRangeBegin(), matches[idx]->_acc1->getRangeLength(),
534 matches[idx]->_id2, matches[idx]->_acc2->getRangeBegin(), matches[idx]->_acc2->getRangeLength());
535 #endif
536
537 #ifdef DEBUG_EXTEND
538 if ((m->pos1() > m->seq1()->sequenceLength()) || (m->pos2() > m->seq2()->sequenceLength()))
539 m->dump(stderr, "NEGATIVE after forward extend!", true), abort();
540
541 fprintf(stderr, "\n==============\n\n");
542 #endif
543
544 ++idx;
545 }
546
547 return idx;
548 }
549
550
551