Skip to content

Commit

Permalink
Merge pull request #4361 from vgteam/stable-extension-queue
Browse files Browse the repository at this point in the history
Add insertion number to make gapless extension queue order stable
  • Loading branch information
adamnovak authored Jul 30, 2024
2 parents 9e095dc + 610c061 commit 4b501c6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/gbwt_extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,12 @@ std::vector<GaplessExtension> GaplessExtender::extend(cluster_type& cluster, std
};

// Match the initial node and add it to the queue.
std::priority_queue<GaplessExtension> extensions;
std::priority_queue<std::pair<GaplessExtension, size_t>> extensions;
// Each extension gets a unique deduplicating number to break score
// ties and make the queue order stable across different backing STL
// implementations.
size_t extension_number = 0;

{
size_t read_offset = get_read_offset(seed);
size_t node_offset = get_node_offset(seed);
Expand All @@ -572,13 +577,13 @@ std::vector<GaplessExtension> GaplessExtender::extend(cluster_type& cluster, std
match.right_maximal = true;
}
set_score(match, this->aligner);
extensions.push(std::move(match));
extensions.emplace(std::move(match), extension_number++);
}

// Extend the most promising extensions first, using alignment scores for priority.
// First make the extension right-maximal and then left-maximal.
while (!extensions.empty()) {
GaplessExtension curr = std::move(extensions.top());
GaplessExtension curr = std::move(extensions.top().first);
extensions.pop();

// Case 1: Extend to the right.
Expand Down Expand Up @@ -612,15 +617,15 @@ std::vector<GaplessExtension> GaplessExtender::extend(cluster_type& cluster, std
}
set_score(next, this->aligner);
num_extensions += next.state.size();
extensions.push(std::move(next));
extensions.emplace(std::move(next), extension_number++);
return true;
});
// We could not extend all threads in 'curr' to the right. The unextended ones
// may have different left extensions, so we must consider 'curr' right-maximal.
if (num_extensions < curr.state.size()) {
curr.right_maximal = true;
curr.old_score = curr.internal_score;
extensions.push(std::move(curr));
extensions.emplace(std::move(curr), extension_number++);
}
continue;
}
Expand Down Expand Up @@ -656,7 +661,7 @@ std::vector<GaplessExtension> GaplessExtender::extend(cluster_type& cluster, std
// No need to set old_score.
}
set_score(next, this->aligner);
extensions.push(std::move(next));
extensions.emplace(std::move(next), extension_number++);
found_extension = true;
return true;
});
Expand Down

1 comment on commit 4b501c6

@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 17208 seconds

Please sign in to comment.