SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
policy_search_result_builder.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
10#pragma once
11
16
17namespace seqan3::detail
18{
19
22template <typename search_configuration_t>
23 requires seqan3::detail::is_type_specialisation_of_v<search_configuration_t, configuration>
25{
26protected:
31
32 static_assert(!std::same_as<search_result_type, typename search_traits_type::empty_search_result_type>,
33 "The search result type was not configured properly.");
34
44
46 explicit policy_search_result_builder(search_configuration_t const &)
47 {}
49
64 template <typename index_cursor_t, typename query_index_t, typename callback_t>
65 void make_results(std::vector<index_cursor_t> internal_hits, query_index_t idx, callback_t && callback)
66 {
67 return make_results_impl(std::move(internal_hits), idx, std::forward<callback_t>(callback));
68 }
69
86 template <typename index_cursor_t, typename query_index_t, typename callback_t>
88 void make_results(std::vector<index_cursor_t> internal_hits, query_index_t idx, callback_t && callback)
89 {
91 results.reserve(internal_hits.size()); // expect at least as many text positions as cursors, possibly more
92
93 make_results_impl(std::move(internal_hits),
94 idx,
95 [&results](auto && search_result)
96 {
97 results.push_back(std::move(search_result));
98 });
99
100 // sort by reference id or by reference position if both have the same reference id.
101 std::sort(results.begin(),
102 results.end(),
103 [](auto const & r1, auto const & r2)
104 {
105 return (r1.reference_id() == r2.reference_id())
106 ? (r1.reference_begin_position() < r2.reference_begin_position())
107 : (r1.reference_id() < r2.reference_id());
108 });
109
110 results.erase(std::unique(results.begin(), results.end()), results.end());
111
112 for (auto && search_result : results)
113 callback(std::move(search_result));
114 }
115
116private:
134 template <typename index_cursor_t, typename query_index_t, typename callback_t>
136 [[maybe_unused]] query_index_t idx,
137 callback_t && callback)
138 {
139 auto maybe_locate = [](auto const & cursor)
140 {
142 return cursor.lazy_locate();
143 else
144 return std::views::single(std::tuple{0, 0});
145 };
146
147 for (auto const & cursor : internal_hits)
148 {
149 for (auto && [ref_id, ref_pos] : maybe_locate(cursor))
150 {
151 search_result_type result{};
152
154 result.query_id_ = std::move(idx);
156 result.cursor_ = cursor;
158 result.reference_id_ = std::move(ref_id);
160 result.reference_begin_position_ = std::move(ref_pos);
161
162 callback(result);
163
165 return;
166 }
167 }
168 }
169};
170
171} // namespace seqan3::detail
The result class generated by the seqan3::seach algorithm.
Definition search_result.hpp:76
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T reserve(T... args)
Provides the concept for seqan3::detail::sdsl_index.
Provides seqan3::search_result.
Provides seqan3::detail::search_traits.
T size(T... args)
T sort(T... args)
Provides the function make_results if inherited by a search algorithm.
Definition policy_search_result_builder.hpp:25
policy_search_result_builder(policy_search_result_builder const &)=default
Defaulted.
void make_results(std::vector< index_cursor_t > internal_hits, query_index_t idx, callback_t &&callback)
Invoke the callback on all hits (index cursors) without calling locate on each cursor.
Definition policy_search_result_builder.hpp:65
policy_search_result_builder(search_configuration_t const &)
Construction from the configuration object.
Definition policy_search_result_builder.hpp:46
policy_search_result_builder & operator=(policy_search_result_builder &&)=default
Defaulted.
void make_results_impl(std::vector< index_cursor_t > internal_hits, query_index_t idx, callback_t &&callback)
Invokes the callback on each seqan3::search_result and calls locate on the cursor depending on the co...
Definition policy_search_result_builder.hpp:135
policy_search_result_builder(policy_search_result_builder &&)=default
Defaulted.
::output_requires_locate_call &&!search_traits_type ::search_single_best_hit void make_results(std::vector< index_cursor_t > internal_hits, query_index_t idx, callback_t &&callback)
Invokes the callback on each seqan3::search_result after calling locate on each cursor.
Definition policy_search_result_builder.hpp:88
policy_search_result_builder & operator=(policy_search_result_builder const &)=default
Defaulted.
typename search_traits_type::search_result_type search_result_type
The configured search result type.
Definition policy_search_result_builder.hpp:30
A collection of traits extracted from the search configuration.
Definition search_traits.hpp:31
static constexpr bool output_requires_locate_call
A flag indicating whether it is required to call cursor.locate() to retrieve the respective informati...
Definition search_traits.hpp:80
typename std::remove_cvref_t< decltype(std::declval< search_configuration_t >().get_or(search_cfg::detail::result_type< empty_search_result_type >{}))>::type search_result_type
The configured search result type.
Definition search_traits.hpp:36
static constexpr bool output_query_id
A flag indicating whether search should return the query_id.
Definition search_traits.hpp:69
static constexpr bool search_single_best_hit
A flag indicating whether search should find best hits.
Definition search_traits.hpp:57
static constexpr bool output_index_cursor
A flag indicating whether search should return the index_cursor.
Definition search_traits.hpp:77
static constexpr bool output_reference_id
A flag indicating whether search should return the reference_id.
Definition search_traits.hpp:71
static constexpr bool output_reference_begin_position
A flag indicating whether search should return the reference_begin_position.
Definition search_traits.hpp:74
Provides type traits for working with templates.
T unique(T... args)
Hide me