Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ksw2 to align soft-clipped ends from ungapped alignment #382

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Add soft clipping to CIGAR if necessary
  • Loading branch information
marcelm committed Feb 22, 2024
commit 7d23a81e91fb8390bd19f87e9f3525837ed21b11
2 changes: 2 additions & 0 deletions src/aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ AlignmentInfo Aligner::ksw_extend(const std::string& query, const std::string_vi
info.ref_end = ez.max_t + 1;
info.query_end = ez.max_q + 1;
info.sw_score = ez.max;
info.cigar.push(CIGAR_SOFTCLIP, query.length() - info.query_end);
}
assert(info.cigar.derived_sequence_length() == query.length());

kfree(km, ez.cigar);
return info;
Expand Down
12 changes: 12 additions & 0 deletions src/cigar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ class Cigar {
return dist;
}

size_t derived_sequence_length() const {
size_t length = 0;
for (auto op_len : m_ops) {
auto op = op_len & 0xf;
auto len = op_len >> 4;
if (op == CIGAR_MATCH || op == CIGAR_EQ || op == CIGAR_X || op == CIGAR_INS || op == CIGAR_SOFTCLIP) {
length += len;
}
}
return length;
}

void reverse() {
std::reverse(m_ops.begin(), m_ops.end());
}
Expand Down