37 bool use_first =
true;
42 int max_mismatches1 = 0;
52 int max_mismatches2 = 0;
89 const Options& options
97 opt.
strand = options.strand1;
109 opt.
strand = options.strand2;
115 my_randomized(options.random),
116 my_use_first(options.use_first)
118 my_pool_size[0] = barcode_pool1.size();
119 my_pool_size[1] = barcode_pool2.size();
123 SimpleSingleMatch<max_size_> my_matcher1, my_matcher2;
124 std::array<BarcodeIndex, 2> my_pool_size;
127 bool my_use_first =
true;
129 std::unordered_map<std::array<BarcodeIndex, 2>,
Count, CombinationHash<2> > my_combinations;
131 Count my_barcode1_only = 0;
132 Count my_barcode2_only = 0;
140 State(
typename SimpleSingleMatch<max_size_>::State s1,
typename SimpleSingleMatch<max_size_>::State s2) : search1(std::move(s1)), search2(std::move(s2)) {}
142 std::unordered_map<std::array<BarcodeIndex, 2>,
Count, CombinationHash<2> >collected;
143 Count barcode1_only = 0;
144 Count barcode2_only = 0;
150 typename SimpleSingleMatch<max_size_>::State search1;
151 typename SimpleSingleMatch<max_size_>::State search2;
157 State initialize()
const {
158 return State(my_matcher1.initialize(), my_matcher2.initialize());
161 void reduce(State& s) {
162 my_matcher1.reduce(s.search1);
163 my_matcher2.reduce(s.search2);
164 for (
const auto& col : s.collected) {
165 my_combinations[col.first] += col.second;
168 my_barcode1_only += s.barcode1_only;
169 my_barcode2_only += s.barcode2_only;
172 constexpr static bool use_names =
false;
181 void process(State& state,
const std::pair<const char*, const char*>& r1,
const std::pair<const char*, const char*>& r2)
const {
183 bool m1 = my_matcher1.search_first(r1.first, r1.second - r1.first, state.search1);
184 bool m2 = my_matcher2.search_first(r2.first, r2.second - r2.first, state.search2);
187 std::array<BarcodeIndex, 2> key{ state.search1.index, state.search2.index };
188 ++state.collected[std::move(key)];
189 }
else if (my_randomized) {
190 bool n1 = my_matcher1.search_first(r2.first, r2.second - r2.first, state.search1);
191 bool n2 = my_matcher2.search_first(r1.first, r1.second - r1.first, state.search2);
193 std::array<BarcodeIndex, 2> key{ state.search1.index, state.search2.index };
194 ++state.collected[std::move(key)];
197 ++state.barcode1_only;
198 }
else if (m2 || n2) {
199 ++state.barcode2_only;
204 ++state.barcode1_only;
206 ++state.barcode2_only;
211 bool m1 = my_matcher1.search_best(r1.first, r1.second - r1.first, state.search1);
212 bool m2 = my_matcher2.search_best(r2.first, r2.second - r2.first, state.search2);
214 if (!my_randomized) {
216 std::array<BarcodeIndex, 2> key{ state.search1.index, state.search2.index };
217 ++state.collected[std::move(key)];
219 ++state.barcode1_only;
221 ++state.barcode2_only;
223 }
else if (m1 && m2) {
224 std::array<BarcodeIndex, 2> candidate{ state.search1.index, state.search2.index };
225 int mismatches = state.search1.mismatches + state.search2.mismatches;
227 bool n1 = my_matcher1.search_best(r2.first, r2.second - r2.first, state.search1);
228 bool n2 = my_matcher2.search_best(r1.first, r1.second - r1.first, state.search2);
231 int rmismatches = state.search1.mismatches + state.search2.mismatches;
232 if (mismatches > rmismatches) {
233 std::array<BarcodeIndex, 2> key{ state.search1.index, state.search2.index };
234 ++state.collected[std::move(key)];
235 }
else if (mismatches < rmismatches) {
236 ++state.collected[candidate];
237 }
else if (candidate[0] == state.search1.index && candidate[1] == state.search2.index) {
240 ++state.collected[candidate];
243 ++state.collected[candidate];
246 bool n1 = my_matcher1.search_best(r2.first, r2.second - r2.first, state.search1);
247 bool n2 = my_matcher2.search_best(r1.first, r1.second - r1.first, state.search2);
250 std::array<BarcodeIndex, 2> key{ state.search1.index, state.search2.index };
251 ++state.collected[std::move(key)];
252 }
else if (m1 || n1) {
253 ++state.barcode1_only;
254 }
else if (m2 || n2) {
255 ++state.barcode2_only;
272 return my_combinations;
286 return my_barcode1_only;
293 return my_barcode2_only;