60 my_forward(search_forward(options.strand)),
61 my_reverse(search_reverse(options.strand)),
62 my_constant(template_seq, template_length, options.strand),
63 my_max_mm(options.max_mismatches),
64 my_use_first(options.use_first)
68 std::unordered_map<std::string, Count> my_counts;
71 bool my_forward, my_reverse;
82 State(SeqLength varsize) : buffer(varsize,
' ') {}
84 std::unordered_map<std::string, Count> counts;
89 void forward_match(
const char* seq,
SeqLength position, State& state)
const {
90 auto start = seq + position;
92 std::copy(start + range.first, start + range.second, state.buffer.data());
94 auto it = state.counts.find(state.buffer);
95 if (it != state.counts.end()) {
98 state.counts[state.buffer] = 1;
102 void reverse_match(
const char* seq,
SeqLength position, State& state)
const {
104 auto start = seq + position + range.first;
107 state.buffer[j] = complement_base<true>(start[len - j - 1]);
110 auto it = state.counts.find(state.buffer);
111 if (it != state.counts.end()) {
114 state.counts[state.buffer] = 1;
118 void process(State& state,
const std::pair<const char*, const char*>& x)
const {
119 auto read_seq = x.first;
120 auto deets = my_constant.
initialize(read_seq, x.second - x.first);
123 while (!deets.finished) {
124 my_constant.
next(deets);
125 if (my_forward && deets.forward_mismatches <= my_max_mm) {
126 forward_match(read_seq, deets.position, state);
129 if (my_reverse && deets.reverse_mismatches <= my_max_mm) {
130 reverse_match(read_seq, deets.position, state);
136 int best = my_max_mm + 1;
137 bool best_forward =
true;
139 bool best_tied =
false;
141 while (!deets.finished) {
142 my_constant.
next(deets);
144 if (my_forward && deets.forward_mismatches <= my_max_mm) {
145 if (deets.forward_mismatches < best) {
146 best = deets.forward_mismatches;
147 best_position = deets.position;
150 }
else if (deets.forward_mismatches == best) {
155 if (my_reverse && deets.reverse_mismatches <= my_max_mm) {
156 if (deets.reverse_mismatches < best) {
157 best = deets.reverse_mismatches;
158 best_position = deets.position;
159 best_forward =
false;
161 }
else if (deets.reverse_mismatches == best) {
167 if (!best_tied && best <= my_max_mm) {
169 forward_match(read_seq, best_position, state);
171 reverse_match(read_seq, best_position, state);
179 static constexpr bool use_names =
false;
188 State initialize()
const {
190 return State(range.second - range.first);
193 void reduce(State& s) {
194 for (
const auto& pair : s.counts) {
195 auto it = my_counts.find(pair.first);
196 if (it != my_counts.end()) {
197 it->second += pair.second;
199 my_counts[pair.first] = pair.second;
212 const std::unordered_map<std::string, Count>&
get_counts()
const {