SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
search_result.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 <seqan3/std/concepts>
17 #include <exception>
18 
26 
27 namespace seqan3::detail
28 {
29 // forward declaration
30 template <typename search_configuration_t>
31 #if !SEQAN3_WORKAROUND_GCC_93467
32  requires is_type_specialisation_of_v<search_configuration_t, configuration>
33 #endif // !SEQAN3_WORKAROUND_GCC_93467
34 struct policy_search_result_builder;
35 } // namespace seqan3::detail
36 
37 namespace seqan3
38 {
39 
68 template <typename query_id_type,
69  typename cursor_type,
70  typename reference_id_type,
71  typename reference_begin_position_type>
73  requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>) &&
74  (detail::template_specialisation_of<cursor_type, fm_index_cursor> ||
75  detail::template_specialisation_of<cursor_type, bi_fm_index_cursor> ||
76  std::same_as<cursor_type, detail::empty_type>) &&
77  (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>) &&
78  (std::integral<reference_begin_position_type> || std::same_as<reference_begin_position_type,
79  detail::empty_type>)
82 {
83 private:
85  query_id_type query_id_{};
87  cursor_type cursor_{};
89  reference_id_type reference_id_{};
91  reference_begin_position_type reference_begin_position_{};
92 
93  // Grant the policy access to private constructors.
94  template <typename search_configuration_t>
95  #if !SEQAN3_WORKAROUND_GCC_93467
97  requires detail::is_type_specialisation_of_v<search_configuration_t, configuration>
99  #endif // !SEQAN3_WORKAROUND_GCC_93467
100  friend struct detail::policy_search_result_builder;
101 
102 public:
106  search_result() = default;
107  search_result(search_result const &) = default;
108  search_result(search_result &&) = default;
109  search_result & operator=(search_result const &) = default;
111  ~search_result() = default;
112 
114 
120  constexpr auto query_id() const noexcept
121  {
122  static_assert(!std::same_as<query_id_type, detail::empty_type>,
123  "You tried to access the query_id but it was not selected in the output "
124  "configuration of the search.");
125 
126  return query_id_;
127  }
128 
133  constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
134  {
135  static_assert(!std::same_as<cursor_type, detail::empty_type>,
136  "You tried to access the index cursor but it was not selected in the output "
137  "configuration of the search.");
138 
139  return cursor_;
140  }
141 
148  constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
149  {
150  static_assert(!std::same_as<reference_id_type, detail::empty_type>,
151  "You tried to access the reference id but it was not selected in the output "
152  "configuration of the search.");
153 
154  return reference_id_;
155  }
156 
158  constexpr auto reference_begin_position() const
159  noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
160  {
161  static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
162  "You tried to access the reference begin position but it was not selected in the "
163  "output configuration of the search.");
164 
165  return reference_begin_position_;
166  }
168 
173  friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
174  {
175  bool equality = lhs.query_id_ == rhs.query_id_;
176  if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
177  equality &= lhs.cursor_ == rhs.cursor_;
178  if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
179  equality &= lhs.reference_id_ == rhs.reference_id_;
180  if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
181  equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
182 
183  return equality;
184  }
185 
187  friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
188  {
189  return !(lhs == rhs);
190  }
192 };
193 
201 template <typename char_t, typename search_result_t>
203  requires detail::is_type_specialisation_of_v<std::remove_cvref_t<search_result_t>, search_result>
205 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, search_result_t && result)
206 {
207  using result_type_list = detail::transfer_template_args_onto_t<std::remove_cvref_t<search_result_t>, type_list>;
208 
209  stream << "<";
210  if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
211  stream << "query_id:" << result.query_id();
212  if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
213  stream << ", index cursor is present";
214  if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
215  stream << ", reference_id:" << result.reference_id();
216  if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
217  stream << ", reference_pos:" << result.reference_begin_position();
218  stream << ">";
219 
220  return stream;
221 }
222 
223 } // 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:82
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:187
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:133
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:158
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:173
constexpr auto query_id() const noexcept
Returns the id of the query which produced this search result.
Definition: search_result.hpp:120
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:148
search_result & operator=(search_result const &)=default
Defaulted.
search_result & operator=(search_result &&)=default
Defaulted.
The Concepts library.
Provides seqan3::configuration and utility functions.
Provides seqan3::debug_stream and related types.
Provides type traits for working with templates.
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:101
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition: traits.hpp:260
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.