mengyao / Complete-Striped-Smith-Waterman-Library

294 stars 112 forks source link

Segmentation fault in rare cases #70

Closed mkirsche closed 2 years ago

mkirsche commented 4 years ago

I'm trying to use the SSW C++ library for genomic read alignment, but am finding that in rare cases it crashes. I tried isolating my usage of the SSW library (see code below) and modelling it exactly after the example you provide, but it still crashes. I also provided the make file I used, and my g++ version is 7.4.0. Could you please let me know if I am using the API incorrectly, or if not, what would be causing it to crash? The error appears to be an array-out-of-bounds in the following line of ssw.c:

direction_line[de] = temp1 > temp2 ? (int8_t)3 : (int8_t)2;

`#include "ssw_cpp.h"

include

include

include

include <bits/stdc++.h>

using namespace std;

int main() { StripedSmithWaterman::Aligner aln; string ref_seq = "GATTGAAAAACTCCCAGGCTGGACACGGTGGCCCATGCCTGTAATCCCAGCACTCTGGGAGGCTGAGGTGGGCTGATCCCTTGAGGTCAGGAGTTCGAGACCATCCTGGAAAATGTGGCA"; string seq = "AAAGGTGACCGGGCACGGTGGCCCATGCCTATAATCCCAGCACTTTGGGAGGCCCAGGCAGGTGGATCACTTGAGGTCAGGAGTTCGAGACCAGCCTGGC"; StripedSmithWaterman::Alignment aln_result; StripedSmithWaterman::Filter filter; cout << "aligning" << endl; int32_t maskLen = strlen(seq.c_str())/2; maskLen = maskLen < 15 ? 15 : maskLen; aln.Align(seq.c_str(), ref_seq.c_str(), ref_seq.length(), filter, &aln_result, maskLen); cout << "done" << endl; }

CXX = g++ CXXFLAGS = -O2 -std=c++11 -g -Wall

test: testssw.o ssw_cpp.o ssw.o $(CXX) $(CXXFLAGS) -o testssw testssw.o ssw_cpp.o ssw.o

clean: rm testssw *.o`

Thanks! Melanie

morispi commented 4 years ago

Second that.

I'm also getting random segmentation faults when I attempt to fool around with the match scores and mismatch / gap penalties. I don't seem to get any segmentation fault when sticking to default parameters, however.

@mkirsche did you end up finding a fix?

Best, Pierre

mkirsche commented 4 years ago

Nope, unfortunately I ended up having to just modify the surrounding logic to accommodate the crashes and try different seed matches

morispi commented 4 years ago

Guess I'll have to work around as you did, then. Thanks for the quick reply!