Skip to content

Commit

Permalink
Call ksw_gen_simple_mat only once
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelm committed Mar 17, 2023
1 parent b70bf3c commit 88ffb17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ unsigned char seq_nt4_table[256] = {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
};

} // namespace

void ksw_gen_simple_mat(int m, int8_t *mat, int8_t a, int8_t b)
{
int i, j;
Expand All @@ -233,8 +235,6 @@ void ksw_gen_simple_mat(int m, int8_t *mat, int8_t a, int8_t b)
mat[(m - 1) * m + j] = 0;
}

} // namespace

aln_info Aligner::ksw_extend(const std::string& query, const std::string& ref, bool right_align) const {
int w = -1; // band width; -1 is inf
int zdrop = -1; // -1 to disable
Expand All @@ -245,10 +245,6 @@ aln_info Aligner::ksw_extend(const std::string& query, const std::string& ref, b
ksw_extz_t ez;
memset(&ez, 0, sizeof(ksw_extz_t));

int8_t m = 5;
int8_t mat[25];
ksw_gen_simple_mat(5, mat, parameters.match, -parameters.mismatch);

ez.max_q = ez.max_t = ez.mqe_t = ez.mte_q = -1;
ez.max = 0; ez.mqe = ez.mte = KSW_NEG_INF;
ez.n_cigar = 0;
Expand All @@ -262,7 +258,7 @@ aln_info Aligner::ksw_extend(const std::string& query, const std::string& ref, b
tseq[i] = seq_nt4_table[(uint8_t)ref[i]];

ksw_extz2_sse(
nullptr, qlen, (uint8_t*)qseq, tlen, (uint8_t*)tseq, m, mat, parameters.gap_open, parameters.gap_extend, w, zdrop, parameters.end_bonus, flag, &ez
nullptr, qlen, (uint8_t*)qseq, tlen, (uint8_t*)tseq, ksw_matrix_m, ksw_matrix, parameters.gap_open, parameters.gap_extend, w, zdrop, parameters.end_bonus, flag, &ez
);
free(qseq);
free(tseq);
Expand Down
8 changes: 7 additions & 1 deletion src/aligner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ struct aln_info {
int ref_span() const { return ref_end - ref_start; }
};

void ksw_gen_simple_mat(int m, int8_t *mat, int8_t a, int8_t b);

struct Aligner {
public:
Aligner(alignment_params parameters)
: parameters(parameters)
, ssw_aligner(StripedSmithWaterman::Aligner(parameters.match, parameters.mismatch, parameters.gap_open, parameters.gap_extend))
{ }
{
ksw_gen_simple_mat(ksw_matrix_m, ksw_matrix, parameters.match, -parameters.mismatch);
}

aln_info align(const std::string &query, const std::string &ref) const;

Expand Down Expand Up @@ -63,6 +67,8 @@ struct Aligner {
const StripedSmithWaterman::Aligner ssw_aligner;
const StripedSmithWaterman::Filter filter;
mutable unsigned m_align_calls{0}; // no. of calls to the align() method
const int8_t ksw_matrix_m{5};
int8_t ksw_matrix[25];
};

inline int hamming_distance(const std::string &s, const std::string &t) {
Expand Down

0 comments on commit 88ffb17

Please sign in to comment.