// Iteratively left-aligns the indels in the alignment until we have a stable // realignment. Returns true on realignment success or non-realignment. // Returns false if we exceed the maximum number of realignment iterations. // bool stablyLeftAlign(BAMALIGN& alignment, string referenceSequence, int maxiterations, bool debug) { #ifdef VERBOSE_DEBUG int mismatchesBefore = countMismatches(alignment, referenceSequence); #endif if (!leftAlign(alignment, referenceSequence, debug)) { return true; } else { while (leftAlign(alignment, referenceSequence, debug) && --maxiterations > 0) { LEFTALIGN_DEBUG("realigning ..." << endl); } #ifdef VERBOSE_DEBUG int mismatchesAfter = countMismatches(alignment, referenceSequence); if (mismatchesBefore != mismatchesAfter) { cerr << alignment.QNAME << endl; cerr << "ERROR: found " << mismatchesBefore << " mismatches before, but " << mismatchesAfter << " after left realignment!" << endl; exit(1); } #endif if (maxiterations <= 0) { return false; } else { return true; } } }
void test_countMismatches(char *a, char *b, int e) { int n; if ((n=countMismatches(a,b)) == e) success++; else { failure++; fprintf(stderr, "countMismatches(%s,%s) returned %d: expected %d\n", a,b,n,e); } }