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<size_t max_size>
27public:
45 const char* template_seq1, size_t template_length1, const BarcodePool& barcode_pool1,
46 const char* template_seq2, size_t template_length2, const BarcodePool& barcode_pool2,
47 const typename DualBarcodesPairedEnd<max_size>::Options& options
48 ) :
49 dual_handler(template_seq1, template_length1, barcode_pool1, template_seq2, template_length2, barcode_pool2, options),
50
51 combo_handler(
52 template_seq1,
53 template_length1,
54 barcode_pool1,
55 template_seq2,
56 template_length2,
57 barcode_pool2,
58 [&]{
60 combopt.use_first = options.use_first;
61
62 combopt.max_mismatches1 = options.max_mismatches1;
63 combopt.strand1 = options.strand1;
64 combopt.max_mismatches2 = options.max_mismatches2;
65 combopt.strand2 = options.strand2;
66
67 // we allow duplicates in the trie for each individual barcode, as only the pairs are unique in the dual barcode setup.
68 combopt.duplicates = DuplicateAction::FIRST;
69 combopt.random = options.random;
70 return combopt;
71 }()
72 )
73 {}
74
75private:
76 DualBarcodesPairedEnd<max_size> dual_handler;
77 CombinatorialBarcodesPairedEnd<max_size> combo_handler;
78
79public:
83 struct State {
84 State() {}
85 State(typename DualBarcodesPairedEnd<max_size>::State ds, typename CombinatorialBarcodesPairedEnd<max_size>::State cs) : dual_state(std::move(ds)), combo_state(std::move(cs)) {}
86
90 typename DualBarcodesPairedEnd<max_size>::State dual_state;
91 typename CombinatorialBarcodesPairedEnd<max_size>::State combo_state;
95 };
96
97 State initialize() const {
98 return State(dual_handler.initialize(), combo_handler.initialize());
99 }
100
101 void reduce(State& s) {
102 dual_handler.reduce(s.dual_state);
103 combo_handler.reduce(s.combo_state);
104 }
105
106 constexpr static bool use_names = false;
111public:
115 void process(State& state, const std::pair<const char*, const char*>& r1, const std::pair<const char*, const char*>& r2) const {
116 // Only searching for combinations if we couldn't find a proper dual barcode match.
117 if (!dual_handler.process(state.dual_state, r1, r2)) {
118 combo_handler.process(state.combo_state, r1, r2);
119 }
120 }
125public:
130 void sort() {
131 combo_handler.sort();
132 }
133
139 const std::vector<int>& get_counts() const {
140 return dual_handler.get_counts();
141 }
142
147 const std::vector<std::array<int, 2> >& get_combinations() const {
148 return combo_handler.get_combinations();
149 }
150
154 int get_total() const {
155 return dual_handler.get_total();
156 }
157
161 int get_barcode1_only() const {
162 return combo_handler.get_barcode1_only();
163 }
164
168 int get_barcode2_only() const {
169 return combo_handler.get_barcode2_only();
170 }
171};
172
176// Soft-deprecated back-compatible aliases.
177template<size_t max_size>
178using DualBarcodesWithDiagnostics = DualBarcodesPairedEndWithDiagnostics<max_size>;
183}
184
185#endif
Process paired-end combinatorial barcodes.
Process dual barcodes.
Handler for paired-end combinatorial barcodes.
Definition CombinatorialBarcodesPairedEnd.hpp:29
Handler for dual barcodes with extra diagnostics.
Definition DualBarcodesPairedEndWithDiagnostics.hpp:26
const std::vector< std::array< int, 2 > > & get_combinations() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:147
const std::vector< int > & get_counts() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:139
DualBarcodesPairedEndWithDiagnostics(const char *template_seq1, size_t template_length1, const BarcodePool &barcode_pool1, const char *template_seq2, size_t template_length2, const BarcodePool &barcode_pool2, const typename DualBarcodesPairedEnd< max_size >::Options &options)
Definition DualBarcodesPairedEndWithDiagnostics.hpp:44
int get_barcode2_only() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:168
void sort()
Definition DualBarcodesPairedEndWithDiagnostics.hpp:130
int get_barcode1_only() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:161
int get_total() const
Definition DualBarcodesPairedEndWithDiagnostics.hpp:154
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 DualBarcodesPairedEnd.
Definition DualBarcodesPairedEnd.hpp:32
int max_mismatches1
Definition DualBarcodesPairedEnd.hpp:42
bool random
Definition DualBarcodesPairedEnd.hpp:71
int max_mismatches2
Definition DualBarcodesPairedEnd.hpp:53
SearchStrand strand2
Definition DualBarcodesPairedEnd.hpp:59
bool use_first
Definition DualBarcodesPairedEnd.hpp:37
SearchStrand strand1
Definition DualBarcodesPairedEnd.hpp:48