Description: Adapt to vcflib 1.0.12, which moved the canonicalization API to VariantCanonical
 vcflib 1.0.12 (as shipped in openKylin 3.0) moved the canonicalization API out
 of vcflib::Variant into the derived class vcflib::VariantCanonical, declared in
 <vcflib/canonicalize.h>: the data member "canonical" and the methods
 canonicalizable(), canonicalize() and getMaxReferencePos() are no longer
 members of Variant.  vg 1.59.0 uses all of them, so the build fails with
 errors such as
   src/constructor.cpp:178:27: error: 'class vcflib::Variant' has no member
     named 'getMaxReferencePos'
   src/constructor.cpp:778:35: error: 'class vcflib::Variant' has no member
     named 'canonical'
 Use vcflib::VariantCanonical for every variant that gets canonicalized: the
 VcfBuffer now buffers a VariantCanonical and hands out VariantCanonical
 pointers, Constructor::construct_chunk() takes and clumps VariantCanonical
 objects, and the local variants of VCFTraversalFinder::create_variant_index(),
 variant_recall() and the constructor unit tests are VariantCanonical as well.
 The canonical flag of those objects is initialized to false before
 canonicalize() is called, because the member is uninitialized by default and
 canonicalize() asserts that the variant is not canonical yet.
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Origin: vendor
Forwarded: not-needed
Last-Update: 2026-09-16

--- vg-1.59.0+ds.orig/src/constructor.cpp
+++ vg-1.59.0+ds/src/constructor.cpp
@@ -165,7 +165,7 @@ namespace vg {
         }
     }
 
