From 9093d3dc2de34d2c52b61bc59354c3d064d22f05 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Fri, 11 Aug 2023 12:10:03 -0400 Subject: [PATCH] Add inline racing stripes for speed --- src/minimizer_mapper.cpp | 59 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/minimizer_mapper.cpp b/src/minimizer_mapper.cpp index b0bf41a6aad..ae2991c0238 100644 --- a/src/minimizer_mapper.cpp +++ b/src/minimizer_mapper.cpp @@ -4034,6 +4034,36 @@ static int32_t flank_penalty(size_t length, const std::vector& fro return result; } +/// A helper function that cna merge softclips in properly when joining up +/// paths, but doesn't need expensive full passes over the paths later. +static inline void add_to_path(Path* target, Path* to_append) { + for (auto& mapping : *to_append->mutable_mapping()) { + // For each mapping to append + if (target->mapping_size() > 0) { + // There is an existing mapping on the path. + // Find that previous mapping. + auto* prev_mapping = target->mutable_mapping(target->mapping_size() - 1); + + if (mapping.position().node_id() == prev_mapping->position().node_id() && + (mapping.position().offset() != 0 || mapping_is_total_insertion(*prev_mapping) || mapping_is_total_insertion(mapping))) { + // Previous mapping is to the same node, and either the new + // mapping doesn't start at 0, or one mapping takes up no + // space on the node (i.e. is a pure insert). + // + // So we want to combine the mappings. + for (auto& edit : *mapping.mutable_edit()) { + // Move over all the edits in this mapping onto the end of that one. + *prev_mapping->add_edit() = std::move(edit); + } + + continue; + } + } + // If we don't combine the mappings, we need to just move the whole mapping + *target->add_mapping() = std::move(mapping); + } +}; + void MinimizerMapper::find_optimal_tail_alignments(const Alignment& aln, const vector& extended_seeds, LazyRNG& rng, Alignment& best, Alignment& second_best) const { // This assumes that full-length extensions have the highest scores. @@ -4271,35 +4301,6 @@ void MinimizerMapper::find_optimal_tail_alignments(const Alignment& aln, const v second_best.set_score(second_score); // Concatenate the paths. - // We need a helper function that cna merge softclips in propelry. - auto add_to_path = [](Path* target, Path* to_append) { - for (auto& mapping : *to_append->mutable_mapping()) { - // For each mapping to append - if (target->mapping_size() > 0) { - // There is an existing mapping on the path. - // Find that previous mapping. - auto* prev_mapping = target->mutable_mapping(target->mapping_size() - 1); - - if (mapping.position().node_id() == prev_mapping->position().node_id() && - (mapping.position().offset() != 0 || mapping_is_total_insertion(*prev_mapping) || mapping_is_total_insertion(mapping))) { - // Previous mapping is to the same node, and either the new - // mapping doesn't start at 0, or one mapping takes up no - // space on the node (i.e. is a pure insert). - // - // So we want to combine the mappings. - for (auto& edit : *mapping.mutable_edit()) { - // Move over all the edits in this mapping onto the end of that one. - *prev_mapping->add_edit() = std::move(edit); - } - - continue; - } - } - // If we don't combine the mappings, we need to just move the whole mapping - *target->add_mapping() = std::move(mapping); - } - }; - // We know there must be at least an edit boundary // between each part, because the maximal extension doesn't end in a