Skip to content
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
16 changes: 11 additions & 5 deletions bdsg/include/bdsg/overlays/reference_path_overlay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ class ReferencePathOverlay : public PathPositionHandleGraph {

public:

/// Create a ReferencePathOverlay indexing all non-hidden paths in the
/// backing graph (which show up in for_each_path_handle()). For path names
/// in extra_path_names, look them up and index them too, even if they are
/// hidden.
ReferencePathOverlay(const PathHandleGraph* graph, const std::unordered_set<std::string>& extra_path_names = {});
/// Create a ReferencePathOverlay indexing paths in the backing graph.
/// If all_paths is true, indexes all paths visible via for_each_path_handle().
/// If false (default), indexes only REFERENCE and GENERIC sense paths.
/// For path names in extra_path_names, look them up and index them too,
/// even if they are hidden.
ReferencePathOverlay(const PathHandleGraph* graph, bool all_paths = false);

/// Same, but also indexes hidden paths listed in extra_path_names.
Comment on lines +49 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't/shouldn't have a concept of a path being "hidden" anymore.

ReferencePathOverlay(const PathHandleGraph* graph,
const std::unordered_set<std::string>& extra_path_names,
bool all_paths = false);
Comment on lines +54 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all_paths is true, extra_path_names can't really be used, because we'll do all paths, since none of them are hidden anymore.

ReferencePathOverlay() = default;
~ReferencePathOverlay() = default;

Expand Down
37 changes: 25 additions & 12 deletions bdsg/src/reference_path_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@ namespace bdsg {
using namespace std;
using namespace handlegraph;

ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, const std::unordered_set<std::string>& extra_path_names) : graph(graph) {

// Get step counts for all paths we want to process, once.
ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, bool all_paths)
: ReferencePathOverlay(graph, std::unordered_set<std::string>{}, all_paths) {
}

ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph,
const std::unordered_set<std::string>& extra_path_names,
bool all_paths) : graph(graph) {

std::unordered_map<path_handle_t, size_t> cached_step_counts;
graph->for_each_path_handle([&](const path_handle_t& path) {
// Find and measure all the non-hidden paths.
// TODO: If we made the overlay transparent so we could access paths
// that didn't get indexed, we wouldn't be weirdly indexing haplotype
// paths from backends that don't hide them in the "reference" path
// overlay.
Comment on lines -22 to -25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now all the backends are like that; I think I forgot to address that here when I made that change.

cached_step_counts[path] = graph->get_step_count(path);
});

if (all_paths) {
// Index ALL visible paths
graph->for_each_path_handle([&](const path_handle_t& path) {
cached_step_counts[path] = graph->get_step_count(path);
return true;
});
} else {
// Only index REFERENCE and GENERIC paths (the default)
std::unordered_set<PathSense> senses = {PathSense::REFERENCE, PathSense::GENERIC};
graph->for_each_path_matching(&senses, nullptr, nullptr, [&](const path_handle_t& path) {
cached_step_counts[path] = graph->get_step_count(path);
return true;
});
}

for (auto& path_name : extra_path_names) {
// Also index hidden paths that the user is asking for by name.
if (graph->has_path(path_name)) {
// The graph actually has this path.
path_handle_t path = graph->get_path_handle(path_name);
auto found = cached_step_counts.find(path);
if (found == cached_step_counts.end()) {
// And it's not already reference sense.
// And it's not already indexed.
// Count steps and remember it
cached_step_counts.emplace_hint(found, path, graph->get_step_count(path));
}
Expand Down