From 45a923a3d39a71d6e88775615e279b69f83e118a Mon Sep 17 00:00:00 2001 From: Xian Date: Tue, 12 Nov 2024 21:43:11 +0100 Subject: [PATCH 1/2] Skip doing dijkstras for internal nodes --- src/snarl_distance_index.cpp | 13 +++++++++++-- src/unittest/snarl_distance_index.cpp | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/snarl_distance_index.cpp b/src/snarl_distance_index.cpp index d60cd78035..793f3259c5 100644 --- a/src/snarl_distance_index.cpp +++ b/src/snarl_distance_index.cpp @@ -1,4 +1,4 @@ -//#define debug_distance_indexing +#define debug_distance_indexing //#define debug_snarl_traversal //#define debug_distances //#define debug_subgraph @@ -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 @@ -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); @@ -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& child_index = temp_snarl_record.children[i]; diff --git a/src/unittest/snarl_distance_index.cpp b/src/unittest/snarl_distance_index.cpp index 5067b31040..018cc2e6f9 100644 --- a/src/unittest/snarl_distance_index.cpp +++ b/src/unittest/snarl_distance_index.cpp @@ -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; @@ -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", @@ -3216,6 +3221,15 @@ namespace vg { REQUIRE(distance_index.minimum_distance( n5->id(), false, 0, n5->id(), true, 0) == std::numeric_limits::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); + } + } } From 87df7fc95bfbbd2f18f56a429534b6f17bed7ead Mon Sep 17 00:00:00 2001 From: Xian Date: Tue, 12 Nov 2024 22:27:38 +0100 Subject: [PATCH 2/2] Turn off debug --- src/snarl_distance_index.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snarl_distance_index.cpp b/src/snarl_distance_index.cpp index 793f3259c5..92948f2de3 100644 --- a/src/snarl_distance_index.cpp +++ b/src/snarl_distance_index.cpp @@ -1,4 +1,4 @@ -#define debug_distance_indexing +//#define debug_distance_indexing //#define debug_snarl_traversal //#define debug_distances //#define debug_subgraph