fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
index.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------
7
8#pragma once
9
10#include <sharg/exceptions.hpp>
11
15
16namespace raptor
17{
18
19namespace index_structure
20{
21
22using ibf = seqan3::interleaved_bloom_filter<seqan3::data_layout::uncompressed>;
23using ibf_compressed = seqan3::interleaved_bloom_filter<seqan3::data_layout::compressed>;
26
27template <typename return_t, typename input_t>
28concept compressible_from = (std::same_as<return_t, ibf_compressed> && std::same_as<input_t, ibf>)
29 || (std::same_as<return_t, hibf_compressed> && std::same_as<input_t, hibf>);
30
31} // namespace index_structure
32
33template <typename data_t = index_structure::ibf>
35{
36private:
37 template <typename friend_data_t>
38 friend class raptor_index;
39
40 uint64_t window_size_{};
41 seqan3::shape shape_{};
42 uint8_t parts_{};
43 bool compressed_{};
44 std::vector<std::vector<std::string>> bin_path_{};
45 data_t ibf_{};
46
47public:
48 static constexpr seqan3::data_layout data_layout_mode = data_t::data_layout_mode;
49 static constexpr uint32_t version{1u};
50
51 raptor_index() = default;
52 raptor_index(raptor_index const &) = default;
54 raptor_index & operator=(raptor_index const &) = default;
56 ~raptor_index() = default;
57
59 seqan3::shape const shape,
60 uint8_t const parts,
61 bool const compressed,
62 std::vector<std::vector<std::string>> const & bin_path,
63 data_t && ibf) :
64 window_size_{window_size.v},
65 shape_{shape},
66 parts_{parts},
67 compressed_{compressed},
68 bin_path_{bin_path},
69 ibf_{std::move(ibf)}
70 {}
71
72 explicit raptor_index(build_arguments const & arguments) :
73 window_size_{arguments.window_size},
74 shape_{arguments.shape},
75 parts_{arguments.parts},
76 compressed_{arguments.compressed},
77 bin_path_{arguments.bin_path},
78 ibf_{seqan3::bin_count{arguments.bins},
79 seqan3::bin_size{arguments.bits / arguments.parts},
80 seqan3::hash_function_count{arguments.hash}}
81 {
82 static_assert(data_layout_mode == seqan3::data_layout::uncompressed);
83 }
84
85 template <typename other_data_t>
87 {
89 window_size_ = other.window_size_;
90 shape_ = other.shape_;
91 parts_ = other.parts_;
92 compressed_ = true;
93 bin_path_ = other.bin_path_;
94 ibf_ = data_t{other.ibf_};
95 }
96
97 template <typename other_data_t>
99 {
101 window_size_ = std::move(other.window_size_);
102 shape_ = std::move(other.shape_);
103 parts_ = std::move(other.parts_);
104 compressed_ = true;
105 bin_path_ = std::move(other.bin_path_);
106 ibf_ = std::move(data_t{std::move(other.ibf_)});
107 }
108
109 uint64_t window_size() const
110 {
111 return window_size_;
112 }
113
114 seqan3::shape shape() const
115 {
116 return shape_;
117 }
118
119 uint8_t parts() const
120 {
121 return parts_;
122 }
123
124 bool compressed() const
125 {
126 return compressed_;
127 }
128
129 std::vector<std::vector<std::string>> const & bin_path() const
130 {
131 return bin_path_;
132 }
133
134 data_t & ibf()
135 {
136 return ibf_;
137 }
138
139 data_t const & ibf() const
140 {
141 return ibf_;
142 }
143
151 template <seqan3::cereal_archive archive_t>
152 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
153 {
154 uint32_t parsed_version{raptor_index<>::version};
155 archive(parsed_version);
156 if (parsed_version == raptor_index<>::version)
157 {
158 try
159 {
160 archive(window_size_);
161 archive(shape_);
162 archive(parts_);
163 archive(compressed_);
164 if ((data_layout_mode == seqan3::data_layout::compressed && !compressed_)
165 || (data_layout_mode == seqan3::data_layout::uncompressed && compressed_))
166 {
167 throw sharg::parser_error{"Data layouts of serialised and specified index differ."};
168 }
169 archive(bin_path_);
170 archive(ibf_);
171 }
172 catch (std::exception const & e)
173 {
174 throw sharg::parser_error{"Cannot read index: " + std::string{e.what()}};
175 }
176 }
177 else
178 {
179 throw sharg::parser_error{"Unsupported index version. Check raptor upgrade."}; // GCOVR_EXCL_LINE
180 }
181 }
182
183 /* \brief Serialisation support function. Do not load the actual data.
184 * \tparam archive_t Type of `archive`; must satisfy seqan3::cereal_input_archive.
185 * \param[in] archive The archive being serialised from/to.
186 * \param[in] version Index version.
187 *
188 * \attention These functions are never called directly, see \ref serialisation for more details.
189 */
190 template <seqan3::cereal_input_archive archive_t>
191 void load_parameters(archive_t & archive)
192 {
193 uint32_t parsed_version{};
194 archive(parsed_version);
195 if (parsed_version == version)
196 {
197 try
198 {
199 archive(window_size_);
200 archive(shape_);
201 archive(parts_);
202 archive(compressed_);
203 archive(bin_path_);
204 }
205 // GCOVR_EXCL_START
206 catch (std::exception const & e)
207 {
208 throw sharg::parser_error{"Cannot read index: " + std::string{e.what()}};
209 }
210 // GCOVR_EXCL_STOP
211 }
212 else
213 {
214 throw sharg::parser_error{"Unsupported index version. Check raptor upgrade."}; // GCOVR_EXCL_LINE
215 }
216 }
218};
219
220} // namespace raptor
The HIBF binning directory. A data structure that efficiently answers set-membership queries for mult...
Definition: hierarchical_interleaved_bloom_filter.hpp:78
Definition: index.hpp:35
seqan3::shape shape() const
Definition: index.hpp:114
raptor_index & operator=(raptor_index &&)=default
raptor_index & operator=(raptor_index const &)=default
static constexpr uint32_t version
Definition: index.hpp:49
bool compressed() const
Definition: index.hpp:124
raptor_index(window const window_size, seqan3::shape const shape, uint8_t const parts, bool const compressed, std::vector< std::vector< std::string > > const &bin_path, data_t &&ibf)
Definition: index.hpp:58
raptor_index(raptor_index const &)=default
std::vector< std::vector< std::string > > const & bin_path() const
Definition: index.hpp:129
uint8_t parts() const
Definition: index.hpp:119
raptor_index(build_arguments const &arguments)
Definition: index.hpp:72
data_t const & ibf() const
Definition: index.hpp:139
uint64_t window_size() const
Definition: index.hpp:109
raptor_index(raptor_index &&)=default
data_t & ibf()
Definition: index.hpp:134
raptor_index(raptor_index< other_data_t > &&other)
Definition: index.hpp:98
raptor_index(raptor_index< other_data_t > const &other)
Definition: index.hpp:86
static constexpr seqan3::data_layout data_layout_mode
Definition: index.hpp:48
seqan3::interleaved_bloom_filter< seqan3::data_layout::compressed > ibf_compressed
Definition: index.hpp:23
seqan3::interleaved_bloom_filter< seqan3::data_layout::uncompressed > ibf
Definition: index.hpp:22
Definition: adjust_seed.hpp:13
Definition: build_arguments.hpp:21
Strong type for passing the window size.
Definition: strong_types.hpp:17