From 88c3ff6eb0237f0be24298c0d7bfe6d56116bf27 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Mon, 1 Jul 2024 16:40:52 -0400 Subject: [PATCH] Add in offset even when the alignment starts past the end of the anchor node --- src/minimizer_mapper_from_chains.cpp | 30 +++++++++++++++++----------- src/unittest/minimizer_mapper.cpp | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/minimizer_mapper_from_chains.cpp b/src/minimizer_mapper_from_chains.cpp index e5f67ee38ba..5fb53c7d773 100644 --- a/src/minimizer_mapper_from_chains.cpp +++ b/src/minimizer_mapper_from_chains.cpp @@ -3681,9 +3681,9 @@ std::pair MinimizerMapper::align_sequence_between(const pos_t& l MinimizerMapper::with_dagified_local_graph(left_anchor, right_anchor, max_path_length, *graph, [&](DeletableHandleGraph& dagified_graph, const std::function(const handle_t&)>& dagified_handle_to_base) { -//#ifdef debug +#ifdef debug dump_debug_graph(dagified_graph); -//#endif +#endif // Then trim off the tips that are either in the wrong orientation relative // to whether we want them to be a source or a sink, or extraneous @@ -3813,23 +3813,29 @@ std::pair MinimizerMapper::align_sequence_between(const pos_t& l Mapping* m = alignment.mutable_path()->mutable_mapping(i); handle_t dagified_handle = dagified_graph.get_handle(m->position().node_id(), m->position().is_reverse()); - auto base_coords = dagified_handle_to_base(dagified_handle); - + auto base_coords = dagified_handle_to_base(dagified_handle); + m->mutable_position()->set_node_id(base_coords.first); m->mutable_position()->set_is_reverse(base_coords.second); } - if (!is_empty(left_anchor) && alignment.path().mapping_size() > 0 && offset(left_anchor) != 0 && offset(left_anchor) < graph->get_length(graph->get_handle(id(left_anchor)))) { - // There is some of the left anchor's node actually in the - // extracted graph. The left anchor isn't past the end of its node. - + if (!is_empty(left_anchor) && alignment.path().mapping_size() > 0) { // Get the positions of the leftmost mapping Position* left_pos = alignment.mutable_path()->mutable_mapping(0)->mutable_position(); - // The alignment must actually start on the anchor node. - assert(left_pos->node_id() == id(left_anchor)); + if (offset(left_anchor) != 0 && offset(left_anchor) < graph->get_length(graph->get_handle(id(left_anchor)))) { + // There is some of the left anchor's node actually in the + // extracted graph. The left anchor isn't past the end of its node. - // Add on the offset for the missing piece of the left anchor node - left_pos->set_offset(left_pos->offset() + offset(left_anchor)); + // The alignment must actually start on the anchor node. + assert(left_pos->node_id() == id(left_anchor)); + } + + if (left_pos->node_id() == id(left_anchor)) { + // If the alignment does start on the anchor node (even at 0 or at the past-end position) + + // Add on the offset for the cut-off piece of the left anchor node + left_pos->set_offset(left_pos->offset() + offset(left_anchor)); + } } if (alignment.path().mapping_size() > 0) { // Make sure we don't have an empty mapping on the end diff --git a/src/unittest/minimizer_mapper.cpp b/src/unittest/minimizer_mapper.cpp index 1293a051ccc..e9e7a5071af 100644 --- a/src/unittest/minimizer_mapper.cpp +++ b/src/unittest/minimizer_mapper.cpp @@ -328,6 +328,8 @@ TEST_CASE("MinimizerMapper can map against subgraphs between abutting points", " pos_t right_anchor {graph.get_id(h2), false, 0}; TestMinimizerMapper::align_sequence_between(left_anchor, right_anchor, 100, 20, &graph, &aligner, aln); + + std::cerr << pb2json(aln) << std::endl; // Make sure we get the right alignment REQUIRE(aln.path().mapping_size() == 1);