Skip to content

Commit

Permalink
Merge pull request #4446 from xchang1/distanceless-distance-index
Browse files Browse the repository at this point in the history
Speed up building the distance index without distances
  • Loading branch information
xchang1 authored Nov 19, 2024
2 parents 62ccb55 + 87df7fc commit c9e7e2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ SnarlDistanceIndex::TemporaryDistanceIndex make_temporary_distance_index(
temp_snarl_record.node_count = temp_snarl_record.children.size();
}


/*Now go through the decomposition again to fill in the distances
* This traverses all chains in reverse order that we found them in, so bottom up
* Each chain and snarl already knows its parents and children, except for single nodes
Expand Down Expand Up @@ -1071,6 +1072,9 @@ 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 @@ -1432,9 +1436,14 @@ 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 (temp_snarl_record.is_simple) {
if (size_limit != 0 && 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
16 changes: 15 additions & 1 deletion src/unittest/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace vg {
REQUIRE(std::get<2>(traceback.second.back()) == -5);
}
}
TEST_CASE( "Nested chain with loop", "[snarl_distance][bug]" ) {
TEST_CASE( "Nested chain with loop", "[snarl_distance]" ) {

VG graph;

Expand Down Expand Up @@ -263,6 +263,11 @@ namespace vg {
SECTION("Distanceless index") {
SnarlDistanceIndex distance_index;
fill_in_distance_index(&distance_index, &graph, &snarl_finder, 0);

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);
}
}
}
TEST_CASE( "Snarl decomposition can deal with multiple connected components",
Expand Down Expand Up @@ -3216,6 +3221,15 @@ namespace vg {
REQUIRE(distance_index.minimum_distance(
n5->id(), false, 0, n5->id(), true, 0) == std::numeric_limits<size_t>::max());
}
SECTION("Distanceless index") {
SnarlDistanceIndex distance_index;
fill_in_distance_index(&distance_index, &graph, &snarl_finder, 0);

for (auto& id : {n1->id(), n2->id(), n3->id(), n4->id(), n5->id(), n6->id(), n7->id(), n8->id()}) {
net_handle_t n = distance_index.get_node_net_handle(id);
distance_index.get_parent(n);
}
}

}

Expand Down

1 comment on commit c9e7e2b

@adamnovak
Copy link
Member

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 17310 seconds

Please sign in to comment.