1#ifndef KAORI_SCAN_TEMPLATE_HPP
2#define KAORI_SCAN_TEMPLATE_HPP
36template<
size_t max_size>
39 static constexpr size_t N =
max_size * 4;
60 throw std::runtime_error(
"maximum template size should be " + std::to_string(
max_size) +
" bp");
64 for (
size_t i = 0;
i < length; ++
i) {
68 add_mask_to_hash(forward_mask);
69 forward_mask_ambiguous.set(
i);
73 add_variable_base(forward_variables,
i);
78 for (
size_t i = 0;
i < length; ++
i) {
81 add_variable_base(forward_variables,
i);
87 for (
size_t i = 0;
i < length; ++
i) {
91 add_mask_to_hash(reverse_mask);
92 reverse_mask_ambiguous.set(
i);
96 add_variable_base(reverse_variables,
i);
134 std::bitset<N>
state;
162 for (
size_t i = 0;
i < length - 1; ++
i) {
168 if (
out.any_ambiguous) {
174 if (
out.any_ambiguous) {
177 out.any_ambiguous =
true;
179 out.ambiguous.set(0);
180 out.last_ambiguous =
i;
204 if (
state.any_ambiguous) {
205 state.ambiguous <<= 1;
211 state.any_ambiguous =
false;
218 if (
state.any_ambiguous) {
219 state.ambiguous <<= 1;
221 state.any_ambiguous =
true;
223 state.ambiguous.set(0);
230 state.finished =
true;
237 std::bitset<N> forward_ref, forward_mask;
238 std::bitset<N> reverse_ref, reverse_mask;
241 bool forward, reverse;
243 std::bitset<N/4> forward_mask_ambiguous;
244 std::bitset<N/4> reverse_mask_ambiguous;
246 static void add_mask_to_hash(std::bitset<N>&
current) {
255 static int strand_match(
const State&
match,
const std::bitset<N>&
ref,
const std::bitset<N>&
mask,
const std::bitset<N/4>&
mask_ambiguous) {
263 if (
match.any_ambiguous) {
271 void full_match(State&
match)
const {
273 match.forward_mismatches = strand_match(
match, forward_ref, forward_mask, forward_mask_ambiguous);
276 match.reverse_mismatches = strand_match(
match, reverse_ref, reverse_mask, reverse_mask_ambiguous);
281 std::vector<std::pair<int, int> > forward_variables, reverse_variables;
294 template<
bool reverse = false>
296 if constexpr(reverse) {
297 return reverse_variables;
299 return forward_variables;
304 static void add_variable_base(std::vector<std::pair<int, int> >&
variables,
int i) {
Scan a read sequence for the template sequence.
Definition ScanTemplate.hpp:37
ScanTemplate()
Definition ScanTemplate.hpp:46
void next(State &state) const
Definition ScanTemplate.hpp:198
const std::vector< std::pair< int, int > > & variable_regions() const
Definition ScanTemplate.hpp:295
ScanTemplate(const char *template_seq, size_t template_length, SearchStrand strand)
Definition ScanTemplate.hpp:56
State initialize(const char *read_seq, size_t read_length) const
Definition ScanTemplate.hpp:156
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:13
Details on the current match to the read sequence.
Definition ScanTemplate.hpp:106
size_t position
Definition ScanTemplate.hpp:111
int reverse_mismatches
Definition ScanTemplate.hpp:123
int forward_mismatches
Definition ScanTemplate.hpp:117
bool finished
Definition ScanTemplate.hpp:129