Skip to content

Commit

Permalink
put back trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
ekg committed Jul 26, 2024
1 parent f31f6dd commit c341e1e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/common/wflign/src/wflign_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,38 @@ AlignmentBounds find_alignment_bounds(const alignment_t& aln) {
return bounds;
}

void trim_alignment(alignment_t& aln) {
// Trim head
int head_trim_q = 0, head_trim_t = 0;
while (aln.edit_cigar.begin_offset < aln.edit_cigar.end_offset) {
char op = aln.edit_cigar.cigar_ops[aln.edit_cigar.begin_offset];
if (op != 'I' && op != 'D') break;
if (op == 'I') head_trim_q++;
if (op == 'D') head_trim_t++;
aln.edit_cigar.begin_offset++;
}

// Trim tail
int tail_trim_q = 0, tail_trim_t = 0;
while (aln.edit_cigar.end_offset > aln.edit_cigar.begin_offset) {
char op = aln.edit_cigar.cigar_ops[aln.edit_cigar.end_offset - 1];
if (op != 'I' && op != 'D') break;
if (op == 'I') tail_trim_q++;
if (op == 'D') tail_trim_t++;
aln.edit_cigar.end_offset--;
}

// Adjust coordinates
if (aln.is_rev) {
aln.j += tail_trim_q; // For reverse alignments, tail trim affects the start
} else {
aln.j += head_trim_q;
}
aln.i += head_trim_t;
aln.query_length -= (head_trim_q + tail_trim_q);
aln.target_length -= (head_trim_t + tail_trim_t);
}

std::vector<alignment_t> do_progressive_wfa_patch_alignment(
const char* query,
const uint64_t& query_start,
Expand Down Expand Up @@ -1184,6 +1216,7 @@ void write_merged_alignment(
}
} else if (save_multi_patch_alns) {
for (auto& aln : patch_alignments) {
trim_alignment(aln);
multi_patch_alns.push_back(aln);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/common/wflign/src/wflign_patch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace wflign {
const int64_t& chain_gap,
const int& max_patching_score,
const uint64_t& min_inversion_length);
void trim_alignment(alignment_t& aln);
std::vector<alignment_t> do_progressive_wfa_patch_alignment(
const char* query,
const uint64_t& query_start,
Expand Down

0 comments on commit c341e1e

Please sign in to comment.