kaori
A C++ library for barcode extraction and matching
Loading...
Searching...
No Matches
SingleBarcodeSingleEnd.hpp
Go to the documentation of this file.
1#ifndef KAORI_SINGLE_BARCODE_SINGLE_END_HPP
2#define KAORI_SINGLE_BARCODE_SINGLE_END_HPP
3
5#include <vector>
6
13namespace kaori {
14
24template<SeqLength max_size_>
26public:
30 struct Options {
35
40 bool use_first = true;
41
45 SearchStrand strand = SearchStrand::FORWARD;
46
50 DuplicateAction duplicates = DuplicateAction::ERROR;
51 };
52
53public:
62 SingleBarcodeSingleEnd(const char* template_seq, SeqLength template_length, const BarcodePool& barcode_pool, const Options& options) :
63 my_matcher(
64 template_seq,
65 template_length,
66 barcode_pool,
67 [&]{
69 ssopt.strand = options.strand;
70 ssopt.max_mismatches = options.max_mismatches;
71 ssopt.duplicates = options.duplicates;
72 return ssopt;
73 }()
74 ),
75 my_counts(barcode_pool.size()),
76 my_use_first(options.use_first)
77 {}
78
79public:
83 struct State {
84 State() = default;
85 State(typename SimpleSingleMatch<max_size_>::State s, typename std::vector<Count>::size_type nvar) : search(std::move(s)), counts(nvar) {}
86
87 typename SimpleSingleMatch<max_size_>::State search;
88 std::vector<Count> counts;
89 Count total = 0;
90 };
91
92 void process(State& state, const std::pair<const char*, const char*>& x) const {
93 bool found = false;
94 if (my_use_first) {
95 found = my_matcher.search_first(x.first, x.second - x.first, state.search);
96 } else {
97 found = my_matcher.search_best(x.first, x.second - x.first, state.search);
98 }
99 if (found) {
100 ++(state.counts[state.search.index]);
101 }
102 ++state.total;
103 }
104
105 static constexpr bool use_names = false;
110public:
114 State initialize() const {
115 return State(my_matcher.initialize(), my_counts.size());
116 }
117
118 void reduce(State& s) {
119 my_matcher.reduce(s.search);
120 for (decltype(my_counts.size()) i = 0, end = my_counts.size(); i < end; ++i) {
121 my_counts[i] += s.counts[i];
122 }
123 my_total += s.total;
124 }
129private:
130 SimpleSingleMatch<max_size_> my_matcher;
131 std::vector<Count> my_counts;
132 Count my_total = 0;
133 bool my_use_first;
134
135public:
140 const std::vector<Count>& get_counts() const {
141 return my_counts;
142 }
143
147 Count get_total() const {
148 return my_total;
149 }
150};
151
152}
153
154#endif
Defines the SimpleSingleMatch class.
Pool of barcode sequences.
Definition BarcodePool.hpp:24
Handler for single-end single barcodes.
Definition SingleBarcodeSingleEnd.hpp:25
const std::vector< Count > & get_counts() const
Definition SingleBarcodeSingleEnd.hpp:140
SingleBarcodeSingleEnd(const char *template_seq, SeqLength template_length, const BarcodePool &barcode_pool, const Options &options)
Definition SingleBarcodeSingleEnd.hpp:62
Count get_total() const
Definition SingleBarcodeSingleEnd.hpp:147
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:16
std::size_t SeqLength
Definition utils.hpp:37
SearchStrand
Definition utils.hpp:31
DuplicateAction
Definition utils.hpp:26
unsigned long long Count
Definition utils.hpp:67
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
Optional parameters for SingleBarcodeSingleEnd.
Definition SingleBarcodeSingleEnd.hpp:30
DuplicateAction duplicates
Definition SingleBarcodeSingleEnd.hpp:50
SearchStrand strand
Definition SingleBarcodeSingleEnd.hpp:45
int max_mismatches
Definition SingleBarcodeSingleEnd.hpp:34
bool use_first
Definition SingleBarcodeSingleEnd.hpp:40