Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distanceless index #4454

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading