SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
search_result.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
11#pragma once
12
13#include <concepts>
14#include <exception>
15
23
24namespace seqan3::detail
25{
26// forward declaration
27template <typename search_configuration_t>
28 requires seqan3::detail::is_type_specialisation_of_v<search_configuration_t, configuration>
29struct policy_search_result_builder;
30} // namespace seqan3::detail
31
32namespace seqan3
33{
34
64template <typename query_id_type,
65 typename cursor_type,
66 typename reference_id_type,
67 typename reference_begin_position_type>
68 requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>)
69 && (detail::template_specialisation_of<cursor_type, fm_index_cursor>
70 || detail::template_specialisation_of<cursor_type, bi_fm_index_cursor>
71 || std::same_as<cursor_type, detail::empty_type>)
72 && (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>)
73 && (std::integral<reference_begin_position_type>
74 || std::same_as<reference_begin_position_type, detail::empty_type>)
76{
77private:
79 query_id_type query_id_{};
81 cursor_type cursor_{};
83 reference_id_type reference_id_{};
85 reference_begin_position_type reference_begin_position_{};
86
87 // Grant the policy access to private constructors.
88 template <typename search_configuration_t>
89 requires seqan3::detail::is_type_specialisation_of_v<search_configuration_t, configuration>
91
92public:
96 search_result() = default;
97 search_result(search_result const &) = default;
99 search_result & operator=(search_result const &) = default;
101 ~search_result() = default;
102
104
110 constexpr auto query_id() const noexcept
111 {
112 static_assert(!std::same_as<query_id_type, detail::empty_type>,
113 "You tried to access the query_id but it was not selected in the output "
114 "configuration of the search.");
115
116 return query_id_;
117 }
118
123 constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
124 {
125 static_assert(!std::same_as<cursor_type, detail::empty_type>,
126 "You tried to access the index cursor but it was not selected in the output "
127 "configuration of the search.");
128
129 return cursor_;
130 }
131
138 constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
139 {
140 static_assert(!std::same_as<reference_id_type, detail::empty_type>,
141 "You tried to access the reference id but it was not selected in the output "
142 "configuration of the search.");
143
144 return reference_id_;
145 }
146
148 constexpr auto reference_begin_position() const
149 noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
150 {
151 static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
152 "You tried to access the reference begin position but it was not selected in the "
153 "output configuration of the search.");
154
156 }
158
163 friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
164 {
165 bool equality = lhs.query_id_ == rhs.query_id_;
166 if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
167 equality &= lhs.cursor_ == rhs.cursor_;
168 if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
169 equality &= lhs.reference_id_ == rhs.reference_id_;
170 if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
171 equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
172
173 return equality;
174 }
175
177 friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
178 {
179 return !(lhs == rhs);
180 }
182};
183
191template <typename char_t, typename search_result_t>
192 requires detail::is_type_specialisation_of_v<std::remove_cvref_t<search_result_t>, search_result>
193inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, search_result_t && result)
194{
195 using result_type_list = detail::transfer_template_args_onto_t<std::remove_cvref_t<search_result_t>, type_list>;
196
197 stream << "<";
198 if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
199 stream << "query_id:" << result.query_id();
200 if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
201 stream << ", index cursor is present";
202 if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
203 stream << ", reference_id:" << result.reference_id();
204 if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
205 stream << ", reference_pos:" << result.reference_begin_position();
206 stream << ">";
207
208 return stream;
209}
210
211} // namespace seqan3
Provides the seqan3::bi_fm_index_cursor for searching in the bidirectional seqan3::bi_fm_index.
The result class generated by the seqan3::seach algorithm.
Definition search_result.hpp:76
friend bool operator!=(search_result const &lhs, search_result const &rhs) noexcept
Returns whether lhs and rhs are not the same.
Definition search_result.hpp:177
search_result()=default
Defaulted.
constexpr auto index_cursor() const noexcept(!(std::same_as< cursor_type, detail::empty_type >))
Returns the index cursor pointing to the suffix array range where the query was found.
Definition search_result.hpp:123
constexpr auto reference_begin_position() const noexcept(!(std::same_as< reference_begin_position_type, detail::empty_type >))
Returns the reference begin positions where the query was found in the reference text (at reference i...
Definition search_result.hpp:148
search_result & operator=(search_result &&)=default
Defaulted.
search_result(search_result &&)=default
Defaulted.
query_id_type query_id_
Stores the query_id of the search result.
Definition search_result.hpp:79
friend bool operator==(search_result const &lhs, search_result const &rhs) noexcept
Returns whether lhs and rhs are the same.
Definition search_result.hpp:163
reference_id_type reference_id_
Stores the reference_id of the search result.
Definition search_result.hpp:83
constexpr auto query_id() const noexcept
Returns the id of the query which produced this search result.
Definition search_result.hpp:110
cursor_type cursor_
Stores the cursor of the search result.
Definition search_result.hpp:81
search_result & operator=(search_result const &)=default
Defaulted.
search_result(search_result const &)=default
Defaulted.
reference_begin_position_type reference_begin_position_
Stores the reference_begin_position of the search result.
Definition search_result.hpp:85
~search_result()=default
Defaulted.
constexpr auto reference_id() const noexcept(!(std::same_as< reference_id_type, detail::empty_type >))
Returns the reference id where the query was found.
Definition search_result.hpp:138
Provides seqan3::configuration and utility functions.
Provides seqan3::debug_stream and related types.
Provides seqan3::detail::empty_type.
Provides the seqan3::fm_index_cursor for searching in the unidirectional seqan3::fm_index.
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition debug_stream_alignment.hpp:107
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Provides the concept for seqan3::detail::sdsl_index.
Provides the function make_results if inherited by a search algorithm.
Definition policy_search_result_builder.hpp:25
Provides type traits for working with templates.
Hide me