SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
policy_optimum_tracker.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 <limits>
14
21
22namespace seqan3::detail
23{
24
36{
52 template <typename score_t, typename coordinate_t>
53 requires (std::totally_ordered<score_t> && std::assignable_from<score_t &, score_t const &>
54 && std::assignable_from<coordinate_t &, coordinate_t const &>)
55 void operator()(score_t & optimal_score,
56 coordinate_t & optimal_coordinate,
57 score_t current_score,
58 coordinate_t current_coordinate) const noexcept
59 {
60 bool const is_better_score = current_score >= optimal_score;
61 optimal_score = (is_better_score) ? std::move(current_score) : optimal_score;
62 optimal_coordinate = (is_better_score) ? std::move(current_coordinate) : optimal_coordinate;
63 }
64};
65
107{
108private:
113
114public:
132 template <typename score_t, typename coordinate_t>
133 requires (std::totally_ordered<score_t> && std::assignable_from<score_t &, score_t const &>
134 && std::assignable_from<coordinate_t &, coordinate_t const &>)
135 void operator()(score_t & optimal_score,
136 coordinate_t & optimal_coordinate,
137 score_t current_score,
138 coordinate_t current_coordinate) const noexcept
139 {
140 bool const is_better_score =
141 (target_row_index == current_coordinate.row || target_col_index == current_coordinate.col)
142 && (current_score >= optimal_score);
143 optimal_score = (is_better_score) ? std::move(current_score) : optimal_score;
144 optimal_coordinate = (is_better_score) ? std::move(current_coordinate) : optimal_coordinate;
145 }
146
152 {
153 target_row_index = row_index.get();
154 target_col_index = col_index.get();
155 }
156};
157
177template <typename alignment_configuration_t, std::semiregular optimum_updater_t>
178 requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
179 && std::invocable<
180 optimum_updater_t,
186{
187protected:
194
200 optimum_updater_t compare_and_set_optimum{};
201
203 bool test_every_cell{false};
208
218
227 policy_optimum_tracker(alignment_configuration_t const & config)
228 {
229 auto method_global_config = config.get_or(align_cfg::method_global{});
230 test_last_row_cell = method_global_config.free_end_gaps_sequence1_trailing;
231 test_last_column_cell = method_global_config.free_end_gaps_sequence2_trailing;
232 }
234
249 template <typename cell_t>
250 decltype(auto) track_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
251 {
252 if (test_every_cell)
253 invoke_comparator(cell, std::move(coordinate));
254
255 return std::forward<cell_t>(cell);
256 }
257
272 template <typename cell_t>
273 decltype(auto) track_last_row_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
274 {
276 invoke_comparator(cell, std::move(coordinate));
277 }
292 template <typename cell_t>
293 decltype(auto) track_last_column_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
294 {
296 invoke_comparator(cell, std::move(coordinate));
297
298 return std::forward<cell_t>(cell);
299 }
300
315 template <typename cell_t>
316 decltype(auto) track_final_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
317 {
319 invoke_comparator(cell, std::move(coordinate));
320 }
327
339 template <typename cell_t>
340 void invoke_comparator(cell_t && cell, matrix_coordinate_type coordinate) noexcept
341 {
342 compare_and_set_optimum(optimal_score, optimal_coordinate, cell.best_score(), std::move(coordinate));
343 }
344};
345} // namespace seqan3::detail
Provides helper type traits for the configuration and execution of the alignment algorithm.
Sets the global alignment method.
Definition align_config_method.hpp:119
Implements the tracker to store the global optimum for a particular alignment computation.
Definition policy_optimum_tracker.hpp:186
void reset_optimum() noexcept
Resets the optimum such that a new alignment can be computed.
Definition policy_optimum_tracker.hpp:322
~policy_optimum_tracker()=default
Defaulted.
policy_optimum_tracker(alignment_configuration_t const &config)
Construction and initialisation using the alignment configuration.
Definition policy_optimum_tracker.hpp:227
policy_optimum_tracker & operator=(policy_optimum_tracker const &)=default
Defaulted.
void invoke_comparator(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Handles the invocation of the optimum comparator and updater.
Definition policy_optimum_tracker.hpp:340
decltype(auto) track_final_cell(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Tracks the final cell of the alignment matrix.
Definition policy_optimum_tracker.hpp:316
bool test_last_row_cell
Whether cells of the last row shall be tracked.
Definition policy_optimum_tracker.hpp:205
typename traits_type::matrix_coordinate_type matrix_coordinate_type
The matrix coordinate type that is used to locate a cell inside of the alignment matrix.
Definition policy_optimum_tracker.hpp:193
typename traits_type::score_type score_type
The configured score type.
Definition policy_optimum_tracker.hpp:191
policy_optimum_tracker()=default
Defaulted.
score_type optimal_score
The tracked score of the global optimum.
Definition policy_optimum_tracker.hpp:196
decltype(auto) track_last_row_cell(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Tracks the last cell of a row within the alignment matrix.
Definition policy_optimum_tracker.hpp:273
policy_optimum_tracker & operator=(policy_optimum_tracker &&)=default
Defaulted.
optimum_updater_t compare_and_set_optimum
The function object to compare and exchange the optimum.
Definition policy_optimum_tracker.hpp:200
policy_optimum_tracker(policy_optimum_tracker &&)=default
Defaulted.
bool test_every_cell
Whether every cell of the alignment matrix shall be tracked.
Definition policy_optimum_tracker.hpp:203
decltype(auto) track_last_column_cell(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Tracks the last cell of a column within the alignment matrix.
Definition policy_optimum_tracker.hpp:293
matrix_coordinate_type optimal_coordinate
The matrix coordinate of the tracked optimum.
Definition policy_optimum_tracker.hpp:198
bool test_last_column_cell
Whether cells of the last column shall be tracked.
Definition policy_optimum_tracker.hpp:207
decltype(auto) track_cell(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Tracks any cell within the alignment matrix.
Definition policy_optimum_tracker.hpp:250
policy_optimum_tracker(policy_optimum_tracker const &)=default
Defaulted.
Provides seqan3::configuration and utility functions.
Provides seqan3::detail::coordinate_matrix.
T lowest(T... args)
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
A traits type for the alignment algorithm that exposes static information stored within the alignment...
Definition alignment/pairwise/detail/type_traits.hpp:80
std::conditional_t< is_vectorised, simd_type_t< original_score_type >, original_score_type > score_type
The score type for the alignment algorithm.
Definition alignment/pairwise/detail/type_traits.hpp:133
lazy_conditional_t< is_vectorised, lazy< simd_matrix_coordinate, matrix_index_type >, matrix_coordinate > matrix_coordinate_type
The type of the matrix coordinate.
Definition alignment/pairwise/detail/type_traits.hpp:143
A strong type for designated initialisation of the column index of a matrix.
Definition matrix_coordinate.hpp:29
A function object that compares and possibly updates the alignment optimum with the current cell.
Definition policy_optimum_tracker.hpp:107
void set_target_indices(row_index_type< size_t > row_index, column_index_type< size_t > col_index) noexcept
Sets the target index for the last row and column of the matrix.
Definition policy_optimum_tracker.hpp:151
size_t target_row_index
The row index indicating the last row of the alignment matrix.
Definition policy_optimum_tracker.hpp:110
size_t target_col_index
The column index indicating the last column of the alignment matrix.
Definition policy_optimum_tracker.hpp:112
A function object that compares and possibly updates the alignment optimum with the current cell.
Definition policy_optimum_tracker.hpp:36
A strong type for designated initialisation of the row index of a matrix.
Definition matrix_coordinate.hpp:58
Provides type traits for working with templates.
Provides seqan3::tuple_like.
Hide me