Skip to content

Commit

Permalink
Merge pull request #274 from kdm9/kdm9-paf-fix
Browse files Browse the repository at this point in the history
fix: invalid paf produced for some patch alignments
  • Loading branch information
ekg authored Sep 24, 2024
2 parents 1f485f3 + dd0bbc3 commit 73c1331
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
48 changes: 27 additions & 21 deletions src/common/wflign/src/wflign_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,26 +2032,29 @@ query_start : query_end)
// write how many reverse complement alignments were found
//std::cerr << "got " << rev_patch_alns.size() << " rev patch alns" << std::endl;
for (auto& patch_aln : multi_patch_alns) {
write_alignment_paf(
out,
patch_aln,
query_name,
query_total_length,
query_offset,
query_length,
query_is_rev,
target_name,
target_total_length,
target_offset,
target_length,
min_identity,
mashmap_estimated_identity,
false, // Don't add an endline after each alignment
true); // This is a reverse complement alignment
// write tag indicating that this is a multipatch alignment
out << "\t" << "pt:Z:true" << "\t"
// and if the patch is inverted as well
<< "\t" << "iv:Z:" << (patch_aln.is_rev ? "true" : "false") << "\n";
// write_alignment_paf only writes anything if aln.ok. We need to guard the manual tag writing below with the same conditional to avoid writing an invalid PAF.
bool wrote = write_alignment_paf(
out,
patch_aln,
query_name,
query_total_length,
query_offset,
query_length,
query_is_rev,
target_name,
target_total_length,
target_offset,
target_length,
min_identity,
mashmap_estimated_identity,
false, // Don't add an endline after each alignment
true); // This is a reverse complement alignment
if (wrote) {
// write tag indicating that this is a multipatch alignment
out << "\t" << "pt:Z:true" << "\t"
// and if the patch is inverted as well
<< "iv:Z:" << (patch_aln.is_rev ? "true" : "false") << "\n";
}
}
}
out << std::flush;
Expand Down Expand Up @@ -2221,7 +2224,7 @@ void write_alignment_sam(
free(patch_cigar);
}

void write_alignment_paf(
bool write_alignment_paf(
std::ostream& out,
const alignment_t& aln,
const std::string& query_name,
Expand All @@ -2237,6 +2240,7 @@ void write_alignment_paf(
const float& mashmap_estimated_identity,
const bool& with_endline,
const bool& is_rev_patch) {
bool ret = false; // return true if we wrote the alignment

if (aln.ok) {
uint64_t matches = 0;
Expand Down Expand Up @@ -2291,9 +2295,11 @@ void write_alignment_paf(
if (with_endline) {
out << std::endl;
}
ret = true;
}
free(cigar);
}
return ret;
}

double float2phred(const double& prob) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/wflign/src/wflign_patch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace wflign {
const char* query,
const char* target,
const int64_t& target_pointer_shift);
void write_alignment_paf(
bool write_alignment_paf(
std::ostream& out,
const alignment_t& aln,
const std::string& query_name,
Expand Down

0 comments on commit 73c1331

Please sign in to comment.