Skip to content

Commit

Permalink
make parser global
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusta committed Dec 9, 2024
1 parent 9078a65 commit d5d6221
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 16 additions & 7 deletions metagraph/src/graph/representation/hash/dbg_sshash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <type_traits>

#include <query/streaming_query_regular_parsing.hpp>

#include "common/seq_tools/reverse_complement.hpp"
#include "common/threads/threading.hpp"
#include "common/logger.hpp"
Expand Down Expand Up @@ -86,7 +84,11 @@ DBGSSHash::DBGSSHash(const std::string &input_filename, size_t k, Mode mode, siz
orig_state.copyfmt(std::cout);
if (!common::get_verbose())
std::cout.setstate(std::ios_base::failbit);
std::visit([&](auto &d) { d.build(input_filename, build_config); }, dict_);
std::visit([&](auto &d) {
d.build(input_filename, build_config);
using kmer_t = get_kmer_t<decltype(d)>;
parser_ = sshash::streaming_query_regular_parsing<kmer_t>(&d);
}, dict_);
if (!common::get_verbose())
std::cout.copyfmt(orig_state);

Expand Down Expand Up @@ -122,9 +124,10 @@ void map_to_nodes_with_rc_impl(size_t k,
using kmer_t = get_kmer_t<Dict>;

if (with_rc) {
sshash::streaming_query_regular_parsing<kmer_t> parser(&dict);
for (size_t i = 0; i + k <= sequence.size(); ++i) {
callback(parser.lookup_advanced(sequence.data() + i));
std::visit([&](const auto &p) {
callback(p.lookup_advanced(sequence.data() + i));
}, parser_);
}
} else {
std::vector<bool> invalid_char(n);
Expand Down Expand Up @@ -406,8 +409,14 @@ bool DBGSSHash::load(std::istream &in) {
*this = DBGSSHash(k, mode);
num_nodes_ = num_nodes;

if (num_nodes_)
std::visit([&](auto &d) { d.visit(loader); }, dict_);
if (num_nodes_) {
std::visit([&](auto &d) {
d.visit(loader);

using kmer_t = get_kmer_t<decltype(d)>;
parser_ = sshash::streaming_query_regular_parsing<kmer_t>(&d);
}, dict_);
}

return true;
}
Expand Down
8 changes: 8 additions & 0 deletions metagraph/src/graph/representation/hash/dbg_sshash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <dictionary.hpp>
#include <sdsl/uint256_t.hpp>

#include <query/streaming_query_regular_parsing.hpp>

#include "graph/representation/base/sequence_graph.hpp"

namespace mtg::graph {
Expand Down Expand Up @@ -117,6 +119,12 @@ class DBGSSHash : public DeBruijnGraph {
size_t num_nodes_;
Mode mode_;

using parser_t = std::variant<
sshash::streaming_query_regular_parsing<kmer_t<KmerInt64>>,
sshash::streaming_query_regular_parsing<kmer_t<KmerInt128>>,
sshash::streaming_query_regular_parsing<kmer_t<KmerInt256>>>;
static parser_t parser_;

size_t dict_size() const;
};

Expand Down

0 comments on commit d5d6221

Please sign in to comment.