From d08995b7c17fccb339eeba4f256c9b70a07840c7 Mon Sep 17 00:00:00 2001 From: faithokamoto Date: Fri, 13 Feb 2026 15:06:04 -0800 Subject: [PATCH 1/4] save tip orientations --- bdsg/include/bdsg/snarl_distance_index.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bdsg/include/bdsg/snarl_distance_index.hpp b/bdsg/include/bdsg/snarl_distance_index.hpp index 9cd60ff2..0770ab9f 100644 --- a/bdsg/include/bdsg/snarl_distance_index.hpp +++ b/bdsg/include/bdsg/snarl_distance_index.hpp @@ -1644,8 +1644,10 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab bool is_tip = false; bool is_root_snarl = false; bool include_distances = true; - vector> children; //All children, nodes and chains, in arbitrary order - unordered_set tippy_child_ranks; //The ranks of children that are tips + //All children, nodes and chains, in arbitrary order + vector> children; + //The ranks & orientations of children that are tips + unordered_map tippy_child_ranks; //vector, pair, size_t>> distances; unordered_map, pair>, size_t> distances; From 37185bff5d303263b13e379281b8206e6982b544 Mon Sep 17 00:00:00 2001 From: faithokamoto Date: Fri, 13 Feb 2026 15:16:44 -0800 Subject: [PATCH 2/4] bump version --- bdsg/include/bdsg/snarl_distance_index.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bdsg/include/bdsg/snarl_distance_index.hpp b/bdsg/include/bdsg/snarl_distance_index.hpp index 0770ab9f..51b5799b 100644 --- a/bdsg/include/bdsg/snarl_distance_index.hpp +++ b/bdsg/include/bdsg/snarl_distance_index.hpp @@ -820,10 +820,10 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab const static size_t MIN_NODE_ID_OFFSET = 4; const static size_t MAX_TREE_DEPTH_OFFSET = 5; - // While the version number is 3, store it in a bit masked way + // While the version number is 4, store it in a bit masked way // to avoid getting confused with old indexes without version numbers // that start with component count - const static size_t CURRENT_VERSION_NUMBER = 3; + const static size_t CURRENT_VERSION_NUMBER = 4; /// Arbitrary large number which doens't overflow the number of bits we give const static size_t VERSION_NUMBER_SENTINEL = (1 << 10) - 1; From d7e4ebb70135ad67e7da45e065fb813c33192a7c Mon Sep 17 00:00:00 2001 From: faithokamoto Date: Fri, 13 Feb 2026 16:09:25 -0800 Subject: [PATCH 3/4] allow prev version --- bdsg/include/bdsg/snarl_distance_index.hpp | 2 ++ bdsg/src/snarl_distance_index.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bdsg/include/bdsg/snarl_distance_index.hpp b/bdsg/include/bdsg/snarl_distance_index.hpp index 51b5799b..f5b7ceb6 100644 --- a/bdsg/include/bdsg/snarl_distance_index.hpp +++ b/bdsg/include/bdsg/snarl_distance_index.hpp @@ -824,6 +824,8 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab // to avoid getting confused with old indexes without version numbers // that start with component count const static size_t CURRENT_VERSION_NUMBER = 4; + // A verion to allow though but warn about + const static size_t WARN_VERSION_NUMBER = 4; /// Arbitrary large number which doens't overflow the number of bits we give const static size_t VERSION_NUMBER_SENTINEL = (1 << 10) - 1; diff --git a/bdsg/src/snarl_distance_index.cpp b/bdsg/src/snarl_distance_index.cpp index 4f71a039..75e44eee 100644 --- a/bdsg/src/snarl_distance_index.cpp +++ b/bdsg/src/snarl_distance_index.cpp @@ -1068,8 +1068,15 @@ void SnarlDistanceIndex::deserialize(int fd) { snarl_tree_records.load(fd, get_prefix()); RootRecord root_record (get_root(), &snarl_tree_records); if (root_record.get_version_number() != CURRENT_VERSION_NUMBER) { - throw runtime_error("error: Trying to load a SnarlDistanceIndex which is not version " + - std::to_string(CURRENT_VERSION_NUMBER) + "; try regenerating the index"); + if (root_record.get_version_number() == WARN_VERSION_NUMBER) { + cerr << "WARNING: loading in a SnarlDistanceIndex which is v" << WARN_VERSION_NUMBER + << " instead of the up-to-date v" << CURRENT_VERSION_NUMBER << endl; + cerr << "Upgrading to the latest version will improve alignments from vg giraffe's chaining mode " << endl + << "(i.e. if long-read alignment from hifi, r10, or also sr-chaining)" << endl; + } else { + throw runtime_error("error: Trying to load a SnarlDistanceIndex which is not version " + + std::to_string(CURRENT_VERSION_NUMBER) + "; try regenerating the index"); + } } } From e74fb663a5f85bc1f76d159b2b3a3691ed85862f Mon Sep 17 00:00:00 2001 From: faithokamoto Date: Mon, 16 Feb 2026 09:06:51 -0800 Subject: [PATCH 4/4] centralized checker --- bdsg/include/bdsg/snarl_distance_index.hpp | 4 ++- bdsg/src/snarl_distance_index.cpp | 29 +++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bdsg/include/bdsg/snarl_distance_index.hpp b/bdsg/include/bdsg/snarl_distance_index.hpp index f5b7ceb6..75c1db7d 100644 --- a/bdsg/include/bdsg/snarl_distance_index.hpp +++ b/bdsg/include/bdsg/snarl_distance_index.hpp @@ -199,6 +199,8 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab void serialize_members(std::ostream& out) const; void deserialize_members(std::istream& in); + /// Call when loading a distance index; will error if wrong version + void check_version_on_load() const; virtual uint32_t get_magic_number() const; std::string get_prefix() const; @@ -825,7 +827,7 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab // that start with component count const static size_t CURRENT_VERSION_NUMBER = 4; // A verion to allow though but warn about - const static size_t WARN_VERSION_NUMBER = 4; + const static size_t WARN_VERSION_NUMBER = 3; /// Arbitrary large number which doens't overflow the number of bits we give const static size_t VERSION_NUMBER_SENTINEL = (1 << 10) - 1; diff --git a/bdsg/src/snarl_distance_index.cpp b/bdsg/src/snarl_distance_index.cpp index 75e44eee..9a27592d 100644 --- a/bdsg/src/snarl_distance_index.cpp +++ b/bdsg/src/snarl_distance_index.cpp @@ -1066,18 +1066,7 @@ void SnarlDistanceIndex::deserialize(int fd) { //This gets called by TriviallySerializable::deserialize(filename), which //doesn't check for the prefix, so this should expect it snarl_tree_records.load(fd, get_prefix()); - RootRecord root_record (get_root(), &snarl_tree_records); - if (root_record.get_version_number() != CURRENT_VERSION_NUMBER) { - if (root_record.get_version_number() == WARN_VERSION_NUMBER) { - cerr << "WARNING: loading in a SnarlDistanceIndex which is v" << WARN_VERSION_NUMBER - << " instead of the up-to-date v" << CURRENT_VERSION_NUMBER << endl; - cerr << "Upgrading to the latest version will improve alignments from vg giraffe's chaining mode " << endl - << "(i.e. if long-read alignment from hifi, r10, or also sr-chaining)" << endl; - } else { - throw runtime_error("error: Trying to load a SnarlDistanceIndex which is not version " + - std::to_string(CURRENT_VERSION_NUMBER) + "; try regenerating the index"); - } - } + check_version_on_load(); } void SnarlDistanceIndex::serialize_members(std::ostream& out) const { @@ -1089,10 +1078,22 @@ void SnarlDistanceIndex::deserialize_members(std::istream& in){ //This gets called by Serializable::deserialize(istream), which has already //read the prefix, so don't expect the prefix snarl_tree_records.load_after_prefix(in, get_prefix()); + check_version_on_load(); +} + +void SnarlDistanceIndex::check_version_on_load() const { RootRecord root_record (get_root(), &snarl_tree_records); if (root_record.get_version_number() != CURRENT_VERSION_NUMBER) { - throw runtime_error("error: Trying to load a SnarlDistanceIndex which is not version " + - std::to_string(CURRENT_VERSION_NUMBER) + "; try regenerating the index"); + if (root_record.get_version_number() == WARN_VERSION_NUMBER) { + cerr << "WARNING: loading in a SnarlDistanceIndex which is v" << WARN_VERSION_NUMBER + << " instead of the up-to-date v" << CURRENT_VERSION_NUMBER << endl; + cerr << "Upgrading to the latest version will improve alignments from vg giraffe's chaining mode " << endl + << "(i.e. if long-read alignment from hifi, r10, or also sr-chaining)" << endl; + } else { + throw runtime_error("error: Trying to load a SnarlDistanceIndex which is v" + + std::to_string(root_record.get_version_number()) + " instead of the up-to-date v" + + std::to_string(CURRENT_VERSION_NUMBER) + "; try regenerating the index"); + } } }