digest
Loading...
Searching...
No Matches
syncmer.hpp
1#ifndef SYNCMER_HPP
2#define SYNCMER_HPP
3
4#include "digest/digester.hpp"
5#include "digest/window_minimizer.hpp"
6
7namespace digest {
8
21template <BadCharPolicy P, class T> class Syncmer : public WindowMin<P, T> {
22 public:
35 Syncmer(const char *seq, size_t len, unsigned k, unsigned large_window,
36 size_t start = 0,
38 : WindowMin<P, T>(seq, len, k, large_window, start, minimized_h) {}
39
51 Syncmer(const std::string &seq, unsigned k, unsigned large_window,
52 size_t start = 0,
54 : Syncmer<P, T>(seq.c_str(), seq.size(), k, large_window, start,
55 minimized_h) {}
56
65 void roll_minimizer(unsigned amount, std::vector<uint32_t> &vec) override {
66 amount += vec.size();
67
68 while (this->ds_size + 1 < this->large_window and this->is_valid_hash) {
70 this->ds.insert(this->get_pos(), this->chash);
71 } else if (this->get_minimized_h() ==
73 this->ds.insert(this->get_pos(), this->fhash);
74 } else {
75 this->ds.insert(this->get_pos(), this->rhash);
76 }
77
78 this->roll_one();
79 this->ds_size++;
80 }
81
82 while (this->is_valid_hash and vec.size() < amount) {
83 Syncmer::roll_ds_sync(vec);
84 }
85 }
86
95 void
96 roll_minimizer(unsigned amount,
97 std::vector<std::pair<uint32_t, uint32_t>> &vec) override {
98 amount += vec.size();
99
100 while (this->ds_size + 1 < this->large_window and this->is_valid_hash) {
102 this->ds.insert(this->get_pos(), this->chash);
103 } else if (this->get_minimized_h() ==
105 this->ds.insert(this->get_pos(), this->fhash);
106 } else {
107 this->ds.insert(this->get_pos(), this->rhash);
108 }
109
110 this->roll_one();
111 this->ds_size++;
112 }
113
114 while (this->is_valid_hash and vec.size() < amount) {
115 Syncmer::roll_ds_sync(vec);
116 }
117 }
118
119 private:
125 void roll_ds_sync(std::vector<uint32_t> &vec) {
127 this->ds.insert(this->get_pos(), this->chash);
128 } else if (this->get_minimized_h() ==
130 this->ds.insert(this->get_pos(), this->fhash);
131 } else {
132 this->ds.insert(this->get_pos(), this->rhash);
133 }
134 this->ds.min_syncmer(vec);
135
136 this->roll_one();
137 }
138
144 void roll_ds_sync(std::vector<std::pair<uint32_t, uint32_t>> &vec) {
146 this->ds.insert(this->get_pos(), this->chash);
147 } else if (this->get_minimized_h() ==
149 this->ds.insert(this->get_pos(), this->fhash);
150 } else {
151 this->ds.insert(this->get_pos(), this->rhash);
152 }
153 this->ds.min_syncmer(vec);
154
155 this->roll_one();
156 }
157};
158
159} // namespace digest
160
161#endif // SYNCMER_HPP
bool roll_one()
moves the internal pointer to the next valid k-mer. Time Complexity: O(1)
Definition digester.hpp:138
MinimizedHashType get_minimized_h()
Definition digester.hpp:289
size_t get_pos()
Definition digester.hpp:177
This class inherits from WindowMinimizer (implementation reasons), but the represent very different t...
Definition syncmer.hpp:21
void roll_minimizer(unsigned amount, std::vector< uint32_t > &vec) override
adds up to amount of positions of syncmers into vec. Here a large window is considered a syncmer if t...
Definition syncmer.hpp:65
Syncmer(const char *seq, size_t len, unsigned k, unsigned large_window, size_t start=0, MinimizedHashType minimized_h=MinimizedHashType::CANON)
Definition syncmer.hpp:35
Syncmer(const std::string &seq, unsigned k, unsigned large_window, size_t start=0, MinimizedHashType minimized_h=MinimizedHashType::CANON)
Definition syncmer.hpp:51
void roll_minimizer(unsigned amount, std::vector< std::pair< uint32_t, uint32_t > > &vec) override
adds up to amount of positions and hashes of syncmers into vec. Here a large window is considered a s...
Definition syncmer.hpp:96
Child class of Digester that defines a minimizer as a kmer whose hash is minimal among those in the l...
Definition window_minimizer.hpp:33
digest code.
Definition data_structure.hpp:27
MinimizedHashType
Enum values for the type of hash to minimize.
Definition digester.hpp:41