smarco/WFA2-lib

Possible bug in ends-free score calculation when match < 0

ctsa opened this issue · 3 comments

ctsa commented

Thanks for the great library. I've observed an issue with the alignment score in some endsfree alignments when I set a match score. I've been able to boil this down to a relatively small test case as follows:

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "wavefront/wavefront_align.h"

int main() {
    char *pattern = "A";
    char *text    = "ABC";

    wavefront_aligner_attr_t attr = wavefront_aligner_attr_default;
    attr.distance_metric = gap_linear;
    attr.linear_penalties.match = -1;
    attr.linear_penalties.mismatch = 1;
    attr.linear_penalties.indel = 1;
    attr.alignment_scope = compute_alignment;

    attr.alignment_form.span = alignment_endsfree;
    attr.alignment_form.pattern_begin_free = 0;
    attr.alignment_form.pattern_end_free = 0;
    attr.alignment_form.text_begin_free = 0;
    attr.alignment_form.text_end_free = 2;

    wavefront_aligner_t* const wf_aligner = wavefront_aligner_new(&attr);
    wavefront_align(wf_aligner, pattern, strlen(pattern), text, strlen(text));
    cigar_print_pretty(stderr,
      pattern,strlen(pattern),text,strlen(text),
      wf_aligner->cigar,wf_aligner->mm_allocator);

    fprintf(stderr,"Alignment Score %d\n",wf_aligner->cigar->score);

    wavefront_aligner_delete(wf_aligner);
}

On the current tip of main (94bcccd), this program produces:

$  gcc -I../WFA2-lib ../WFA2-lib/build/libwfa2.a test1.c
$ a.out
      ALIGNMENT 1M2I
      ALIGNMENT.COMPACT 2I
      PATTERN    A--
                 |  
      TEXT       ABC
Alignment Score 2

...with the incorrect score of 2 instead of 1. This seems to be a trailing edge issue, because I can't reproduce the problem with the equivalent 'text_begin_free' setting.

smarco commented

Sorry for the late reply.

I believe this is solved in the development branch (now merged into main).
I tried your example and it gives a correct solution.

Can you please double-check that the error has been resolved?

Best,

ctsa commented
ctsa commented

I've retested on the latest version of main and verify that this test case behaves as expected now. Thanks for the update!