-    pair<int64_t, int64_t> Constructor::get_symbolic_bounds(vcflib::Variant var) {
+    pair<int64_t, int64_t> Constructor::get_symbolic_bounds(vcflib::VariantCanonical var) {
         // TODO: We assume that the variant actually has at least one symbolic alt allele like <INS>.
         // If that is the case, the base at POS must be an anchoring, unmodified base.
         // But you can also have SV tags on something like a CCATG->G right-anchored deletion as long as
@@ -318,7 +318,7 @@ namespace vg {
     }
 
     ConstructedChunk Constructor::construct_chunk(string reference_sequence, string reference_path_name,
-        vector<vcflib::Variant> variants, size_t chunk_offset) const {
+        vector<vcflib::VariantCanonical> variants, size_t chunk_offset) const {
         
         std::stringstream status_stream;
         status_stream << "constructing chunk " << reference_path_name << ":" << chunk_offset << " length " << reference_sequence.size();
@@ -391,7 +391,7 @@ namespace vg {
         auto next_variant = variants.begin();
 
         // We're going to clump overlapping variants together.
-        vector<vcflib::Variant*> clump;
+        vector<vcflib::VariantCanonical*> clump;
         // And we need to rember the highest past-the-end base of anything in the
         // clump, to catch all the overlaps.
         size_t clump_end = 0;
@@ -593,18 +593,18 @@ namespace vg {
                 // This holds a map from Variant pointer to a vector of lists
                 // of VariantAllele edits, one list per non-ref allele of the
                 // variant.
-                map<vcflib::Variant*, vector<list<vcflib::VariantAllele>>> parsed_clump;
+                map<vcflib::VariantCanonical*, vector<list<vcflib::VariantAllele>>> parsed_clump;
 
                 // This determines the order we will process variants in. We use it
                 // to sort variants in a clump by hash for the purposes of assigning
                 // IDs.
-                map<string, vcflib::Variant*> variants_by_name;
+                map<string, vcflib::VariantCanonical*> variants_by_name;
 
                 // This holds the min and max values for the starts and ends of
                 // edits in each variant that are actual change-making edits. These
                 // are in chunk coordinates. They are only populated if a variant
                 // has a variable region. Equal start and end indicate a 1-base region.
-                vector<IntervalTree<int64_t, vcflib::Variant*>::interval> variable_intervals;
+                vector<IntervalTree<int64_t, vcflib::VariantCanonical*>::interval> variable_intervals;
 
                 // This holds the min and max values for starts and ends of edits
                 // not removed from the clump. These are in chunk coordinates.
@@ -614,11 +614,11 @@ namespace vg {
                 // We'll fill this with any variants that should be ignored,
                 // out of the clump. This is better than erasing out of a
                 // vector.
-                set<vcflib::Variant*> skipped;
+                set<vcflib::VariantCanonical*> skipped;
                 
                 for (size_t var_num = 0; var_num < clump.size(); var_num++) {
                     // For each variant in the clump
-                    vcflib::Variant* variant = clump[var_num];
+                    vcflib::VariantCanonical* variant = clump[var_num];
 #ifdef debug
                     cerr << "Handling clump variant " << var_num << "/" << clump.size() << " @ " << variant->zeroBasedPosition() << endl;
 #endif
@@ -856,7 +856,7 @@ namespace vg {
                             #ifdef debug
                             cerr << "Record ref interval of " << bounds.first << " to " << bounds.second << " for " << *variant << endl;
                             #endif
-                            variable_intervals.push_back(IntervalTree<int64_t, vcflib::Variant*>::interval(bounds.first, bounds.second, variant));
+                            variable_intervals.push_back(IntervalTree<int64_t, vcflib::VariantCanonical*>::interval(bounds.first, bounds.second, variant));
                         }
 
                         #ifdef debug
@@ -894,7 +894,7 @@ namespace vg {
                     #pragma omp critical (cerr)
                     {
                         cerr << "error:[vg::Constructor] got improperly bounded region " << first_edit_start << " to " << last_edit_end << " for edits of clump of " << clump.size() << " variants, of which " << skipped.size() << " were skipped." << endl;
-                        for (vcflib::Variant* v : clump) {
+                        for (vcflib::VariantCanonical* v : clump) {
                             if (!skipped.count(v)) {
                                 cerr << "Unskipped variant: " << *v << endl;
                             }
@@ -908,7 +908,7 @@ namespace vg {
                 #endif
 
                 // Index the variants in the clump by the reference region they overlap
-                IntervalTree<int64_t, vcflib::Variant*> variable_interval_tree(std::move(variable_intervals));
+                IntervalTree<int64_t, vcflib::VariantCanonical*> variable_interval_tree(std::move(variable_intervals));
 
                 // Create ref nodes from the end of the last clump (where the cursor
                 // is) to the start of this clump's interior non-ref content.
@@ -925,7 +925,7 @@ namespace vg {
                 // This holds on to variant ref paths, which we can't actually fill
                 // in until all the variants in the clump have had their non-ref
                 // paths done.
-                unordered_map<vcflib::Variant*, Path*> variant_ref_paths;
+                unordered_map<vcflib::VariantCanonical*, Path*> variant_ref_paths;
                 
                 // This holds alt Path pointers and the inversions (start, end)
                 // that they need to trace through in their inverted
@@ -1811,7 +1811,7 @@ namespace vg {
 
         // We maintain a growing list of variants that will go into a chunk. They
         // are all positioned relative to chunk_start.
-        vector<vcflib::Variant> chunk_variants;
+        vector<vcflib::VariantCanonical> chunk_variants;
         // And we track the largest past-the-end position of all the variants
         size_t chunk_end = 0;
 
--- vg-1.59.0+ds.orig/src/constructor.hpp
+++ vg-1.59.0+ds/src/constructor.hpp
@@ -23,6 +23,10 @@
 
 // We need vcflib
 #include <vcflib/Variant.h>
+// vcflib >= 1.0.12 declares the canonicalization API (canonical,
+// canonicalizable(), canonicalize(), getMaxReferencePos()) in
+// vcflib::VariantCanonical from this header.
+#include <vcflib/canonicalize.h>
 // And fastahack
 #include <Fasta.h>
 
@@ -166,7 +170,7 @@ public:
      * variants.
      */
     ConstructedChunk construct_chunk(string reference_sequence, string reference_path_name,
-        vector<vcflib::Variant> variants, size_t chunk_offset) const;
+        vector<vcflib::VariantCanonical> variants, size_t chunk_offset) const;
     
     /**
      * Construct a graph for the given VCF contig name, using the given
@@ -302,7 +306,7 @@ private:
      * their ref and alt fields put in. Note that insertions may have an end
      * bound before their start, because the anchoring base isn't included.
      */
-    static pair<int64_t, int64_t> get_symbolic_bounds(vcflib::Variant var);
+    static pair<int64_t, int64_t> get_symbolic_bounds(vcflib::VariantCanonical var);
     
     /**
      * Given a sequence, get rid of all the lowercase characters and all the
--- vg-1.59.0+ds.orig/src/traversal_finder.cpp
+++ vg-1.59.0+ds/src/traversal_finder.cpp
@@ -4,6 +4,9 @@
 #include "cactus.hpp"
 #include "gbwt_helper.hpp"
 #include "haplotype_extracter.hpp"
+// vcflib >= 1.0.12 provides the canonicalization API through
+// vcflib::VariantCanonical (declared here), not through vcflib::Variant.
+#include <vcflib/canonicalize.h>
 //#define debug
 
 namespace vg {
@@ -2625,7 +2628,9 @@ VCFTraversalFinder::~VCFTraversalFinder(
 void VCFTraversalFinder::create_variant_index(vcflib::VariantCallFile& vcf, FastaReference* ref_fasta,
                                               FastaReference* ins_fasta) {
 
-    vcflib::Variant var;
+    // We need a variant that supports the canonicalization API, so that
+    // symbolic alleles get the same hashes as in vg construct.
+    vcflib::VariantCanonical var;
 #ifdef debug
     cerr << "indexing vcf using alt-path information from graph" << endl;
 #endif
@@ -2645,6 +2650,9 @@ void VCFTraversalFinder::create_variant_
                      << " was given:\n" << var << endl;
                 continue;
             }
+            // The canonical flag starts out uninitialized, and canonicalize()
+            // asserts that the variant is not already canonical.
+            var.canonical = false;
             bool could_canonicalize = var.canonicalize(*ref_fasta, insertion_fastas, true);
             if (!could_canonicalize) {
                 cerr << "[VCFTraversalFinder] Warning: Failed to canonicalize symbolic variant:\n" << var << endl;
--- vg-1.59.0+ds.orig/src/unittest/constructor.cpp
+++ vg-1.59.0+ds/src/unittest/constructor.cpp
@@ -23,7 +23,7 @@ namespace unittest {
 TEST_CASE( "An empty chunk with no variants can be constructed", "[constructor]" ) {
     Constructor constructor;
     
-    auto result = constructor.construct_chunk("", "empty", std::vector<vcflib::Variant>(), 0);
+    auto result = constructor.construct_chunk("", "empty", std::vector<vcflib::VariantCanonical>(), 0);
     
     SECTION("the graph should have no elements") {
         REQUIRE(result.graph.node_size() == 0);
@@ -37,7 +37,7 @@ TEST_CASE( "An empty chunk with no varia
 TEST_CASE( "A small linear chunk with no variants can be constructed", "[constructor]" ) {
     Constructor constructor;
     
-    auto result = constructor.construct_chunk("GATTACA", "movie", std::vector<vcflib::Variant>(), 0);
+    auto result = constructor.construct_chunk("GATTACA", "movie", std::vector<vcflib::VariantCanonical>(), 0);
     
     SECTION("the graph should have one node") {
         REQUIRE(result.graph.node_size() == 1);
@@ -99,7 +99,7 @@ TEST_CASE( "A chunk with lowercase lette
     // Don't warn during testing
     constructor.warn_on_lowercase = false;
     
-    auto result = constructor.construct_chunk("cangantan", "lower", std::vector<vcflib::Variant>(), 0);
+    auto result = constructor.construct_chunk("cangantan", "lower", std::vector<vcflib::VariantCanonical>(), 0);
     
     SECTION("the graph should have one node") {
         REQUIRE(result.graph.node_size() == 1);
@@ -119,7 +119,7 @@ TEST_CASE( "Max node length is respected
     // The reasoning here applies to greedy mode, not old-vg-construct-mimicing mode
     constructor.greedy_pieces = true;
     
-    auto result = constructor.construct_chunk("GATTACA", "movie", std::vector<vcflib::Variant>(), 0);
+    auto result = constructor.construct_chunk("GATTACA", "movie", std::vector<vcflib::VariantCanonical>(), 0);
     
     SECTION("the graph should have two nodes") {
         REQUIRE(result.graph.node_size() == 2);
@@ -213,8 +213,8 @@ static ConstructedChunk construct_test_c
     vcf.open(vcf_stream);
     
     // Fill in this vector of variants
-    std::vector<vcflib::Variant> variants;
-    vcflib::Variant var;
+    std::vector<vcflib::VariantCanonical> variants;
+    vcflib::VariantCanonical var;
     while (vcf.getNextVariant(var)) {
         // Make sure to correct each variant's position to 0-based
         //var.position -= 1;
@@ -831,8 +831,8 @@ ref	5	rs1337	A	G	29	PASS	.	GT
     vcf.open(vcf_stream);
     
     // Fill in this vector of variants
-    std::vector<vcflib::Variant> variants;
-    vcflib::Variant var;
+    std::vector<vcflib::VariantCanonical> variants;
+    vcflib::VariantCanonical var;
     while (vcf.getNextVariant(var)) {
         // Make sure to correct each variant's position to 0-based
         //var.position -= 1;
--- vg-1.59.0+ds.orig/src/variant_recall.cpp
+++ vg-1.59.0+ds/src/variant_recall.cpp
@@ -1,4 +1,7 @@
 #include <cstdint>
+// vcflib >= 1.0.12 provides the canonicalization API through
+// vcflib::VariantCanonical (declared here), not through vcflib::Variant.
+#include <vcflib/canonicalize.h>
 #include "variant_recall.hpp"
 #include "cactus_snarl_finder.hpp"
 #include "traversal_finder.hpp"
@@ -191,11 +194,15 @@ void variant_recall(VG* graph,
         
 
     // For each variant in VCF:
-    vcflib::Variant var;
+    // We need a variant that supports the canonicalization API.
+    vcflib::VariantCanonical var;
     while(vars->getNextVariant(var)){
         // DON'T Adjust the position offset, canonicalize any structural variants,
         // and get the sha1 hash of the variant and store that in a map for later.
         // var.position -= 1;
+        // The canonical flag starts out uninitialized, and canonicalize()
+        // asserts that the variant is not already canonical.
+        var.canonical = false;
         var.canonicalize(*ref_genome, insertions, true, 0);
         string var_id = make_variant_id(var);
 
--- vg-1.59.0+ds.orig/src/vcf_buffer.cpp
+++ vg-1.59.0+ds/src/vcf_buffer.cpp
@@ -10,7 +10,7 @@ namespace vg {
 
 using namespace std;
 
-vcflib::Variant* VcfBuffer::get() {
+vcflib::VariantCanonical* VcfBuffer::get() {
     if(has_buffer) {
         // We have a variant
         return &buffer;
--- vg-1.59.0+ds.orig/src/vcf_buffer.hpp
+++ vg-1.59.0+ds/src/vcf_buffer.hpp
@@ -11,6 +11,12 @@
 
 // We need vcflib
 #include <vcflib/Variant.h>
+// vcflib >= 1.0.12 moved the canonicalization API (canonical,
+// canonicalizable(), canonicalize(), getMaxReferencePos()) out of
+// vcflib::Variant into a separate derived class vcflib::VariantCanonical,
+// which is declared in this header. We buffer variants as VariantCanonical so
+// that the canonicalization flag/methods stay available.
+#include <vcflib/canonicalize.h>
 
 
 namespace vg {
@@ -33,7 +39,7 @@ public:
      * Although the variant is not const, it may not be moved out of or modified
      * in ways that confuse vcflib.
      */
-    vcflib::Variant* get();
+    vcflib::VariantCanonical* get();
     
     /**
      * To be called when the buffer is filled. Marks the buffered variant as
@@ -87,7 +93,7 @@ protected:
     // crash.
     bool safe_to_get = true;
     // This is the actual buffer.
-    vcflib::Variant buffer;
+    vcflib::VariantCanonical buffer;
     // This points to the VariantCallFile we wrap
     // We can wrap the null file (and never have any variants) with a null here.
     vcflib::VariantCallFile* const file;
