1212
1313#include " misc/debug.hpp"
1414#include " misc/filenames.hpp"
15+ #include " misc/needle_matrix.hpp"
1516#include " misc/read_levels.hpp"
1617
1718inline std::vector<uint64_t > get_minimiser (seqan3::dna4_vector const & seq, minimiser_arguments const & args)
@@ -27,7 +28,7 @@ inline std::vector<uint64_t> get_minimiser(seqan3::dna4_vector const & seq, mini
2728template <typename ibf_t , bool normalization, typename exp_t >
2829void check_ibf (estimate_ibf_arguments const & args,
2930 ibf_t const & ibf,
30- std::vector <uint16_t > & estimations,
31+ std::span <uint16_t > estimations,
3132 seqan3::dna4_vector const & seq,
3233 exp_t const & expressions,
3334 std::vector<std::vector<double >> const & fprs,
@@ -36,7 +37,7 @@ void check_ibf(estimate_ibf_arguments const & args,
3637 size_t const num_experiments)
3738{
3839 // Check, if one expression threshold for all or individual thresholds
39- static constexpr bool multiple_expressions = std::same_as<exp_t , std::vector<std::vector< uint16_t > >>;
40+ static constexpr bool multiple_expressions = std::same_as<exp_t , needle_matrix< uint16_t >>;
4041
4142 std::vector<uint64_t > const minimiser = get_minimiser (seq, args);
4243 uint64_t const minimiser_count = minimiser.size ();
@@ -86,7 +87,7 @@ void check_ibf(estimate_ibf_arguments const & args,
8687 if (level == num_levels - 1 ) // This is the last (lowest) level
8788 {
8889 if constexpr (multiple_expressions)
89- estimations[experiment] = expressions[level][ experiment];
90+ estimations[experiment] = expressions[level, experiment];
9091 else
9192 estimations[experiment] = args.expression_thresholds [level];
9293 }
@@ -102,11 +103,11 @@ void check_ibf(estimate_ibf_arguments const & args,
102103 // Actually calculate estimation, in the else case level stands for the prev_expression
103104 if constexpr (multiple_expressions)
104105 {
105- size_t const prev_level_expression = expressions[level + 1 ][ experiment];
106- size_t const expression_difference = prev_level_expression - expressions[level][ experiment];
106+ size_t const prev_level_expression = expressions[level + 1 , experiment];
107+ size_t const expression_difference = prev_level_expression - expressions[level, experiment];
107108 size_t const estimate =
108109 prev_level_expression - (normalized_minimiser_pos * expression_difference);
109- estimations[experiment] = std::max<size_t >(expressions[level][ experiment], estimate);
110+ estimations[experiment] = std::max<size_t >(expressions[level, experiment], estimate);
110111 }
111112 else
112113 {
@@ -121,7 +122,7 @@ void check_ibf(estimate_ibf_arguments const & args,
121122 // Apply normalization if requested
122123 // TODO: Is this meant to be expressions[0]?
123124 if constexpr (normalization && multiple_expressions)
124- estimations[experiment] /= expressions[1 ][ experiment]; // Normalize by first level
125+ estimations[experiment] /= expressions[1 , experiment]; // Normalize by first level
125126
126127 break ; // Found the estimate for this experiment
127128 }
@@ -149,9 +150,9 @@ void estimate(estimate_ibf_arguments & args,
149150 // ========================================================================
150151 // const data
151152 // ========================================================================
152- std::vector<std::vector< uint16_t > > const expressions = [&]()
153+ needle_matrix< uint16_t > const expressions = [&]()
153154 {
154- std::vector<std::vector< uint16_t > > result;
155+ needle_matrix< uint16_t > result;
155156 if constexpr (samplewise)
156157 read_levels<uint16_t >(result, filenames::levels (estimate_args.path_in ));
157158 return result;
@@ -186,8 +187,8 @@ void estimate(estimate_ibf_arguments & args,
186187 // ========================================================================
187188 std::vector<std::string> ids;
188189 std::vector<seqan3::dna4_vector> seqs;
189- std::vector<std::vector< float > > prev_counts;
190- std::vector<std::vector< uint16_t > > estimations;
190+ needle_matrix< float > prev_counts;
191+ needle_matrix< uint16_t > estimations;
191192 bool counters_initialised = false ;
192193
193194 // ========================================================================
@@ -221,29 +222,17 @@ void estimate(estimate_ibf_arguments & args,
221222 // ========================================================================
222223 auto init_counter = [&](size_t const size)
223224 {
224- static_assert (std::same_as<std::ranges::range_value_t <decltype (prev_counts)>, std::vector<float >>);
225- prev_counts.resize (size, std::vector<float >(num_experiments));
226-
227- static_assert (std::same_as<std::ranges::range_value_t <decltype (estimations)>, std::vector<uint16_t >>);
228- estimations.resize (size, std::vector<uint16_t >(num_experiments));
229-
225+ prev_counts = needle_matrix<float >{size, num_experiments};
226+ estimations = needle_matrix<uint16_t >{size, num_experiments};
230227 return true ;
231228 };
232229
233230 auto clear_data = [&]()
234231 {
235232 ids.clear ();
236233 seqs.clear ();
237- std::ranges::for_each (prev_counts,
238- [](auto & v)
239- {
240- std::ranges::fill (v, float {});
241- });
242- std::ranges::for_each (estimations,
243- [](auto & v)
244- {
245- std::ranges::fill (v, uint16_t {});
246- });
234+ std::ranges::fill_n (prev_counts.data (), prev_counts.size (), float {});
235+ std::ranges::fill_n (estimations.data (), estimations.size (), uint16_t {});
247236 };
248237
249238 auto process_ibf = [&](size_t const i)
@@ -252,7 +241,7 @@ void estimate(estimate_ibf_arguments & args,
252241 {
253242 check_ibf<ibf_t , normalization_method>(args,
254243 ibf,
255- estimations[i] ,
244+ estimations. level (i) ,
256245 seqs[i],
257246 expressions,
258247 fprs,
@@ -264,7 +253,7 @@ void estimate(estimate_ibf_arguments & args,
264253 {
265254 check_ibf<ibf_t , false >(args,
266255 ibf,
267- estimations[i] ,
256+ estimations. level (i) ,
268257 seqs[i],
269258 args.expression_thresholds ,
270259 fprs,
@@ -303,7 +292,7 @@ void estimate(estimate_ibf_arguments & args,
303292 {
304293 outfile << ids[i] << ' \t ' ;
305294 for (size_t j = 0 ; j < num_experiments; ++j)
306- outfile << estimations[i][ j] << ' \t ' ;
295+ outfile << estimations[i, j] << ' \t ' ;
307296 outfile << ' \n ' ;
308297 }
309298 }
0 commit comments