From f11f91138253e9643741e84d5e81abb411288176 Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Sat, 12 Oct 2024 16:22:55 -0500 Subject: [PATCH] feat: Add index file loading to Sketch constructor --- src/map/include/winSketch.hpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/map/include/winSketch.hpp b/src/map/include/winSketch.hpp index fec0ce00..3dd0302f 100644 --- a/src/map/include/winSketch.hpp +++ b/src/map/include/winSketch.hpp @@ -135,13 +135,34 @@ namespace skch */ Sketch(skch::Parameters p, SequenceIdManager& idMgr, - const std::vector& targets = {}) + const std::vector& targets = {}, + const std::string& indexFilename = "") : param(std::move(p)), idManager(idMgr) { - initialize(targets); + if (!indexFilename.empty()) { + loadIndex(indexFilename); + } else { + initialize(targets); + } + } + + void loadIndex(const std::string& indexFilename) { + std::ifstream inStream(indexFilename, std::ios::binary); + if (!inStream) { + std::cerr << "Error: Unable to open index file: " << indexFilename << std::endl; + exit(1); + } + readParameters(inStream); + readSketchBinary(inStream); + readPosListBinary(inStream); + readFreqKmersBinary(inStream); + inStream.close(); + isInitialized = true; + std::cerr << "[mashmap::skch::Sketch] Sketch loaded from index file: " << indexFilename << std::endl; } + public: void initialize(const std::vector& targets = {}) { std::cerr << "[mashmap::skch::Sketch] Initializing Sketch..." << std::endl;