kaori
A C++ library for barcode extraction and matching
Loading...
Searching...
No Matches
DualBarcodesSingleEndWithDiagnostics.hpp
Go to the documentation of this file.
1#ifndef KAORI_DUAL_BARCODES_SINGLE_END_WITH_DIAGNOSTICS_HPP
2#define KAORI_DUAL_BARCODES_SINGLE_END_WITH_DIAGNOSTICS_HPP
3
6#include "../utils.hpp"
7
14namespace kaori {
15
25template<SeqLength max_size_, int num_variable_>
27public:
38 const char* template_seq,
39 SeqLength template_length,
40 const std::vector<BarcodePool>& barcode_pools,
41 const typename DualBarcodesSingleEnd<max_size_>::Options& options
42 ) :
43 my_dual_handler(
44 template_seq,
45 template_length,
46 barcode_pools,
47 options
48 ),
49 my_combo_handler(
50 template_seq,
51 template_length,
52 barcode_pools,
53 [&]{
55 combopt.use_first = options.use_first;
56
57 combopt.max_mismatches = options.max_mismatches;
58 combopt.strand = options.strand;
59
60 // we allow duplicates in the trie for each individual barcode, as only the combinations are unique in the dual barcode setup.
61 combopt.duplicates = DuplicateAction::FIRST;
62 return combopt;
63 }()
64 )
65 {}
66
67private:
68 DualBarcodesSingleEnd<max_size_> my_dual_handler;
69 CombinatorialBarcodesSingleEnd<max_size_, num_variable_> my_combo_handler;
70
71public:
75 struct State {
76 State() {}
77 State(typename DualBarcodesSingleEnd<max_size_>::State ds, typename CombinatorialBarcodesSingleEnd<max_size_, num_variable_>::State cs) :
78 dual_state(std::move(ds)), combo_state(std::move(cs)) {}
79
83 typename DualBarcodesSingleEnd<max_size_>::State dual_state;
84 typename CombinatorialBarcodesSingleEnd<max_size_, num_variable_>::State combo_state;
88 };
89
90 State initialize() const {
91 return State(my_dual_handler.initialize(), my_combo_handler.initialize());
92 }
93
94 void reduce(State& s) {
95 my_dual_handler.reduce(s.dual_state);
96 my_combo_handler.reduce(s.combo_state);
97 }
98
99 constexpr static bool use_names = false;
104public:
108 void process(State& state, const std::pair<const char*, const char*>& x) const {
109 // Only searching for combinations if we couldn't find a proper dual barcode match.
110 if (!my_dual_handler.process(state.dual_state, x)) {
111 my_combo_handler.process(state.combo_state, x);
112 }
113 }
118public:
124 const std::vector<Count>& get_counts() const {
125 return my_dual_handler.get_counts();
126 }
127
132 const std::unordered_map<std::array<BarcodeIndex, num_variable_>, Count, CombinationHash<num_variable_> >& get_combinations() const {
133 return my_combo_handler.get_combinations();
134 }
135
139 Count get_total() const {
140 return my_dual_handler.get_total();
141 }
142};
143
144}
145
146#endif
Process single-end combinatorial barcodes.
Process single-end dual barcodes.
Hash a combination of barcode indices.
Definition utils.hpp:286
Handler for dual barcodes with extra diagnostics.
Definition DualBarcodesSingleEndWithDiagnostics.hpp:26
DualBarcodesSingleEndWithDiagnostics(const char *template_seq, SeqLength template_length, const std::vector< BarcodePool > &barcode_pools, const typename DualBarcodesSingleEnd< max_size_ >::Options &options)
Definition DualBarcodesSingleEndWithDiagnostics.hpp:37
Count get_total() const
Definition DualBarcodesSingleEndWithDiagnostics.hpp:139
const std::unordered_map< std::array< BarcodeIndex, num_variable_ >, Count, CombinationHash< num_variable_ > > & get_combinations() const
Definition DualBarcodesSingleEndWithDiagnostics.hpp:132
const std::vector< Count > & get_counts() const
Definition DualBarcodesSingleEndWithDiagnostics.hpp:124
Namespace for the kaori barcode-matching library.
Definition BarcodePool.hpp:16
std::size_t SeqLength
Definition utils.hpp:37
unsigned long long Count
Definition utils.hpp:67
Optional parameters for CombinatorialBarcodeSingleEnd.
Definition CombinatorialBarcodesSingleEnd.hpp:37
bool use_first
Definition CombinatorialBarcodesSingleEnd.hpp:46
DuplicateAction duplicates
Definition CombinatorialBarcodesSingleEnd.hpp:56
SearchStrand strand
Definition CombinatorialBarcodesSingleEnd.hpp:51
int max_mismatches
Definition CombinatorialBarcodesSingleEnd.hpp:41
Optional parameters for DualBarcodeSingleEnd.
Definition DualBarcodesSingleEnd.hpp:36
int max_mismatches
Definition DualBarcodesSingleEnd.hpp:40
bool use_first
Definition DualBarcodesSingleEnd.hpp:45
SearchStrand strand
Definition DualBarcodesSingleEnd.hpp:50
Utilites for sequence matching.