Raptor
A fast and space-efficient pre-filter
All Classes Namespaces Files Functions Variables Macros Pages Concepts
index_factory.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <seqan3/search/views/minimiser_hash.hpp>
13
20#include <raptor/index.hpp>
21
22namespace raptor
23{
24
26{
27public:
28 index_factory() = default;
29 index_factory(index_factory const &) = default;
30 index_factory(index_factory &&) = default;
31 index_factory & operator=(index_factory const &) = delete; // const member
32 index_factory & operator=(index_factory &&) = delete; // const member
33 ~index_factory() = default;
34
35 explicit index_factory(build_arguments const & args) : arguments{std::addressof(args)}
36 {
37 if (arguments->input_is_minimiser)
39 else
40 reader = file_reader<file_types::sequence>{arguments->shape, arguments->window_size};
41 }
42
43 explicit index_factory(build_arguments const & args, partition_config const & cfg) :
44 arguments{std::addressof(args)},
45 config{std::addressof(cfg)}
46 {
47 if (arguments->input_is_minimiser)
48 reader = file_reader<file_types::minimiser>{}; // GCOVR_EXCL_LINE
49 else
50 reader = file_reader<file_types::sequence>{arguments->shape, arguments->window_size};
51 }
52
53 [[nodiscard]] raptor_index<> operator()(size_t const part = 0u) const
54 {
55 return construct(part);
56 }
57
58private:
59 build_arguments const * const arguments{nullptr};
60 partition_config const * const config{nullptr};
62
63 raptor_index<> construct(size_t const part) const
64 {
65 assert(arguments != nullptr);
66
67 arguments->index_allocation_timer.start();
68 raptor_index<> index{*arguments};
69 arguments->index_allocation_timer.stop();
70
71 auto worker = [&](auto && zipped_view)
72 {
73 seqan::hibf::serial_timer local_timer{};
74 auto & ibf = index.ibf();
75 local_timer.start();
76 // https://godbolt.org/z/PeKnxzjn1
77 for (auto && zipped : zipped_view)
78 {
80 [&](auto const & reader)
81 {
82 auto && [file_names, bin_number] = zipped;
83
84 if (config == nullptr)
85 reader.hash_into(file_names, emplacer(ibf, seqan::hibf::bin_index{bin_number}));
86 else
87 reader.hash_into_if(file_names,
88 emplacer(ibf, seqan::hibf::bin_index{bin_number}),
89 [&](uint64_t const hash)
90 {
91 return config->hash_partition(hash) == part;
92 });
93 },
94 reader);
95 }
96 local_timer.stop();
97 arguments->user_bin_io_timer += local_timer;
98 arguments->fill_ibf_timer += local_timer;
99 };
100
101 call_parallel_on_bins(worker, arguments->bin_path, arguments->threads);
102
103 return index;
104 }
105};
106
107} // namespace raptor
T addressof(T... args)
Provides raptor::adjust_seed.
Provides raptor::call_parallel_on_bins.
Definition file_reader.hpp:29
Definition index_factory.hpp:26
Definition index.hpp:46
Provides raptor::dna4_traits.
Provides raptor::emplace_iterator.
Provides raptor::file_reader.
Provides raptor::raptor_index.
Provides raptor::partition_config.
Definition build_arguments.hpp:23
Definition partition_config.hpp:20
T visit(T... args)
Hide me