SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
search_result.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/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
14#pragma once
15
16#include <concepts>
17#include <exception>
18
26
27namespace seqan3::detail
28{
29// forward declaration
30template <typename search_configuration_t>
31 requires is_type_specialisation_of_v<search_configuration_t, configuration>
32struct policy_search_result_builder;
33} // namespace seqan3::detail
34
35namespace seqan3
36{
37
67template <typename query_id_type,
68 typename cursor_type,
69 typename reference_id_type,
70 typename reference_begin_position_type>
71 requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>)
72 && (detail::template_specialisation_of<cursor_type, fm_index_cursor>
73 || detail::template_specialisation_of<cursor_type, bi_fm_index_cursor>
74 || std::same_as<cursor_type, detail::empty_type>)
75 && (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>)
76 && (std::integral<reference_begin_position_type>
77 || std::same_as<reference_begin_position_type, detail::empty_type>)
79{
80private:
82 query_id_type query_id_{};
84 cursor_type cursor_{};
86 reference_id_type reference_id_{};
88 reference_begin_position_type reference_begin_position_{};
89
90 // Grant the policy access to private constructors.
91 template <typename search_configuration_t>
92 requires detail::is_type_specialisation_of_v<search_configuration_t, configuration>
93 friend struct detail::policy_search_result_builder;
94
95public:
99 search_result() = default;
100 search_result(search_result const &) = default;
102 search_result & operator=(search_result const &) = default;
104 ~search_result() = default;
105
107
113 constexpr auto query_id() const noexcept
114 {
115 static_assert(!std::same_as<query_id_type, detail::empty_type>,
116 "You tried to access the query_id but it was not selected in the output "
117 "configuration of the search.");
118
119 return query_id_;
120 }
121
126 constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
127 {
128 static_assert(!std::same_as<cursor_type, detail::empty_type>,
129 "You tried to access the index cursor but it was not selected in the output "
130 "configuration of the search.");
131
132 return cursor_;
133 }
134
141 constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
142 {
143 static_assert(!std::same_as<reference_id_type, detail::empty_type>,
144 "You tried to access the reference id but it was not selected in the output "
145 "configuration of the search.");
146
147 return reference_id_;
148 }
149
151 constexpr auto reference_begin_position() const
152 noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
153 {
154 static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
155 "You tried to access the reference begin position but it was not selected in the "
156 "output configuration of the search.");
157
158 return reference_begin_position_;
159 }
161
166 friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
167 {
168 bool equality = lhs.query_id_ == rhs.query_id_;
169 if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
170 equality &= lhs.cursor_ == rhs.cursor_;
171 if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
172 equality &= lhs.reference_id_ == rhs.reference_id_;
173 if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
174 equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
175
176 return equality;
177 }
178
180 friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
181 {
182 return !(lhs == rhs);
183 }
185};
186
194template <typename char_t, typename search_result_t>
195 requires detail::is_type_specialisation_of_v<std::remove_cvref_t<search_result_t>, search_result>
196inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, search_result_t && result)
197{
198 using result_type_list = detail::transfer_template_args_onto_t<std::remove_cvref_t<search_result_t>, type_list>;
199
200 stream << "<";
201 if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
202 stream << "query_id:" << result.query_id();
203 if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
204 stream << ", index cursor is present";
205 if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
206 stream << ", reference_id:" << result.reference_id();
207 if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
208 stream << ", reference_pos:" << result.reference_begin_position();
209 stream << ">";
210
211 return stream;
212}
213
214} // 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:79
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:180
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:126
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:151
search_result & operator=(search_result &&)=default
Defaulted.
search_result(search_result &&)=default
Defaulted.
friend bool operator==(search_result const &lhs, search_result const &rhs) noexcept
Returns whether lhs and rhs are the same.
Definition: search_result.hpp:166
constexpr auto query_id() const noexcept
Returns the id of the query which produced this search result.
Definition: search_result.hpp:113
search_result & operator=(search_result const &)=default
Defaulted.
search_result(search_result const &)=default
Defaulted.
~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:141
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:110
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides the concept for seqan3::detail::sdsl_index.
Provides type traits for working with templates.