kaori
A C++ library for barcode extraction and matching
Loading...
Searching...
No Matches
DualBarcodesPairedEndWithDiagnostics.hpp
Go to the documentation of this file.
1#ifndef KAORI_DUAL_BARCODES_PAIRED_END_WITH_DIAGNOSTICS_HPP
2#define KAORI_DUAL_BARCODES_PAIRED_END_WITH_DIAGNOSTICS_HPP
3
6#include "../utils.hpp"
7
14namespace kaori {
15
25template<SeqLength max_size_>
27public:
44 const char* template_seq1, SeqLength template_length1, const BarcodePool& barcode_pool1,
45 const char* template_seq2, SeqLength template_length2, const BarcodePool& barcode_pool2,
46 const typename DualBarcodesPairedEnd<max_size_>::Options& options
47 ) :
48 my_dual_handler(
49 template_seq1,
50 template_length1,
51 barcode_pool1,
52 template_seq2,
53 template_length2,
54 barcode_pool2,
55 options
56 ),
57 my_combo_handler(
58 template_seq1,
59 template_length1,
60 barcode_pool1,
61 template_seq2,
62 template_length2,
63 barcode_pool2,
64 [&]{
65 typename CombinatorialBarcodesPairedEnd<max_size_>::Options combopt;
66 combopt.use_first = options.use_first;
67
68 combopt.max_mismatches1 = options.max_mismatches1;
69 combopt.strand1 = options.strand1;
70 combopt.max_mismatches2 = options.max_mismatches2;
71 combopt.strand2 = options.strand2;
72
73 // we allow duplicates in the trie for each individual barcode, as only the pairs are unique in the dual barcode setup.
74 combopt.duplicates = DuplicateAction::FIRST;
75 combopt.random = options.random;
76 return combopt;
77 }()
78 )
79 {}
80
81private:
82 DualBarcodesPairedEnd<max_size_> my_dual_handler;
83 CombinatorialBarcodesPairedEnd<max_size_> my_combo_handler;
84
85public:
89 struct State {
90 State() {}
91 State(typename DualBarcodesPairedEnd<max_size_>::State ds, typename CombinatorialBarcodesPairedEnd<max_size_>::State cs) : dual_state(std::move(ds)), combo_state(std::move(cs)) {}
92
96 typename DualBarcodesPairedEnd<max_size_>::State dual_state;
97 typename CombinatorialBarcodesPairedEnd<max_size_>::State combo_state;
101 };
102
103 State initialize() const {
104 return State(my_dual_handler.initialize(), my_combo_handler.initialize());
105 }
106
107 void reduce(State& s) {
108 my_dual_handler.reduce(s.dual_state);
109 my_combo_handler.reduce(s.combo_state);
110 }
111
112 constexpr static bool use_names = false;
117public:
121 void process(State& state, const std::pair<const char*, const char*>& r1, const std::pair<const char*, const char*>& r2) const {
122 // Only searching for combinations if we couldn't find a proper dual barcode match.
123 if (!my_dual_handler.process(state.dual_state, r1, r2)) {
124 my_combo_handler.process(state.combo_state, r1, r2);
125 }
126 }
131public:
137 const std::vector<Count>& get_counts() const {
138 return my_dual_handler.get_counts();
139 }
140
145 const std::unordered_map<std::array<BarcodeIndex, 2>, Count, CombinationHash<2> >& get_combinations() const {
146 return my_combo_handler.get_combinations();
147 }
148
152 Count get_total() const {
153 return my_dual_handler.get_total();
154 }
155
160 return my_combo_handler.get_barcode1_only();
161 }
162
167 return my_combo_handler.get_barcode2_only();
168 }
169};
170
174// Soft-deprecated back-compatible aliases.
175template<SeqLength max_size_>
176using DualBarcodesWithDiagnostics = DualBarcodesPairedEndWithDiagnostics<max_size_>;
181}
182
183#endif
Process paired-end combinatorial barcodes.
Process dual barcodes.
Pool of barcode sequences.
Definition BarcodePool.hpp:24
Hash a combination of barcode indices.
Definition utils.hpp:286
Handler for dual barcodes with extra diagnostics.
Definition DualBarcodesPairedEndWithDiagnostics.hpp:26
DualBarcodesPairedEndWithDiagnostics(const char *template_seq1, SeqLength template_length1, const BarcodePool &barcode_pool1, const char *template_seq2, SeqLength template_length2, const BarcodePool &barcode_pool2, const typename DualBarcodesPairedEnd< max_size_ >::Options &options)
Definition DualBarcodesPairedEndWithDiagnostics.hpp:43
Count get_barcode1_only() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:159
Count get_total() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:152
Count get_barcode2_only() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:166
const std::unordered_map< std::array< BarcodeIndex, 2 >, Count, CombinationHash< 2 > > & get_combinations() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:145
const std::vector< Count > & get_counts() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:137
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 DualBarcodesPairedEnd.
Definition DualBarcodesPairedEnd.hpp:32
SearchStrand strand2
Definition DualBarcodesPairedEnd.hpp:59
int max_mismatches1
Definition DualBarcodesPairedEnd.hpp:42
bool use_first
Definition DualBarcodesPairedEnd.hpp:37
SearchStrand strand1
Definition DualBarcodesPairedEnd.hpp:48
bool random
Definition DualBarcodesPairedEnd.hpp:71
int max_mismatches2
Definition DualBarcodesPairedEnd.hpp:53
Utilites for sequence matching.