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
4#include "../SimpleSingleMatch.hpp"
5#include <vector>
6
13namespace kaori {
14
24template<size_t 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, size_t template_length, const BarcodePool& barcode_pool, const Options& options) :
63 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 counts(barcode_pool.size()),
76 use_first(options.use_first)
77 {}
78
79public:
83 struct State {
84 State() {}
85
86 State(typename SimpleSingleMatch<max_size>::State s, size_t nvar) : search(std::move(s)), counts(nvar) {}
87
88 typename SimpleSingleMatch<max_size>::State search;
89 std::vector<int> counts;
90 int total = 0;
91 };
92
93 void process(State& state, const std::pair<const char*, const char*>& x) const {
94 bool found = false;
95 if (use_first) {
96 found = matcher.search_first(x.first, x.second - x.first, state.search);
97 } else {
98 found = matcher.search_best(x.first, x.second - x.first, state.search);
99 }
100 if (found) {
101 ++(state.counts[state.search.index]);
102 }
103 ++state.total;
104 }
105
106 static constexpr bool use_names = false;
111public:
115 State initialize() const {
116 return State(matcher.initialize(), counts.size());
117 }
118
119 void reduce(State& s) {
120 matcher.reduce(s.search);
121 for (size_t i = 0; i < counts.size(); ++i) {
122 counts[i] += s.counts[i];
123 }
124 total += s.total;
125 }
130private:
131 SimpleSingleMatch<max_size> matcher;
132 std::vector<int> counts;
133 int total = 0;
134 bool use_first;
135
136public:
141 const std::vector<int>& get_counts() const {
142 return counts;
143 }
144
148 int get_total() const {
149 return total;
150 }
151};
152
153}
154
155#endif
Handler for single-end single barcodes.
Definition SingleBarcodeSingleEnd.hpp:25
const std::vector< int > & get_counts() const
Definition SingleBarcodeSingleEnd.hpp:141
SingleBarcodeSingleEnd(const char *template_seq, size_t template_length, const BarcodePool &barcode_pool, const Options &options)
Definition SingleBarcodeSingleEnd.hpp:62
int get_total() const
Definition SingleBarcodeSingleEnd.hpp:148
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:13
Pool of barcode sequences for a variable region.
Definition BarcodePool.hpp:21
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
Optional parameters for SingleBarcodeSingleEnd.
Definition SingleBarcodeSingleEnd.hpp:30
bool use_first
Definition SingleBarcodeSingleEnd.hpp:40
DuplicateAction duplicates
Definition SingleBarcodeSingleEnd.hpp:50
SearchStrand strand
Definition SingleBarcodeSingleEnd.hpp:45
int max_mismatches
Definition SingleBarcodeSingleEnd.hpp:34