From f3fba777c9e75a7a7b0f6319ee3ddc0157d38544 Mon Sep 17 00:00:00 2001 From: ishmeal Date: Sun, 22 Sep 2024 16:53:04 +0000 Subject: [PATCH 1/2] fixes #39 --- include/digest/digester.hpp | 4 ++-- include/digest/window_minimizer.hpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/digest/digester.hpp b/include/digest/digester.hpp index c0a5470..9491a28 100644 --- a/include/digest/digester.hpp +++ b/include/digest/digester.hpp @@ -207,7 +207,7 @@ template class Digester { * @throws BadConstructionException thrown if the starting position is * greater than the length of the string */ - void new_seq(const char *seq, size_t len, size_t start) { + virtual void new_seq(const char *seq, size_t len, size_t start) { this->seq = seq; this->len = len; this->offset = 0; @@ -231,7 +231,7 @@ template class Digester { * @throws BadConstructionException thrown if the starting position is * greater than the length of the string */ - void new_seq(const std::string &seq, size_t pos) { + virtual void new_seq(const std::string &seq, size_t pos) { new_seq(seq.c_str(), seq.size(), pos); } diff --git a/include/digest/window_minimizer.hpp b/include/digest/window_minimizer.hpp index d3811ce..6dbeef6 100644 --- a/include/digest/window_minimizer.hpp +++ b/include/digest/window_minimizer.hpp @@ -131,6 +131,16 @@ template class WindowMin : public Digester

