From d804de66130cda6d7010acbd1f1fe8495e27c3f4 Mon Sep 17 00:00:00 2001 From: "Dr. K. D. Murray" <1560490+kdm9@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:16:37 +0200 Subject: [PATCH] fix: invalid paf produced for some patch alignments --- src/common/wflign/src/wflign_patch.cpp | 43 ++++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/common/wflign/src/wflign_patch.cpp b/src/common/wflign/src/wflign_patch.cpp index 6eae79e6..9bfad249 100644 --- a/src/common/wflign/src/wflign_patch.cpp +++ b/src/common/wflign/src/wflign_patch.cpp @@ -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"; + if (patch_aln.ok) { + // 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. + 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 + << "iv:Z:" << (patch_aln.is_rev ? "true" : "false") << "\n"; + } } } out << std::flush;