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

fix: invalid paf produced for some patch alignments #274

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading