Loading...
Searching...
No Matches
search_result.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <concepts>
#include <exception>
#include <seqan3/core/configuration/configuration.hpp>
#include <seqan3/core/debug_stream/debug_stream_type.hpp>
#include <seqan3/core/detail/empty_type.hpp>
#include <seqan3/core/detail/template_inspection.hpp>
#include <seqan3/search/fm_index/bi_fm_index_cursor.hpp>
#include <seqan3/search/fm_index/concept.hpp>
#include <seqan3/search/fm_index/fm_index_cursor.hpp>
namespace seqan3::detail
{
// forward declaration
template <typename search_configuration_t>
requires seqan3::detail::is_type_specialisation_of_v<search_configuration_t, configuration>
struct policy_search_result_builder;
} // namespace seqan3::detail
namespace seqan3
{
template <typename query_id_type,
typename cursor_type,
typename reference_id_type,
typename reference_begin_position_type>
requires (std::integral<query_id_type> || std::same_as<query_id_type, detail::empty_type>)
&& (detail::template_specialisation_of<cursor_type, fm_index_cursor>
|| detail::template_specialisation_of<cursor_type, bi_fm_index_cursor>
|| std::same_as<cursor_type, detail::empty_type>)
&& (std::integral<reference_id_type> || std::same_as<reference_id_type, detail::empty_type>)
&& (std::integral<reference_begin_position_type>
|| std::same_as<reference_begin_position_type, detail::empty_type>)
class search_result
{
private:
query_id_type query_id_{};
cursor_type cursor_{};
reference_id_type reference_id_{};
reference_begin_position_type reference_begin_position_{};
// Grant the policy access to private constructors.
template <typename search_configuration_t>
requires seqan3::detail::is_type_specialisation_of_v<search_configuration_t, configuration>
friend struct detail::policy_search_result_builder;
public:
search_result() = default;
search_result(search_result const &) = default;
search_result(search_result &&) = default;
search_result & operator=(search_result const &) = default;
search_result & operator=(search_result &&) = default;
~search_result() = default;
constexpr auto query_id() const noexcept
{
static_assert(!std::same_as<query_id_type, detail::empty_type>,
"You tried to access the query_id but it was not selected in the output "
"configuration of the search.");
return query_id_;
}
constexpr auto index_cursor() const noexcept(!(std::same_as<cursor_type, detail::empty_type>))
{
static_assert(!std::same_as<cursor_type, detail::empty_type>,
"You tried to access the index cursor but it was not selected in the output "
"configuration of the search.");
return cursor_;
}
constexpr auto reference_id() const noexcept(!(std::same_as<reference_id_type, detail::empty_type>))
{
static_assert(!std::same_as<reference_id_type, detail::empty_type>,
"You tried to access the reference id but it was not selected in the output "
"configuration of the search.");
return reference_id_;
}
constexpr auto reference_begin_position() const
noexcept(!(std::same_as<reference_begin_position_type, detail::empty_type>))
{
static_assert(!std::same_as<reference_begin_position_type, detail::empty_type>,
"You tried to access the reference begin position but it was not selected in the "
"output configuration of the search.");
return reference_begin_position_;
}
friend bool operator==(search_result const & lhs, search_result const & rhs) noexcept
{
bool equality = lhs.query_id_ == rhs.query_id_;
if constexpr (!std::is_same_v<cursor_type, detail::empty_type>)
equality &= lhs.cursor_ == rhs.cursor_;
if constexpr (!std::is_same_v<reference_id_type, detail::empty_type>)
equality &= lhs.reference_id_ == rhs.reference_id_;
if constexpr (!std::is_same_v<reference_begin_position_type, detail::empty_type>)
equality &= lhs.reference_begin_position_ == rhs.reference_begin_position_;
return equality;
}
friend bool operator!=(search_result const & lhs, search_result const & rhs) noexcept
{
return !(lhs == rhs);
}
};
template <typename... specs_t>
struct search_result_printer<search_result<specs_t...>>
{
template <typename stream_t, typename arg_t>
constexpr void operator()(stream_t & stream, arg_t && arg) const
{
using result_type_list = type_list<specs_t...>;
stream << "<";
if constexpr (!std::same_as<list_traits::at<0, result_type_list>, detail::empty_type>)
stream << "query_id:" << arg.query_id();
if constexpr (!std::same_as<list_traits::at<1, result_type_list>, detail::empty_type>)
stream << ", index cursor is present";
if constexpr (!std::same_as<list_traits::at<2, result_type_list>, detail::empty_type>)
stream << ", reference_id:" << arg.reference_id();
if constexpr (!std::same_as<list_traits::at<3, result_type_list>, detail::empty_type>)
stream << ", reference_pos:" << arg.reference_begin_position();
stream << ">";
}
};
} // namespace seqan3
bi_fm_index_cursor.hpp
Provides the seqan3::bi_fm_index_cursor for searching in the bidirectional seqan3::bi_fm_index.
seqan3::search_result
The result class generated by the seqan3::seach algorithm.
Definition search_result.hpp:76
seqan3::search_result::operator!=
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
seqan3::search_result::search_result
search_result()=default
Defaulted.
seqan3::search_result::index_cursor
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
seqan3::search_result::reference_begin_position
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
seqan3::search_result::operator=
search_result & operator=(search_result &&)=default
Defaulted.
seqan3::search_result::search_result
search_result(search_result &&)=default
Defaulted.
seqan3::search_result::operator==
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
seqan3::search_result::query_id
constexpr auto query_id() const noexcept
Returns the id of the query which produced this search result.
Definition search_result.hpp:110
seqan3::search_result::operator=
search_result & operator=(search_result const &)=default
Defaulted.
seqan3::search_result::search_result
search_result(search_result const &)=default
Defaulted.
seqan3::search_result::~search_result
~search_result()=default
Defaulted.
seqan3::search_result::reference_id
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
configuration.hpp
Provides seqan3::configuration and utility functions.
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
empty_type.hpp
Provides seqan3::detail::empty_type.
exception
fm_index_cursor.hpp
Provides the seqan3::fm_index_cursor for searching in the unidirectional seqan3::fm_index.
std::is_same_v
T is_same_v
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
concept.hpp
Provides the concept for seqan3::detail::sdsl_index.
seqan3::search_result_printer< search_result< specs_t... > >::operator()
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the search result.
Definition search_result.hpp:201
seqan3::search_result_printer
Definition default_printer.hpp:43
seqan3::type_list
Type that contains multiple types.
Definition type_list.hpp:26
template_inspection.hpp
Provides type traits for working with templates.
Hide me