Skip to content

Commit c32f4c2

Browse files
author
Mengyao Zhao
committed
make s_align.flag as the return value of c++ API Align function
1 parent 543ee07 commit c32f4c2

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

src/example.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// 1) g++ -Wall ssw_cpp.cpp ssw.c example.cpp
66
// 2) ./a.out
77
// Created by Wan-Ping Lee on 09/04/12.
8-
// Last revision by Mengyao Zhao on 2017-06-05
8+
// Last revision by Mengyao Zhao on 2023-Apr-21
99
// ==========================
1010

1111
#include <iostream>
@@ -24,8 +24,6 @@ int main() {
2424
const string query = "CTGAGCCGGTAAATC";
2525
int32_t maskLen = strlen(query.c_str())/2;
2626
maskLen = maskLen < 15 ? 15 : maskLen;
27-
//const string ref = "CCGTTTATCGCA";
28-
//const string query = "CCTTTTATCGCA";
2927

3028
// Declares a default Aligner
3129
StripedSmithWaterman::Aligner aligner;

src/ssw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*
5757
* Created by Mengyao Zhao on 6/22/10.
5858
* Copyright 2010 Boston College. All rights reserved.
59-
* Version 1.2.4
59+
* Version 1.2.5
6060
* Last revision by Mengyao Zhao on 2022-Apr-17.
6161
*
6262
* The lazy-F loop implementation was derived from SWPS3, which is

src/ssw_cpp.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ssw_cpp.cpp
22
// Created by Wan-Ping Lee
3-
// Last revision by Mengyao Zhao on 2017-05-30
3+
// Last revision by Mengyao Zhao on 2023-Apr-21
44

55
#include "ssw_cpp.h"
66
#include "ssw.h"
@@ -290,25 +290,18 @@ int Aligner::SetReferenceSequence(const char* seq, const int& length) {
290290

291291
int len = 0;
292292
if (translation_matrix_) {
293-
// calculate the valid length
294-
//int calculated_ref_length = static_cast<int>(strlen(seq));
295-
//int valid_length = (calculated_ref_length > length)
296-
// ? length : calculated_ref_length;
297-
int valid_length = length;
298293
// delete the current buffer
299294
CleanReferenceSequence();
300295
// allocate a new buffer
301-
translated_reference_ = new int8_t[valid_length];
296+
translated_reference_ = new int8_t[length];
302297

303-
len = TranslateBase(seq, valid_length, translated_reference_);
298+
len = TranslateBase(seq, length, translated_reference_);
304299
} else {
305300
// nothing
306301
}
307302

308303
reference_length_ = len;
309304
return len;
310-
311-
312305
}
313306

314307
int Aligner::TranslateBase(const char* bases, const int& length,
@@ -326,7 +319,7 @@ int Aligner::TranslateBase(const char* bases, const int& length,
326319
}
327320

328321

329-
bool Aligner::Align(const char* query, const Filter& filter,
322+
uint16_t Aligner::Align(const char* query, const Filter& filter,
330323
Alignment* alignment, const int32_t maskLen) const
331324
{
332325
if (!translation_matrix_) return false;
@@ -351,18 +344,18 @@ bool Aligner::Align(const char* query, const Filter& filter,
351344
alignment->Clear();
352345
ConvertAlignment(*s_al, query_len, alignment);
353346
alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_reference_, translated_query, query_len);
354-
347+
uint16_t align_flag = s_al->flag;
355348

356349
// Free memory
357350
delete [] translated_query;
358351
align_destroy(s_al);
359352
init_destroy(profile);
360353

361-
return true;
354+
return align_flag;
362355
}
363356

364357

365-
bool Aligner::Align(const char* query, const char* ref, const int& ref_len,
358+
uint16_t Aligner::Align(const char* query, const char* ref, const int& ref_len,
366359
const Filter& filter, Alignment* alignment, const int32_t maskLen) const
367360
{
368361
if (!translation_matrix_) return false;
@@ -392,14 +385,15 @@ bool Aligner::Align(const char* query, const char* ref, const int& ref_len,
392385
alignment->Clear();
393386
ConvertAlignment(*s_al, query_len, alignment);
394387
alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_ref, translated_query, query_len);
388+
uint16_t align_flag = s_al->flag;
395389

396390
// Free memory
397391
delete [] translated_query;
398392
delete [] translated_ref;
399393
align_destroy(s_al);
400394
init_destroy(profile);
401395

402-
return true;
396+
return align_flag;
403397
}
404398

405399
void Aligner::Clear(void) {

src/ssw_cpp.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ssw_cpp.h
22
// Created by Wan-Ping Lee
3-
// Last revision by Mengyao Zhao on 2017-05-30
3+
// Last revision by Mengyao Zhao on 2023-Apr-21
44

55
#ifndef COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_
66
#define COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_
@@ -109,7 +109,7 @@ class Aligner {
109109
// and replaced.
110110
// @param seq The reference bases;
111111
// [NOTICE] It is not necessary null terminated.
112-
// @param length The length of bases will be be built.
112+
// @param length The length of bases will be built.
113113
// @return The length of the built bases.
114114
// =========
115115
int SetReferenceSequence(const char* seq, const int& length);
@@ -134,9 +134,9 @@ class Aligner {
134134
// @param maskLen The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to
135135
// use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function
136136
// will NOT return the suboptimal alignment information.
137-
// @return True: succeed; false: fail.
137+
// @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
138138
// =========
139-
bool Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
139+
uint16_t Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
140140

141141
// =========
142142
// @function Align the query againt the reference.
@@ -151,9 +151,9 @@ class Aligner {
151151
// @param maskLen The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to
152152
// use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function
153153
// will NOT return the suboptimal alignment information.
154-
// @return True: succeed; false: fail.
154+
// @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
155155
// =========
156-
bool Align(const char* query, const char* ref, const int& ref_len,
156+
uint16_t Align(const char* query, const char* ref, const int& ref_len,
157157
const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
158158

159159
// @function Clear up all containers and thus the aligner is disabled.

0 commit comments

Comments
 (0)