Debian Codegraph @

prefix_tree.cpp

raw symbols SCIP
1 // PatMaN DNA pattern matcher
2 // (C) 2007 Kay Pruefer, Udo Stenzel
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or (at
7 // your option) any later version. See the LICENSE file for details.
8
9
10 #include "prefix_tree.h"
11
12 #include <cassert>
13 #include <iostream>
14 #include <queue>
15 #include <cstdlib>
16
17 using namespace std ;
18
19 // Why a deque? Because allocation of many small objects of
20 // equal size is faster in it and deallocation of the whole
21 // deque is much faster than deallocation of the small objects,
22 // especially with our extremely simple allocation pattern.
23 // This is probably the most sensible way to plug this memory
24 // leak.
25 prefix_tree::prefix_tree( ) : nodes()
26 {
27 nodes.push_back( node() ) ;
28 }
29
30 #ifndef NDEBUG
31 void prefix_tree::debug( std::ostream& s, const node& n ) const
32 {
33 if( debug_flags & debug_trie )
34 {
35 for( int i = 0 ; i != 5 ; ++i )
36 s << n.label << " -" << "ACGTN"[i] << "> " << n.childs[i]->label << '/' << (int)n.drop[i] << std::endl ;
37 if( n.suffix ) s << n.label << " ==> " << n.suffix->label << '/' << n.drop_suffix << std::endl ;
38
39 for( int i = 0 ; i != 5 ; ++i )
40 if( !n.drop[i] ) debug( s, *n.childs[i] ) ;
41 }
42 }
43 #endif
44
45
46 static mismatch_ptr *junk_yard = 0 ;
47
48 static mismatch_ptr *new_node()
49 {
50 if( junk_yard )
51 {
52 mismatch_ptr *p = junk_yard ;
53 junk_yard = p->next ;
54 return p ;
55 }
56 else
57 {
58 return new mismatch_ptr ;
59 }
60 }
61
62 mismatch_ptr *prefix_tree::seed() const
63 {
64 // add ptr to the root node
65 mismatch_ptr *p = new_node() ;
66 p->ptr = &nodes[0] ;
67 p->mismatch = 0 ;
68 p->gaps = 0 ;
69 p->first = 0 ;
70 p->isgap = 0 ;
71 p->matched = 0 ;
72 p->next = 0 ;
73 return p ;
74 }
75
76 mismatch_ptr *prefix_tree::init( mismatch_ptr *p ) const
77 {
78 if( p ) {
79 mismatch_ptr *q = p ;
80 while( p->next ) p = p->next ;
81 p->next = junk_yard ;
82 junk_yard = q ;
83 }
84 return seed() ;
85 }
86
87 // creates child node # pos if necessary and returns ptr to this child node
88 node* prefix_tree::create_go_node( node* n, int pos ) {
89 if ( n->childs[pos] == 0 ) {
90 node o ;
91 o.depth = n->depth + 1 ;
92 nodes.push_back( o ) ;
93 node *next = &nodes.back() ;
94 n->childs[pos] = next ;
95 #ifndef NDEBUG
96 if( debug_flags & debug_trie )
97 n->childs[pos]->label = n->label + "ACGTN"[pos] ;
98 #endif
99 return next ;
100 } else {
101 return n->childs[pos] ;
102 }
103 }
104
105 void prefix_tree::add_recursion( const string& seq, const string& name, node* ptr, size_t i, char strand )
106 {
107 // is this a leaf?
108 if ( i == seq.size() ) {
109
110 probe_s *probe = new probe_s() ;
111 probe->name = name ;
112 probe->strand = strand ;
113 probe->length = seq.size() ;
114 probe->next = ptr->probes ;
115 ptr->probes = probe ;
116
117 // no leaf -> add
118 } else {
119 switch ( toupper(seq[i]) ) {
120 case 'A':
121 add_recursion( seq, name, create_go_node( ptr, 0 ), ++i, strand ) ;
122 break ;
123 case 'C':
124 add_recursion( seq, name, create_go_node( ptr, 1 ), ++i, strand ) ;
125 break ;
126 case 'G':
127 add_recursion( seq, name, create_go_node( ptr, 2 ), ++i, strand ) ;
128 break ;
129 case 'T':
130 case 'U':
131 add_recursion( seq, name, create_go_node( ptr, 3 ), ++i, strand ) ;
132 break ;
133 case 'N':
134 case 'X':
135 add_recursion( seq, name, create_go_node( ptr, 4 ), ++i, strand ) ;
136 break ;
137 case '-':
138 break ;
139 default:
140 add_recursion( seq, name, create_go_node( ptr, 4 ), ++i, strand ) ;
141 if( debug_flags & debug_notquiet )
142 clog << "Warning: Sequence with name " << name
143 << " has character '" << seq[i]
144 << "' other than ACGTUXN." << endl ;
145 debug_flags &= ~debug_notquiet ;
146 break ;
147 }
148
149 }
150 }
151
152 /***
153 * Adding the sequence taking into account the ambiguity codes.
154 * i.e. Sequence with "N" will be added to A, C, G and T node
155 */
156 void prefix_tree::add_recursion_ambiguity( const string& seq, const string& name, node* ptr, size_t i, char strand )
157 {
158 // is this a leaf?
159 if ( i == seq.size() ) {
160
161 probe_s *probe = new probe_s() ;
162 probe->name = name ;
163 probe->strand = strand ;
164 probe->length = seq.size() ;
165 probe->next = ptr->probes ;
166 ptr->probes = probe ;
167
168 // no leaf -> add
169 } else {
170 switch ( toupper(seq[i]) ) {
171 case 'A':
172 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
173 break ;
174 case 'C':
175 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
176 break ;
177 case 'G':
178 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
179 break ;
180 case 'T':
181 case 'U':
182 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
183 break ;
184 case 'N':
185 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
186 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
187 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
188 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
189 break ;
190 case 'R':
191 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
192 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
193 break ;
194 case 'Y':
195 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
196 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
197 break ;
198 case 'M':
199 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
200 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
201 break ;
202 case 'K':
203 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
204 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
205 break ;
206 case 'S':
207 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
208 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
209 break ;
210 case 'W':
211 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
212 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
213 break ;
214 case 'B':
215 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
216 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
217 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
218 break ;
219 case 'D':
220 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
221 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
222 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
223 break ;
224 case 'H':
225 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
226 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
227 add_recursion_ambiguity( seq, name, create_go_node( ptr, 3 ), i+1, strand ) ;
228 break ;
229 case 'V':
230 add_recursion_ambiguity( seq, name, create_go_node( ptr, 0 ), i+1, strand ) ;
231 add_recursion_ambiguity( seq, name, create_go_node( ptr, 1 ), i+1, strand ) ;
232 add_recursion_ambiguity( seq, name, create_go_node( ptr, 2 ), i+1, strand ) ;
233 break ;
234
235 case '-':
236 break ;
237
238 default:
239 add_recursion_ambiguity( seq, name, create_go_node( ptr, 4 ), i+1, strand ) ;
240 if( debug_flags & debug_notquiet )
241 clog << "Warning: Sequence with name " << name
242 << " has character '" << seq[i]
243 << "' other than ACGTU, BDH, SWKMRY, or XN." << endl ;
244 debug_flags &= ~debug_notquiet ;
245 break ;
246 }
247
248 }
249 }
250
251 /* Ambiguity codes:
252 * R = G or A (puRine)
253 * Y = C or T (pYrimidine)
254 * M = A or C (aMine)
255 * K = G or T (Ketone)
256 * S = G or C (Strong coupling)
257 * W = A or T (Weak coupling)
258 * B = not A (C or G or T)
259 * D = not C (A or G or T)
260 * H = not G (A or C or T)
261 * V = not U (A or C or G)
262 * N = A or C or G or T (Nucleotide)
263 */
264
265 /*
266 * reverse complement of a dna sequence, including correct ambiguity mapping
267 */
268 inline static string reverse_complement( const string& s ) {
269 string ret ;
270 for ( int i = s.size()-1 ; i >= 0 ; i-- ) {
271 switch ( toupper( s[i] ) ) {
272 case 'A':
273 ret += 'T' ; break ;
274 case 'C':
275 ret += 'G' ; break ;
276 case 'G':
277 ret += 'C' ; break ;
278 case 'T':
279 case 'U':
280 ret += 'A' ; break ;
281 case 'R':
282 ret += 'Y' ; break ;
283 case 'Y':
284 ret += 'R' ; break ;
285 case 'M':
286 ret += 'K' ; break ;
287 case 'K':
288 ret += 'M' ; break ;
289 case 'B':
290 ret += 'V' ; break ;
291 case 'V':
292 ret += 'B' ; break ;
293 case 'D':
294 ret += 'H' ; break ;
295 case 'H':
296 ret += 'D' ; break ;
297 case 'S':
298 case 'W':
299 case 'N':
300 case '-':
301 ret += s[i] ;
302 break ;
303 default:
304 clog << "Sequence has invalid character '"
305 << s[i] << "'." << endl ;
306 exit( 1 ) ;
307 }
308 }
309 return ret ;
310 }
311
312 void prefix_tree::add_seq( const string& seq, const string& name, bool ambi_codes )
313 {
314 node *ptr = &nodes[0] ;
315 int i = 0 ;
316 if ( ! ambi_codes ) {
317 add_recursion( seq, name, ptr, i, '+' ) ;
318 if ( only_plus_strand != 1 ) {
319 string rev_seq = reverse_complement( seq ) ;
320 add_recursion( rev_seq, name, ptr, i, '-' ) ;
321 }
322 } else {
323 add_recursion_ambiguity( seq, name, ptr, i, '+' ) ;
324 if ( only_plus_strand != 1 ) {
325 string rev_seq = reverse_complement( seq ) ;
326 add_recursion_ambiguity( rev_seq, name, ptr, i, '-' ) ;
327 }
328 }
329 }
330
331 // Suffix links. These are only needed as an intermediate step. Each
332 // node gets a suffix link, which points to the node that is the longest
333 // existing true suffix. Given a node that already has a suffix, we
334 // find the suffix of child "A" by following the "A" link from our
335 // suffix and adding the 'drop' values for the "suffix" and the "A"
336 // link. We can then fill in the missing children for this node in the
337 // same fashion. To ensure that any node we visit already has a suffix,
338 // we do a breadth-first search.
339 //
340 // The root never has a suffix. To start the fill-in, each missing
341 // child of the root becomes the root itself with a "drop" of one and
342 // the existing ones get the root as suffix with a drop of one.
343 //
344 // Also, after we added the missing children, we no longer need the
345 // suffix link for anything but accessing query sequences that happen to
346 // be substrings of other queries. So we can optimize these.
347
348 void prefix_tree::add_suffix_links()
349 {
350 std::queue< node* > q ;
351 node& root = nodes[0] ;
352 for( int i = 0 ; i != 5 ; ++i )
353 {
354 if( root.childs[i] )
355 {
356 root.childs[i]->suffix = &root ;
357 root.childs[i]->drop_suffix = 1 ;
358 q.push( root.childs[i] ) ;
359 }
360 else
361 {
362 root.childs[i] = &root ;
363 root.drop[i] = 1 ;
364 }
365 }
366
367 while( !q.empty() )
368 {
369 node* n = q.front() ;
370 q.pop() ;
371 for( int i = 0 ; i != 5 ; ++i )
372 {
373 if( n->childs[i] )
374 {
375 n->childs[i]->suffix = n->suffix->childs[i] ;
376 n->childs[i]->drop_suffix = n->drop_suffix + n->suffix->drop[i] ;
377 q.push( n->childs[i] ) ;
378 }
379 else
380 {
381 n->childs[i] = n->suffix->childs[i] ;
382 n->drop[i] = n->drop_suffix + n->suffix->drop[i] ;
383 }
384 }
385 if( !n->suffix->probes )
386 {
387 if( n->suffix->suffix )
388 {
389 n->drop_suffix += n->suffix->drop_suffix ;
390 n->suffix = n->suffix->suffix ;
391 }
392 else
393 {
394 n->suffix = 0 ;
395 }
396 }
397 }
398 }
399
400 inline static void out( int mm, const node* n, int mlen )
401 {
402 for( const probe_s *probe = n->probes ; probe ; probe = probe->next )
403 {
404 ( output ? *output : cout )
405 << genome_name << '\t' << probe->name << '\t'
406 << position_genome - mlen << '\t'
407 << position_genome - 1 << '\t'
408 << probe->strand << '\t' << mm << '\n' ;
409 }
410 }
411
412 // Why does this work? Because when we follow suffix links (to print
413 // matches that are completely inside other matches), we know that we
414 // only drop perfectly matching stuff from the beginning. This allows
415 // us to update "mlen".
416
417 inline static void out_rec( int mm, const node* n, int first, int mlen )
418 {
419 if( n->probes ) out( mm, n, mlen ) ;
420
421 const node* nn = n ;
422 while( nn->suffix && nn->drop_suffix <= first )
423 {
424 first -= nn->drop_suffix ;
425 mlen -= nn->drop_suffix ;
426 nn = nn->suffix ;
427 if( nn->probes ) out( mm, nn, mlen ) ;
428 }
429 }
430
431
432 /* Advancing the mismatch pointers.
433 * - We receive a (singly linked) list of mps. There has to be exactly
434 * one mp that didn't encounter any mismatches in its history (keeping
435 * this one ensures that the algorithm reduces to Aho-Corasick if
436 * mismatches aren't allowed). Too avoid to much special treatment,
437 * this special pointer will always be the first in the list. We
438 * process it first, initalize the result list with it or re-seed the
439 * result list, then go into the loop over the rest of the list. This
440 * implies an if-block in the middle of the loop and it also implies
441 * that some pointers are only initialized in the loop.
442 *
443 * - We will keep multiple pointers into the two involved lists: one to
444 * the end of the result list; this is where we splice in pointers to
445 * be queued for the next round. This list is at all time properly
446 * terminated and disconnected from the stuff we're processing this
447 * round.
448 *
449 * - One to the next node to be processed. This one is easy, it is
450 * advanced once per loop, it's the head of the incoming list and
451 * we're done if it becomes null.
452 *
453 * - One several places ahead of the current one. We prefetch the node
454 * pointed to by this one and its next link. Keeping another yet more
455 * advanced pointer to prefetch mismatch pointers is useless because
456 * of the need to follow the chain of next pointers. This one has to
457 * be valid at all times (see next point), so if it would become null,
458 * we don't advance it.
459 *
460 * - When gapping, we need to splice new mps into the queue being
461 * processed. We do this after the node we prefetched last. That
462 * makes sense, because we already have that mp in cache, so we can
463 * splice without penalty. It works fine, as long as there is such a
464 * pointer, and to ensure that, we first handle gaps (in this
465 * direction) while the current node is still in the queue, then
466 * cache the contents of the current node, handle the node itself,
467 * thereby removing and or splicing it, then handle mismatches and/or
468 * gaps.
469 */
470
471 inline static mismatch_ptr *splice_fresh_after( mismatch_ptr *mp )
472 {
473 if( junk_yard )
474 {
475 mismatch_ptr *p0 = junk_yard ;
476 junk_yard = junk_yard->next ;
477 p0->next = mp->next ;
478 mp->next = p0 ;
479 return p0 ;
480 }
481 else
482 {
483 mismatch_ptr *p0 = new mismatch_ptr ;
484 p0->next = mp->next ;
485 mp->next = p0 ;
486 return p0 ;
487 }
488 }
489
490 mismatch_ptr *prefix_tree::compare( char c, mismatch_ptr *ptrs ) const
491 {
492 int pos ;
493 switch( c )
494 {
495 case '-': return ptrs ;
496 case 'A': case 'a': pos = 0 ; break ;
497 case 'C': case 'c': pos = 1 ; break ;
498 case 'G': case 'g': pos = 2 ; break ;
499 case 'T': case 't': pos = 3 ; break ;
500 case 'U': case 'u': pos = 3 ; break ;
501 default: pos = -1 ; break ;
502 }
503
504 bool is_first = true ;
505 mismatch_ptr *new_head = 0, *last_done = 0 ;
506 mismatch_ptr *next_in_queue = ptrs ;
507 mismatch_ptr *next_to_prefetch = ptrs ;
508 for( int i = 0 ; i != do_prefetch && next_to_prefetch->next ; ++i )
509 next_to_prefetch = next_to_prefetch->next ;
510
511 while( next_in_queue )
512 {
513 ++total_nodes ;
514 if( next_to_prefetch && next_to_prefetch->ptr ) __builtin_prefetch( next_to_prefetch->ptr ) ;
515 if( next_to_prefetch && next_to_prefetch->next ) __builtin_prefetch( next_to_prefetch->next ) ;
516
517 const node* n = next_in_queue->ptr ;
518 size_t mm = next_in_queue->mismatch ;
519 size_t gg = next_in_queue->gaps ;
520 int ff = next_in_queue->first ;
521 int nn = next_in_queue->matched ;
522
523 if( !next_in_queue->isgap ) out_rec( mm, n, is_first ? 255 : ff, nn ) ;
524
525 // If gaps are allowed, also add gapped nodes for
526 // processing _in_this_iteration_. If
527 // discount_adenine is set, don't gap an A (makes
528 // bookkeeping difficult).
529
530 if( gg < allow_gaps && mm < cutoff && n->depth > 0 ) {
531 for ( int i = discount_adenine ? 1 : 0 ; i != 5 ; i++ ) {
532 int ff_ = is_first ? n->depth-1 : ff ;
533 if( ff_ >= n->drop[i] ) {
534 assert( next_to_prefetch ) ;
535 mismatch_ptr *mp2 = splice_fresh_after( next_to_prefetch ) ;
536 mp2->ptr = n->childs[i] ;
537 mp2->mismatch = mm + 1 ;
538 mp2->gaps = gg + 1 ;
539 mp2->first = ff_ - n->drop[i] ;
540 mp2->isgap = 1 ;
541 mp2->matched = nn ;
542 }
543 }
544 }
545
546 // Are we gapping As? then queue that up, no matter how many
547 // mismatches we've already accumulated. (Note how this isn't
548 // even considered a gap, note that gapping the root actually
549 // makes a certain kind of sense.)
550
551 if( discount_adenine ) {
552 int ff_ = is_first ? n->depth-1 : ff ;
553 if( ff_ >= n->drop[0] && n->drop[0] ) {
554 assert( next_to_prefetch ) ;
555 mismatch_ptr *mp2 = splice_fresh_after( next_to_prefetch ) ;
556 mp2->ptr = n->childs[0] ;
557 mp2->mismatch = mm ;
558 mp2->gaps = gg ;
559 mp2->first = ff_ - n->drop[0] ;
560 mp2->isgap = 0 ;
561 mp2->matched = nn ;
562 }
563 }
564
565 // No longer is anything enqueued into the old queue, so we no
566 // longer need the next_to_prefetch pointer and can move it
567 // ahead.
568 if( next_to_prefetch->next ) next_to_prefetch = next_to_prefetch->next ;
569
570 // At this point, we no longer run into difficulties if the
571 // incoming queue gets emptied. So now we move the pointer to its
572 // matching child and throw it out if dropping the prefix kills
573 // a mismatch. Also, we can move the next_to_prefetch pointer,
574 // since it's not needed anymore in this iteration and might
575 // point to nowhere now. Moreover, if we're at the first node
576 // (the one without any mismatches), this is the place to
577 // initialize the new list.
578
579 int pos_ = pos == -1 ? 4 : pos ;
580 if( is_first ) {
581 next_in_queue = ptrs->next ;
582 if( pos == -1 ) {
583 new_head = seed() ;
584 ptrs->next = junk_yard ;
585 junk_yard = ptrs ;
586 } else {
587 new_head = ptrs ;
588 new_head->matched += 1 - ptrs->ptr->drop[pos] ;
589 new_head->ptr = ptrs->ptr->childs[pos] ;
590 new_head->next = 0 ;
591 }
592 last_done = new_head ;
593 } else if( ff >= n->drop[pos_] ) {
594 next_in_queue->ptr = n->childs[pos_] ;
595 next_in_queue->first -= n->drop[pos_] ;
596 next_in_queue->matched ++ ;
597 next_in_queue->matched -= n->drop[pos_] ;
598 next_in_queue->isgap = 0 ;
599 assert( !last_done->next ) ;
600 last_done->next = next_in_queue ;
601 last_done = next_in_queue ;
602 next_in_queue = next_in_queue->next ;
603 last_done->next = 0 ;
604 } else {
605 mismatch_ptr *p = next_in_queue ;
606 next_in_queue = next_in_queue->next ;
607 p->next = junk_yard ;
608 junk_yard = p ;
609 }
610
611 // The following always produces new mismatches, so skip it
612 // completely if we're already at the limit.
613
614 if ( mm < cutoff ) {
615 // if gaps are allowed, always keep the node (but don't
616 // uselessly gap the root node)
617 if( gg < allow_gaps && n->depth > 0 )
618 {
619 assert( last_done ) ;
620 mismatch_ptr *p = splice_fresh_after( last_done ) ;
621 p->ptr = n ;
622 p->mismatch = mm + 1 ;
623 p->gaps = gg + 1 ;
624 p->isgap = 1 ;
625 p->first = is_first ? n->depth-1 : ff ;
626 p->matched = nn + 1 ;
627 last_done = p ;
628 }
629
630 // Take care of the children, but not the one that matches.
631 // (That one has already been handled.)
632
633 for ( int i = 0 ; i != 5 ; i++ ) {
634 if( i != pos ) {
635 // The child always exists, but we follow it only
636 // iff the first mismatch would not be forgotten by
637 // following a suffix link.
638 assert( n->childs[i] ) ;
639 int ff_ = is_first ? n->depth : ff ;
640 if( ff_ >= n->drop[i] )
641 {
642 mismatch_ptr *p = splice_fresh_after( last_done ) ;
643 p->ptr = n->childs[i] ;
644 p->first = ff_ - n->drop[i] ;
645 p->mismatch = mm + 1 ;
646 p->gaps = gg ;
647 p->isgap = 0 ;
648 p->matched = nn + 1 - n->drop[i] ;
649 assert( !p->next ) ;
650 assert( last_done->next == p ) ;
651 last_done = p ;
652 }
653 }
654 }
655 }
656 is_first = false ;
657 assert( !last_done->next ) ;
658 }
659
660 if( debug_flags & debug_numnodes )
661 {
662 int n = 0 ;
663 for( mismatch_ptr *p = new_head ; p ; p=p->next ) ++n ;
664 std::clog << '\r' << n << std::endl;
665 }
666 return new_head ;
667 }
668