12#include <seqan3/search/views/minimiser_hash.hpp>
14#include <hibf/contrib/std/chunk_view.hpp>
26template <
typename index_t>
27void search_partitioned_hibf(search_arguments
const & arguments, index_t && index)
29 seqan3::sequence_file_input<dna4_traits, seqan3::fields<seqan3::field::id, seqan3::field::seq>> fin{
30 arguments.query_file};
31 using record_type =
typename decltype(fin)::record_type;
35 sync_out synced_out{arguments};
42 size_t bin_path_index_offset{0};
45 auto worker = [&](
size_t const start,
size_t const extent,
bool const output_results)
47 seqan::hibf::serial_timer local_compute_minimiser_timer{};
48 seqan::hibf::serial_timer local_query_ibf_timer{};
49 seqan::hibf::serial_timer local_generate_results_timer{};
51 auto agent = index.ibf().membership_agent();
56 auto hash_adaptor = seqan3::views::minimiser_hash(arguments.shape,
57 seqan3::window_size{arguments.window_size},
58 seqan3::seed{adjust_seed(arguments.shape_weight)});
60 for (
size_t pos = start; pos < start + extent; ++pos)
62 auto const & seq = records[pos].sequence();
65 auto minimiser_view = seq | hash_adaptor | std::views::common;
66 local_compute_minimiser_timer.start();
67 minimiser.assign(minimiser_view.begin(), minimiser_view.end());
68 local_compute_minimiser_timer.stop();
70 size_t const minimiser_count{minimiser.size()};
71 size_t const threshold = thresholder.get(minimiser_count);
73 local_query_ibf_timer.start();
74 auto & result = agent.membership_for(minimiser, threshold);
75 local_query_ibf_timer.stop();
76 local_generate_results_timer.start();
77 for (
auto && user_bin_id : result)
79 result_string +=
std::to_string(bin_path_index_offset + user_bin_id);
86 auto const &
id = records[pos].id();
87 result_string.
insert(result_string.
begin(),
id.begin(),
id.end());
89 if (
auto & last_char = result_string.
back(); last_char ==
',')
92 result_string +=
'\n';
94 synced_out.write(result_string);
95 result_string.
clear();
97 local_generate_results_timer.stop();
100 arguments.compute_minimiser_timer += local_compute_minimiser_timer;
101 arguments.query_ibf_timer += local_query_ibf_timer;
102 arguments.generate_results_timer += local_generate_results_timer;
105 bool first_chunk{
true};
106 auto bin_paths = arguments.bin_path;
109 for (
auto && chunked_records : fin | seqan::stl::views::chunk((1ULL << 20) * 10))
112 auto cereal_future =
std::async(std::launch::async,
115 load_index(index, arguments, 0);
119 arguments.query_file_io_timer.start();
121 arguments.query_file_io_timer.stop();
123 results.
resize(records.size());
127 assert(arguments.parts > 0);
128 for (
int part = 0; part < arguments.parts - 1; ++part)
130 do_parallel(worker, records.size(), arguments.threads,
false );
131 load_index(index, arguments, part + 1);
134 bin_path_index_offsets[part + 1] = bin_paths.size();
135 bin_paths.insert(bin_paths.end(), index.bin_path().begin(), index.bin_path().end());
137 bin_path_index_offset = bin_path_index_offsets[part + 1];
142 auto arguments_copy = arguments;
143 arguments_copy.bin_path = bin_paths;
144 synced_out.write_header(arguments_copy, index.ibf().ibf_vector[0].hash_function_count());
146 do_parallel(worker, records.size(), arguments.threads,
true );
149 bin_path_index_offset = 0;
Provides raptor::adjust_seed.
T back_inserter(T... args)
Definition threshold.hpp:19
Provides raptor::dna4_traits.
Provides raptor::do_parallel.
Provides raptor::load_index.
Provides raptor::sync_out.
Provides raptor::threshold::threshold.