Skip to content

Commit

Permalink
Merge pull request #4454 from vgteam/distanceless-index
Browse files Browse the repository at this point in the history
Distanceless index
  • Loading branch information
adamnovak authored Nov 26, 2024
2 parents c15295d + da922cb commit cd71bf9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deps/libbdsg
32 changes: 21 additions & 11 deletions src/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,6 @@ void populate_snarl_index(
temp_index.use_oversized_snarls = true;
}

if (size_limit == 0) {
all_children.clear();
}
//Add the start and end nodes to the list of children so that we include them in the traversal
if (!temp_snarl_record.is_root_snarl) {
all_children.emplace_back(SnarlDistanceIndex::TEMP_NODE, temp_snarl_record.start_node_id);
Expand Down Expand Up @@ -1141,8 +1138,9 @@ void populate_snarl_index(
//}

if ( (temp_snarl_record.node_count > size_limit || size_limit == 0) && (temp_snarl_record.is_root_snarl || (!start_is_tip &&
!start_rank == 0 && ! start_rank == 1))) {
start_rank != 0 && start_rank != 1))) {
//If we don't care about internal distances, and we also are not at a boundary or tip
//TODO: Why do we care about tips specifically?
continue;
}

Expand Down Expand Up @@ -1213,7 +1211,23 @@ void populate_snarl_index(
#endif
graph->follow_edges(current_end_handle, false, [&](const handle_t next_handle) {
if (graph->get_id(current_end_handle) == graph->get_id(next_handle)){
//If there are any loops then this isn't a simple snarl
//If this loops onto the same node side then this isn't a simple snarl
temp_snarl_record.is_simple = false;
} else if ((current_index.first == SnarlDistanceIndex::TEMP_NODE ? current_index.second
: (current_rev ? temp_index.temp_chain_records[current_index.second].end_node_id
: temp_index.temp_chain_records[current_index.second].start_node_id))
== graph->get_id(next_handle)){
//If this loops to the other end of the chain then this isn't a simple snarl
temp_snarl_record.is_simple = false;
} else if (!temp_snarl_record.is_root_snarl && start_rank == 0 &&
current_index != start_index && graph->get_id(next_handle) != temp_snarl_record.end_node_id) {
//If the starting point of this traversal was the start of the snarl, the current starting point is not the start node,
//and we found another child, then this is not a simple snarl
temp_snarl_record.is_simple = false;
} else if (!temp_snarl_record.is_root_snarl && start_rank == 1 &&
current_index != start_index && graph->get_id(next_handle) != temp_snarl_record.start_node_id) {
//If the starting point of this traversal was the end of the snarl, the current starting point is not the end node,
//and we found another child, then this is not a simple snarl
temp_snarl_record.is_simple = false;
}

Expand Down Expand Up @@ -1328,7 +1342,7 @@ void populate_snarl_index(
}
} else if (!next_is_boundary && !temp_snarl_record.distances.count(make_pair(start, next))) {
//Otherwise the snarl stores it in its distance
//If the distance isn't from an internal node to a bound and we haven't stored the distance yets
//If the distance isn't from an internal node to a bound and we haven't stored the distance yet

temp_snarl_record.distances[make_pair(start, next)] = current_distance;
added_new_distance = true;
Expand Down Expand Up @@ -1436,14 +1450,10 @@ void populate_snarl_index(
}
}

//If we aren't keeping track of distances, then we didn't actually go through the snarl so we don't know if the snarl was simple or not
if (size_limit == 0) {
temp_snarl_record.is_simple = false;
}

//If this is a simple snarl (one with only single nodes that connect to the start and end nodes), then
// we want to remember if the child nodes are reversed
if (size_limit != 0 && temp_snarl_record.is_simple) {
if (temp_snarl_record.is_simple) {
for (size_t i = 0 ; i < temp_snarl_record.node_count ; i++) {
//Get the index of the child
const pair<SnarlDistanceIndex::temp_record_t, size_t>& child_index = temp_snarl_record.children[i];
Expand Down
9 changes: 8 additions & 1 deletion src/unittest/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ namespace vg {

for (auto& id : {n1->id(), n2->id(), n3->id(), n4->id(), n5->id(), n6->id(), n7->id(), n8->id(), n9->id(), n10->id(), n11->id(), n12->id(), n13->id()}) {
net_handle_t n = distance_index.get_node_net_handle(id);
distance_index.get_parent(n);
net_handle_t parent = distance_index.get_parent(n);
try {
distance_index.minimum_length(n);
distance_index.minimum_length(parent);
REQUIRE(false);
} catch (const std::runtime_error& err) {
REQUIRE(true);
}
}
}
}
Expand Down

1 comment on commit cd71bf9

@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 merge to master. View the full report here.

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

Please sign in to comment.