From 30c805e28f9095fa977c0da9ed4e3b9aa7ef65d1 Mon Sep 17 00:00:00 2001 From: Glenn Hickey Date: Thu, 5 Feb 2026 14:23:58 -0500 Subject: [PATCH 1/2] dont put haplotypes in ReferencePathOverlays --- bdsg/src/reference_path_overlay.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bdsg/src/reference_path_overlay.cpp b/bdsg/src/reference_path_overlay.cpp index 29404b22..1550ff86 100644 --- a/bdsg/src/reference_path_overlay.cpp +++ b/bdsg/src/reference_path_overlay.cpp @@ -16,14 +16,12 @@ using namespace handlegraph; ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, const std::unordered_set& extra_path_names) : graph(graph) { // Get step counts for all paths we want to process, once. + // Only index REFERENCE and GENERIC paths, not HAPLOTYPE paths. std::unordered_map 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. + std::unordered_set 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. From c075778651956b27f212360bca8cff502b2abfc4 Mon Sep 17 00:00:00 2001 From: Glenn Hickey Date: Thu, 5 Feb 2026 17:34:21 -0500 Subject: [PATCH 2/2] actually we want allow toggling between all / just ref paths --- .../bdsg/overlays/reference_path_overlay.hpp | 16 ++++++--- bdsg/src/reference_path_overlay.cpp | 35 +++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/bdsg/include/bdsg/overlays/reference_path_overlay.hpp b/bdsg/include/bdsg/overlays/reference_path_overlay.hpp index d9547d03..3235634e 100644 --- a/bdsg/include/bdsg/overlays/reference_path_overlay.hpp +++ b/bdsg/include/bdsg/overlays/reference_path_overlay.hpp @@ -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& 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. + ReferencePathOverlay(const PathHandleGraph* graph, + const std::unordered_set& extra_path_names, + bool all_paths = false); ReferencePathOverlay() = default; ~ReferencePathOverlay() = default; diff --git a/bdsg/src/reference_path_overlay.cpp b/bdsg/src/reference_path_overlay.cpp index 1550ff86..2cb8a9fd 100644 --- a/bdsg/src/reference_path_overlay.cpp +++ b/bdsg/src/reference_path_overlay.cpp @@ -13,16 +13,31 @@ namespace bdsg { using namespace std; using namespace handlegraph; -ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, const std::unordered_set& extra_path_names) : graph(graph) { - - // Get step counts for all paths we want to process, once. - // Only index REFERENCE and GENERIC paths, not HAPLOTYPE paths. +ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, bool all_paths) + : ReferencePathOverlay(graph, std::unordered_set{}, all_paths) { +} + +ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, + const std::unordered_set& extra_path_names, + bool all_paths) : graph(graph) { + std::unordered_map cached_step_counts; - std::unordered_set 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; - }); + + 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 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)) { @@ -30,7 +45,7 @@ ReferencePathOverlay::ReferencePathOverlay(const PathHandleGraph* graph, const s 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)); }