Skip to content

Commit

Permalink
make s_align.flag as the return value of c++ API Align function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengyao Zhao committed Apr 21, 2023
1 parent 543ee07 commit c32f4c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ssw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 9 additions & 15 deletions src/ssw_cpp.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<int>(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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -392,14 +385,15 @@ 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;
delete [] translated_ref;
align_destroy(s_al);
init_destroy(profile);

return true;
return align_flag;
}

void Aligner::Clear(void) {
Expand Down
12 changes: 6 additions & 6 deletions src/ssw_cpp.h
Original file line number Diff line number Diff line change
@@ -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_
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit c32f4c2

Please sign in to comment.