1#ifndef KAORI_SIMPLE_SINGLE_MATCH_HPP
2#define KAORI_SIMPLE_SINGLE_MATCH_HPP
10#include <unordered_map>
30template<
size_t max_size>
50 SearchStrand
strand = SearchStrand::FORWARD;
62 const char* template_seq,
63 size_t template_length,
67 num_options(barcode_pool.pool.size()),
68 forward(search_forward(options.strand)),
69 reverse(search_reverse(options.strand)),
70 max_mm(options.max_mismatches),
71 constant(template_seq, template_length, options.strand)
74 const auto& regions = constant.variable_regions();
75 if (regions.size() != 1) {
76 throw std::runtime_error(
"expected one variable region in the constant template");
79 size_t var_length = regions[0].second - regions[0].first;
80 if (var_length != barcode_pool.
length) {
81 throw std::runtime_error(
"length of barcode_pool sequences (" + std::to_string(barcode_pool.
length) +
82 ") should be the same as the barcode_pool region (" + std::to_string(var_length) +
")");
161 forward_lib.
reduce(state.forward_details);
164 reverse_lib.
reduce(state.reverse_details);
169 bool has_match(
int obs_mismatches)
const {
170 return (obs_mismatches >= 0 && obs_mismatches <= max_mm);
173 void forward_match(
const char* seq,
const typename ScanTemplate<max_size>::State& details, State& state)
const {
174 auto start = seq + details.position;
175 const auto& range = constant.variable_regions()[0];
176 std::string curseq(start + range.first, start + range.second);
177 forward_lib.
search(curseq, state.forward_details, max_mm - details.forward_mismatches);
180 void reverse_match(
const char* seq,
const typename ScanTemplate<max_size>::State& details, State& state)
const {
181 auto start = seq + details.position;
182 const auto& range = constant.template variable_regions<true>()[0];
183 std::string curseq(start + range.first, start + range.second);
184 reverse_lib.
search(curseq, state.reverse_details, max_mm - details.reverse_mismatches);
201 auto deets = constant.initialize(read_seq, read_length);
212 int total = const_mismatches + x.mismatches;
213 if (total > max_mm) {
221 state.
index = x.index;
226 while (!deets.finished) {
227 constant.next(deets);
229 if (forward && has_match(deets.forward_mismatches)) {
230 forward_match(read_seq, deets, state);
231 if (update(
false, deets.forward_mismatches, state.forward_details)) {
236 if (reverse && has_match(deets.reverse_mismatches)) {
237 reverse_match(read_seq, deets, state);
238 if (update(
true, deets.reverse_mismatches, state.reverse_details)) {
260 auto deets = constant.initialize(read_seq, read_length);
263 int best = max_mm + 1;
270 auto total = x.mismatches + const_mismatches;
272 if (state.
index != x.index) {
276 }
else if (total < best) {
283 state.
index = x.index;
291 while (!deets.finished) {
292 constant.next(deets);
294 if (forward && has_match(deets.forward_mismatches)) {
295 forward_match(read_seq, deets, state);
296 update(
false, deets.forward_mismatches, state.forward_details);
299 if (reverse && has_match(deets.reverse_mismatches)) {
300 reverse_match(read_seq, deets, state);
301 update(
true, deets.reverse_mismatches, state.reverse_details);
310 bool forward, reverse;
Defines the BarcodePool class.
Search for barcode sequences.
Defines the ScanTemplate class.
Scan a read sequence for the template sequence.
Definition ScanTemplate.hpp:37
Search for known barcode sequences.
Definition BarcodeSearch.hpp:105
void search(const std::string &search_seq, State &state) const
Definition BarcodeSearch.hpp:226
void reduce(State &state)
Definition BarcodeSearch.hpp:192
Search for a template with a single variable region.
Definition SimpleSingleMatch.hpp:31
bool search_best(const char *read_seq, size_t read_length, State &state) const
Definition SimpleSingleMatch.hpp:259
State initialize() const
Definition SimpleSingleMatch.hpp:147
void reduce(State &state)
Definition SimpleSingleMatch.hpp:159
bool search_first(const char *read_seq, size_t read_length, State &state) const
Definition SimpleSingleMatch.hpp:200
SimpleSingleMatch(const char *template_seq, size_t template_length, const BarcodePool &barcode_pool, const Options &options)
Definition SimpleSingleMatch.hpp:61
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:13
Pool of barcode sequences for a variable region.
Definition BarcodePool.hpp:21
size_t length
Definition BarcodePool.hpp:59
Optional parameters for SimpleBarcodeSearch.
Definition BarcodeSearch.hpp:110
bool reverse
Definition BarcodeSearch.hpp:119
int max_mismatches
Definition BarcodeSearch.hpp:114
DuplicateAction duplicates
Definition BarcodeSearch.hpp:124
State of the search.
Definition BarcodeSearch.hpp:153
Optional parameters for SimpleSingleMatch.
Definition SimpleSingleMatch.hpp:36
SearchStrand strand
Definition SimpleSingleMatch.hpp:50
int max_mismatches
Definition SimpleSingleMatch.hpp:40
DuplicateAction duplicates
Definition SimpleSingleMatch.hpp:45
State of the search on a read sequence.
Definition SimpleSingleMatch.hpp:103
int variable_mismatches
Definition SimpleSingleMatch.hpp:126
int index
Definition SimpleSingleMatch.hpp:108
bool reverse
Definition SimpleSingleMatch.hpp:131
size_t position
Definition SimpleSingleMatch.hpp:114
int mismatches
Definition SimpleSingleMatch.hpp:120