1#ifndef KAORI_SIMPLE_SINGLE_MATCH_HPP
2#define KAORI_SIMPLE_SINGLE_MATCH_HPP
10#include <unordered_map>
30template<SeqLength max_size_>
62 const char* template_seq,
67 my_forward(search_forward(options.strand)),
68 my_reverse(search_reverse(options.strand)),
69 my_max_mm(options.max_mismatches),
70 my_constant(template_seq, template_length, options.strand)
73 const auto& regions = my_constant.forward_variable_regions();
74 if (regions.size() != 1) {
75 throw std::runtime_error(
"expected one variable region in the constant template");
78 SeqLength var_length = regions[0].second - regions[0].first;
79 if (var_length != barcode_pool.
length()) {
80 throw std::runtime_error(
"length of barcode_pool sequences (" + std::to_string(barcode_pool.length()) +
81 ") should be the same as the barcode_pool region (" + std::to_string(var_length) +
")");
86 bs_opt.max_mismatches = my_max_mm;
89 bs_opt.reverse =
false;
93 bs_opt.reverse =
true;
99 bool my_forward, my_reverse;
169 my_forward_lib.
reduce(state.forward_details);
172 my_reverse_lib.
reduce(state.reverse_details);
178 auto start = seq + details.
position;
180 state.buffer.clear();
181 state.buffer.insert(state.buffer.end(), start + range.first, start + range.second);
185 void reverse_match(
const char* seq,
const typename ScanTemplate<max_size_>::State& details, State& state)
const {
186 auto start = seq + details.position;
188 state.buffer.clear();
189 state.buffer.insert(state.buffer.end(), start + range.first, start + range.second);
190 my_reverse_lib.
search(state.buffer, state.reverse_details, my_max_mm - details.reverse_mismatches);
207 auto deets = my_constant.
initialize(read_seq, read_length);
218 int total = const_mismatches + x.mismatches;
219 if (total > my_max_mm) {
227 state.
index = x.index;
232 while (!deets.finished) {
233 my_constant.
next(deets);
235 if (my_forward && deets.forward_mismatches <= my_max_mm) {
236 forward_match(read_seq, deets, state);
237 if (update(
false, deets.forward_mismatches, state.forward_details)) {
242 if (my_reverse && deets.reverse_mismatches <= my_max_mm) {
243 reverse_match(read_seq, deets, state);
244 if (update(
true, deets.reverse_mismatches, state.reverse_details)) {
266 auto deets = my_constant.
initialize(read_seq, read_length);
269 int best = my_max_mm + 1;
276 auto total = x.mismatches + const_mismatches;
278 if (state.
index != x.index) {
282 }
else if (total < best) {
289 state.
index = x.index;
297 while (!deets.finished) {
298 my_constant.
next(deets);
300 if (my_forward && deets.forward_mismatches <= my_max_mm) {
301 forward_match(read_seq, deets, state);
302 update(
false, deets.forward_mismatches, state.forward_details);
305 if (my_reverse && deets.reverse_mismatches <= my_max_mm) {
306 reverse_match(read_seq, deets, state);
307 update(
true, deets.reverse_mismatches, state.reverse_details);
Defines the BarcodePool class.
Search for barcode sequences.
Defines the ScanTemplate class.
Pool of barcode sequences.
Definition BarcodePool.hpp:24
SeqLength length() const
Definition BarcodePool.hpp:70
Scan a read sequence for the template sequence.
Definition ScanTemplate.hpp:38
State initialize(const char *read_seq, SeqLength read_length) const
Definition ScanTemplate.hpp:159
const std::vector< std::pair< SeqLength, SeqLength > > & forward_variable_regions() const
Definition ScanTemplate.hpp:291
void next(State &state) const
Definition ScanTemplate.hpp:201
const std::vector< std::pair< SeqLength, SeqLength > > & reverse_variable_regions() const
Definition ScanTemplate.hpp:300
Search against known barcodes.
Definition BarcodeSearch.hpp:70
void search(const std::string &search_seq, State &state) const
Definition BarcodeSearch.hpp:185
void reduce(State &state)
Definition BarcodeSearch.hpp:170
Search for a template with a single variable region.
Definition SimpleSingleMatch.hpp:31
void reduce(State &state)
Definition SimpleSingleMatch.hpp:167
bool search_best(const char *read_seq, SeqLength read_length, State &state) const
Definition SimpleSingleMatch.hpp:265
bool search_first(const char *read_seq, SeqLength read_length, State &state) const
Definition SimpleSingleMatch.hpp:206
SimpleSingleMatch(const char *template_seq, SeqLength template_length, const BarcodePool &barcode_pool, const Options &options)
Definition SimpleSingleMatch.hpp:61
State initialize() const
Definition SimpleSingleMatch.hpp:156
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:16
std::size_t SeqLength
Definition utils.hpp:37
constexpr BarcodeIndex STATUS_AMBIGUOUS
Definition utils.hpp:53
SearchStrand
Definition utils.hpp:31
constexpr BarcodeIndex STATUS_UNMATCHED
Definition utils.hpp:48
DuplicateAction
Definition utils.hpp:26
bool is_barcode_index_ok(BarcodeIndex index)
Definition utils.hpp:60
std::vector< constchar * >::size_type BarcodeIndex
Definition utils.hpp:43
Details on the current match to the read sequence.
Definition ScanTemplate.hpp:109
int forward_mismatches
Definition ScanTemplate.hpp:120
SeqLength position
Definition ScanTemplate.hpp:114
Optional parameters for SimpleBarcodeSearch.
Definition BarcodeSearch.hpp:75
DuplicateAction duplicates
Definition BarcodeSearch.hpp:89
State of the search.
Definition BarcodeSearch.hpp:130
Optional parameters for SimpleSingleMatch.
Definition SimpleSingleMatch.hpp:36
DuplicateAction duplicates
Definition SimpleSingleMatch.hpp:45
int max_mismatches
Definition SimpleSingleMatch.hpp:40
SearchStrand strand
Definition SimpleSingleMatch.hpp:50
State of search().
Definition SimpleSingleMatch.hpp:108
SeqLength position
Definition SimpleSingleMatch.hpp:120
int mismatches
Definition SimpleSingleMatch.hpp:127
bool reverse
Definition SimpleSingleMatch.hpp:139
int variable_mismatches
Definition SimpleSingleMatch.hpp:133
BarcodeIndex index
Definition SimpleSingleMatch.hpp:113
Utilites for sequence matching.