Skip to content

Commit

Permalink
Merge pull request #4285 from vgteam/wfa-full-length-bonus
Browse files Browse the repository at this point in the history
Make WFAExtender apply full length bonuses even though it doesn't use them internally
  • Loading branch information
adamnovak authored May 7, 2024
2 parents 8e28e32 + 5dc1f7d commit a94c974
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 63 deletions.
13 changes: 12 additions & 1 deletion src/gbwt_extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,14 @@ WFAAlignment WFAExtender::connect(std::string sequence, pos_t from, pos_t to) co
}

WFAAlignment WFAExtender::suffix(const std::string& sequence, pos_t from) const {
return this->connect(sequence, from, pos_t(0, false, 0));
WFAAlignment result = this->connect(sequence, from, pos_t(0, false, 0));

if (!result.edits.empty() && result.length == sequence.length() && (result.edits.back().first == WFAAlignment::match || result.edits.back().first == WFAAlignment::mismatch)) {
// The alignment used all of the sequence and has a match/mismatch at the appropriate end
result.score += this->aligner->full_length_bonus;
}

return result;
}

WFAAlignment WFAExtender::prefix(const std::string& sequence, pos_t to) const {
Expand All @@ -2297,6 +2304,10 @@ WFAAlignment WFAExtender::prefix(const std::string& sequence, pos_t to) const {
WFAAlignment result = this->connect(reverse_complement(sequence), to, pos_t(0, false, 0));
result.flip(*(this->graph), sequence);

if (!result.edits.empty() && result.length == sequence.length() && (result.edits.front().first == WFAAlignment::match || result.edits.front().first == WFAAlignment::mismatch)) {
result.score += this->aligner->full_length_bonus;
}

return result;
}

Expand Down
8 changes: 6 additions & 2 deletions src/gbwt_extender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ class WFAExtender {
* entire sequence with an acceptable score, returns the highest-scoring
* partial alignment, which may be empty.
*
* Applies the full-length bonus if the result ends with a match or mismatch.
* TODO: Use the full-length bonus to determine the optimal alignment.
*
* NOTE: This creates a suffix of the full alignment by aligning a
* prefix of the sequence.
* TODO: Should we use full-length bonuses?
*/
WFAAlignment suffix(const std::string& sequence, pos_t from) const;

Expand All @@ -424,9 +426,11 @@ class WFAExtender {
* sequence with an acceptable score, returns the highest-scoring partial
* alignment, which may be empty.
*
* Applies the full-length bonus if the result begins with a match or mismatch.
* TODO: Use the full-length bonus to determine the optimal alignment.
*
* NOTE: This creates a prefix of the full alignment by aligning a suffix
* of the sequence.
* TODO: Should we use full-length bonuses?
*/
WFAAlignment prefix(const std::string& sequence, pos_t to) const;

Expand Down
Loading

0 comments on commit a94c974

Please sign in to comment.