From c32f4c2b07df137a0fce72ec7c7e60474937a52e Mon Sep 17 00:00:00 2001 From: Mengyao Zhao Date: Fri, 21 Apr 2023 15:31:07 -0400 Subject: [PATCH] make s_align.flag as the return value of c++ API Align function --- src/example.cpp | 4 +--- src/ssw.c | 2 +- src/ssw_cpp.cpp | 24 +++++++++--------------- src/ssw_cpp.h | 12 ++++++------ 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/example.cpp b/src/example.cpp index 7f97205..1816f61 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -5,7 +5,7 @@ // 1) g++ -Wall ssw_cpp.cpp ssw.c example.cpp // 2) ./a.out // Created by Wan-Ping Lee on 09/04/12. -// Last revision by Mengyao Zhao on 2017-06-05 +// Last revision by Mengyao Zhao on 2023-Apr-21 // ========================== #include @@ -24,8 +24,6 @@ int main() { const string query = "CTGAGCCGGTAAATC"; int32_t maskLen = strlen(query.c_str())/2; maskLen = maskLen < 15 ? 15 : maskLen; - //const string ref = "CCGTTTATCGCA"; - //const string query = "CCTTTTATCGCA"; // Declares a default Aligner StripedSmithWaterman::Aligner aligner; diff --git a/src/ssw.c b/src/ssw.c index 99da096..e8599c6 100644 --- a/src/ssw.c +++ b/src/ssw.c @@ -56,7 +56,7 @@ * * Created by Mengyao Zhao on 6/22/10. * Copyright 2010 Boston College. All rights reserved. - * Version 1.2.4 + * Version 1.2.5 * Last revision by Mengyao Zhao on 2022-Apr-17. * * The lazy-F loop implementation was derived from SWPS3, which is diff --git a/src/ssw_cpp.cpp b/src/ssw_cpp.cpp index d5e3a7e..fe7dc99 100644 --- a/src/ssw_cpp.cpp +++ b/src/ssw_cpp.cpp @@ -1,6 +1,6 @@ // ssw_cpp.cpp // Created by Wan-Ping Lee -// Last revision by Mengyao Zhao on 2017-05-30 +// Last revision by Mengyao Zhao on 2023-Apr-21 #include "ssw_cpp.h" #include "ssw.h" @@ -290,25 +290,18 @@ int Aligner::SetReferenceSequence(const char* seq, const int& length) { int len = 0; if (translation_matrix_) { - // calculate the valid length - //int calculated_ref_length = static_cast(strlen(seq)); - //int valid_length = (calculated_ref_length > length) - // ? length : calculated_ref_length; - int valid_length = length; // delete the current buffer CleanReferenceSequence(); // allocate a new buffer - translated_reference_ = new int8_t[valid_length]; + translated_reference_ = new int8_t[length]; - len = TranslateBase(seq, valid_length, translated_reference_); + len = TranslateBase(seq, length, translated_reference_); } else { // nothing } reference_length_ = len; return len; - - } int Aligner::TranslateBase(const char* bases, const int& length, @@ -326,7 +319,7 @@ int Aligner::TranslateBase(const char* bases, const int& length, } -bool Aligner::Align(const char* query, const Filter& filter, +uint16_t Aligner::Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const { if (!translation_matrix_) return false; @@ -351,18 +344,18 @@ bool Aligner::Align(const char* query, const Filter& filter, alignment->Clear(); ConvertAlignment(*s_al, query_len, alignment); alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_reference_, translated_query, query_len); - + uint16_t align_flag = s_al->flag; // Free memory delete [] translated_query; align_destroy(s_al); init_destroy(profile); - return true; + return align_flag; } -bool Aligner::Align(const char* query, const char* ref, const int& ref_len, +uint16_t Aligner::Align(const char* query, const char* ref, const int& ref_len, const Filter& filter, Alignment* alignment, const int32_t maskLen) const { if (!translation_matrix_) return false; @@ -392,6 +385,7 @@ bool Aligner::Align(const char* query, const char* ref, const int& ref_len, alignment->Clear(); ConvertAlignment(*s_al, query_len, alignment); alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_ref, translated_query, query_len); + uint16_t align_flag = s_al->flag; // Free memory delete [] translated_query; @@ -399,7 +393,7 @@ bool Aligner::Align(const char* query, const char* ref, const int& ref_len, align_destroy(s_al); init_destroy(profile); - return true; + return align_flag; } void Aligner::Clear(void) { diff --git a/src/ssw_cpp.h b/src/ssw_cpp.h index 4901352..c312fc1 100644 --- a/src/ssw_cpp.h +++ b/src/ssw_cpp.h @@ -1,6 +1,6 @@ // ssw_cpp.h // Created by Wan-Ping Lee -// Last revision by Mengyao Zhao on 2017-05-30 +// Last revision by Mengyao Zhao on 2023-Apr-21 #ifndef COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_ #define COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_ @@ -109,7 +109,7 @@ class Aligner { // and replaced. // @param seq The reference bases; // [NOTICE] It is not necessary null terminated. - // @param length The length of bases will be be built. + // @param length The length of bases will be built. // @return The length of the built bases. // ========= int SetReferenceSequence(const char* seq, const int& length); @@ -134,9 +134,9 @@ class Aligner { // @param maskLen The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to // use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function // will NOT return the suboptimal alignment information. - // @return True: succeed; false: fail. + // @return If the alignment path is accurate (or has missing part). 0: accurate; 1: banded_sw is totally failed; 2: banded_sw returned path has missing part // ========= - bool Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const; + uint16_t Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const; // ========= // @function Align the query againt the reference. @@ -151,9 +151,9 @@ class Aligner { // @param maskLen The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to // use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function // will NOT return the suboptimal alignment information. - // @return True: succeed; false: fail. + // @return If the alignment path is accurate (or has missing part). 0: accurate; 1: banded_sw is totally failed; 2: banded_sw returned path has missing part // ========= - bool Align(const char* query, const char* ref, const int& ref_len, + uint16_t Align(const char* query, const char* ref, const int& ref_len, const Filter& filter, Alignment* alignment, const int32_t maskLen) const; // @function Clear up all containers and thus the aligner is disabled.