MCPcopy Create free account
hub / github.com/Martinsos/edlib / checkAlignment

Function checkAlignment

test/runTests.cpp:592–641  ·  view source on GitHub ↗

* Checks if alignment is correct. */

Source from the content-addressed store, hash-verified

590 * Checks if alignment is correct.
591 */
592bool checkAlignment(const char* query, int queryLength,
593 const char* target,
594 int score, int pos, EdlibAlignMode mode,
595 unsigned char* alignment, int alignmentLength) {
596 int alignScore = 0;
597 int qIdx = queryLength - 1;
598 int tIdx = pos;
599 for (int i = alignmentLength - 1; i >= 0; i--) {
600 if (alignment[i] == EDLIB_EDOP_MATCH) { // match
601 if (query[qIdx] != target[tIdx]) {
602 printf("Should be match but is a mismatch! (tIdx, qIdx, i): (%d, %d, %d)\n", tIdx, qIdx, i);
603 return false;
604 }
605 qIdx--;
606 tIdx--;
607 } else if (alignment[i] == EDLIB_EDOP_MISMATCH) { // mismatch
608 if (query[qIdx] == target[tIdx]) {
609 printf("Should be mismatch but is a match! (tIdx, qIdx, i): (%d, %d, %d)\n", tIdx, qIdx, i);
610 return false;
611 }
612 alignScore += 1;
613 qIdx--;
614 tIdx--;
615 } else if (alignment[i] == EDLIB_EDOP_INSERT) {
616 alignScore += 1;
617 qIdx--;
618 } else if (alignment[i] == EDLIB_EDOP_DELETE) {
619 if (!(mode == EDLIB_MODE_HW && qIdx == -1))
620 alignScore += 1;
621 tIdx--;
622 }
623 if (tIdx < -1 || qIdx < -1) {
624 printf("Alignment went outside of matrix! (tIdx, qIdx, i): (%d, %d, %d)\n", tIdx, qIdx, i);
625 return false;
626 }
627 }
628 if (qIdx != -1) {
629 printf("Alignment did not reach end!\n");
630 return false;
631 }
632 if (alignScore != score) {
633 printf("Wrong score in alignment! %d should be %d\n", alignScore, score);
634 return false;
635 }
636 if (alignmentLength > 0 && alignment[0] == EDLIB_EDOP_INSERT && tIdx >= 0) {
637 printf("Alignment starts with insertion in target, while it could start with mismatch!\n");
638 return false;
639 }
640 return true;
641}
642
643/**
644 * @param alignment

Callers 2

runRandomTestsFunction · 0.85
executeTestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected