Skip to content

Commit

Permalink
Add in offset even when the alignment starts past the end of the anch…
Browse files Browse the repository at this point in the history
…or node
  • Loading branch information
adamnovak committed Jul 1, 2024
1 parent accbe34 commit 88c3ff6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/minimizer_mapper_from_chains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3681,9 +3681,9 @@ std::pair<size_t, size_t> 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<std::pair<nid_t, bool>(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
Expand Down Expand Up @@ -3813,23 +3813,29 @@ std::pair<size_t, size_t> 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
Expand Down
2 changes: 2 additions & 0 deletions src/unittest/minimizer_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

1 comment on commit 88c3ff6

@adamnovak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for branch lr-giraffe. View the full report here.

16 tests passed, 0 tests failed and 0 tests skipped in 17208 seconds

Please sign in to comment.