{ } } + void new_seq(const char *seq, size_t len, size_t start) override { + ds = T(large_window); + Digester

::new_seq(seq, len, start); + } + + void new_seq(const std::string &seq, size_t pos) override { + ds = T(large_window); + Digester

::new_seq(seq.c_str(), seq.size(), pos); + } + /** * * @return unsigned, the value of large_window From 589383e16a7d406903a8cde6ef9b8b28aae30733 Mon Sep 17 00:00:00 2001 From: ishmeal Date: Sun, 22 Sep 2024 16:56:15 +0000 Subject: [PATCH 2/2] format --- include/digest/data_structure.hpp | 4 +- include/digest/window_minimizer.hpp | 10 ++-- pybind/bindings.cpp | 21 ++++--- pybind/digest_utils.hpp | 86 +++++++++++++++-------------- tests/test/test.cpp | 2 +- 5 files changed, 66 insertions(+), 57 deletions(-) diff --git a/include/digest/data_structure.hpp b/include/digest/data_structure.hpp index 9070ba8..34f097b 100644 --- a/include/digest/data_structure.hpp +++ b/include/digest/data_structure.hpp @@ -115,7 +115,7 @@ template struct Naive { std::array arr; unsigned int i = 0; - Naive(uint32_t) {}; + Naive(uint32_t){}; Naive(const Naive &other) = default; Naive &operator=(const Naive &other) = default; @@ -183,7 +183,7 @@ template struct Naive2 { unsigned int last = 0; std::vector arr = std::vector(k); - Naive2(uint32_t) {}; + Naive2(uint32_t){}; Naive2(const Naive2 &other) = default; Naive2 &operator=(const Naive2 &other) = default; diff --git a/include/digest/window_minimizer.hpp b/include/digest/window_minimizer.hpp index 6dbeef6..088f8e1 100644 --- a/include/digest/window_minimizer.hpp +++ b/include/digest/window_minimizer.hpp @@ -149,16 +149,18 @@ template class WindowMin : public Digester

{ // function is mainly to help with tests /** - * @brief gets the size of the internal rmq data structure being used. Mainly used to help with tests (so you probably shouldn't use it). - * + * @brief gets the size of the internal rmq data structure being used. + * Mainly used to help with tests (so you probably shouldn't use it). + * * @return size_t, the size of the internal rmq data structure object */ size_t get_ds_size() { return ds_size; } // function is mainly to help with tests /** - * @brief checks if we have generated the first minimizer. Mainly used to help with tests (so you probably shouldn't use it). - * + * @brief checks if we have generated the first minimizer. Mainly used to + * help with tests (so you probably shouldn't use it). + * * @return bool, if we have already obtained a minimizer */ bool get_is_minimized() { return is_minimized; } diff --git a/pybind/bindings.cpp b/pybind/bindings.cpp index d8820ae..09ec1ad 100644 --- a/pybind/bindings.cpp +++ b/pybind/bindings.cpp @@ -1,15 +1,20 @@ +#include #include #include -#include namespace py = pybind11; PYBIND11_MODULE(Digest, m) { - m.doc() = "bindings for Digest"; - m.def("window_minimizer", &window_minimizer, "A function that runs window minimizer digestion", - py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("include_hash") = false); - m.def("modimizer", &modimizer, "A function that runs mod-minimizer digestion", - py::arg("seq"), py::arg("k") = 31, py::arg("mod") = 100, py::arg("include_hash") = false); - m.def("syncmer", &syncmer, "A function that runs syncmer digestion", - py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("include_hash") = false); + m.doc() = "bindings for Digest"; + m.def("window_minimizer", &window_minimizer, + "A function that runs window minimizer digestion", py::arg("seq"), + py::arg("k") = 31, py::arg("w") = 11, + py::arg("include_hash") = false); + m.def("modimizer", &modimizer, + "A function that runs mod-minimizer digestion", py::arg("seq"), + py::arg("k") = 31, py::arg("mod") = 100, + py::arg("include_hash") = false); + m.def("syncmer", &syncmer, "A function that runs syncmer digestion", + py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, + py::arg("include_hash") = false); } diff --git a/pybind/digest_utils.hpp b/pybind/digest_utils.hpp index 2246f10..f2547ca 100644 --- a/pybind/digest_utils.hpp +++ b/pybind/digest_utils.hpp @@ -1,50 +1,52 @@ -#include -#include #include +#include +#include #include -std::variant, std::vector>> window_minimizer ( - const std::string &seq, unsigned k, unsigned large_window, bool include_hash=false) { - digest::WindowMin digester (seq, k, large_window); - if (include_hash) { - std::vector> output; - digester.roll_minimizer(seq.length(), output); - return output; - } - else { - std::vector output; - digester.roll_minimizer(seq.length(), output); - return output; - } +std::variant, std::vector>> +window_minimizer(const std::string &seq, unsigned k, unsigned large_window, + bool include_hash = false) { + digest::WindowMin + digester(seq, k, large_window); + if (include_hash) { + std::vector> output; + digester.roll_minimizer(seq.length(), output); + return output; + } else { + std::vector output; + digester.roll_minimizer(seq.length(), output); + return output; + } } -//std::vector> output; +// std::vector> output; -std::variant, std::vector>> modimizer ( - const std::string &seq, unsigned k, uint32_t mod, bool include_hash=false) { - digest::ModMin digester (seq, k, mod); - if (include_hash) { - std::vector> output; - digester.roll_minimizer(seq.length(), output); - return output; - } - else { - std::vector output; - digester.roll_minimizer(seq.length(), output); - return output; - } +std::variant, std::vector>> +modimizer(const std::string &seq, unsigned k, uint32_t mod, + bool include_hash = false) { + digest::ModMin digester(seq, k, mod); + if (include_hash) { + std::vector> output; + digester.roll_minimizer(seq.length(), output); + return output; + } else { + std::vector output; + digester.roll_minimizer(seq.length(), output); + return output; + } } -std::variant, std::vector>> syncmer ( - const std::string &seq, unsigned k, unsigned large_window, bool include_hash=false) { - digest::Syncmer digester (seq, k, large_window); - if (include_hash) { - std::vector> output; - digester.roll_minimizer(seq.length(), output); - return output; - } - else { - std::vector output; - digester.roll_minimizer(seq.length(), output); - return output; - } +std::variant, std::vector>> +syncmer(const std::string &seq, unsigned k, unsigned large_window, + bool include_hash = false) { + digest::Syncmer + digester(seq, k, large_window); + if (include_hash) { + std::vector> output; + digester.roll_minimizer(seq.length(), output); + return output; + } else { + std::vector output; + digester.roll_minimizer(seq.length(), output); + return output; + } } \ No newline at end of file diff --git a/tests/test/test.cpp b/tests/test/test.cpp index 00ca8ed..cc1c72b 100644 --- a/tests/test/test.cpp +++ b/tests/test/test.cpp @@ -1246,7 +1246,7 @@ TEST_CASE("ModMin Testing") { { F(digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive, 32) } \ { F(digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive, 33) } \ { F(digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive, 63) } \ - {F(digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive, 64)} + { F(digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive, 64) } TEST_CASE("WindowMin Testing") { SECTION("Constructor Testing") {