SeqAn3 3.3.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// -----------------------------------------------------------------------------------------------------
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 <limits>
17
24
25namespace seqan3::detail
26{
27
39{
55 template <typename score_t, typename coordinate_t>
56 requires (std::totally_ordered<score_t> && std::assignable_from<score_t &, score_t const &>
57 && std::assignable_from<coordinate_t &, coordinate_t const &>)
58 void operator()(score_t & optimal_score,
59 coordinate_t & optimal_coordinate,
60 score_t current_score,
61 coordinate_t current_coordinate) const noexcept
62 {
63 bool const is_better_score = current_score >= optimal_score;
64 optimal_score = (is_better_score) ? std::move(current_score) : optimal_score;
65 optimal_coordinate = (is_better_score) ? std::move(current_coordinate) : optimal_coordinate;
66 }
67};
68
110{
111private:
116
117public:
135 template <typename score_t, typename coordinate_t>
136 requires (std::totally_ordered<score_t> && std::assignable_from<score_t &, score_t const &>
137 && std::assignable_from<coordinate_t &, coordinate_t const &>)
138 void operator()(score_t & optimal_score,
139 coordinate_t & optimal_coordinate,
140 score_t current_score,
141 coordinate_t current_coordinate) const noexcept
142 {
143 bool const is_better_score =
144 (target_row_index == current_coordinate.row || target_col_index == current_coordinate.col)
145 && (current_score >= optimal_score);
146 optimal_score = (is_better_score) ? std::move(current_score) : optimal_score;
147 optimal_coordinate = (is_better_score) ? std::move(current_coordinate) : optimal_coordinate;
148 }
149
155 {
156 target_row_index = row_index.get();
157 target_col_index = col_index.get();
158 }
159};
160
180template <typename alignment_configuration_t, std::semiregular optimum_updater_t>
181 requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
182 && std::invocable<
183 optimum_updater_t,
189{
190protected:
197
203 optimum_updater_t compare_and_set_optimum{};
204
206 bool test_every_cell{false};
211
221
230 policy_optimum_tracker(alignment_configuration_t const & config)
231 {
232 auto method_global_config = config.get_or(align_cfg::method_global{});
233 test_last_row_cell = method_global_config.free_end_gaps_sequence1_trailing;
234 test_last_column_cell = method_global_config.free_end_gaps_sequence2_trailing;
235 }
237
252 template <typename cell_t>
253 decltype(auto) track_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
254 {
255 if (test_every_cell)
256 invoke_comparator(cell, std::move(coordinate));
257
258 return std::forward<cell_t>(cell);
259 }
260
275 template <typename cell_t>
276 decltype(auto) track_last_row_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
277 {
279 invoke_comparator(cell, std::move(coordinate));
280 }
295 template <typename cell_t>
296 decltype(auto) track_last_column_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
297 {
299 invoke_comparator(cell, std::move(coordinate));
300
301 return std::forward<cell_t>(cell);
302 }
303
318 template <typename cell_t>
319 decltype(auto) track_final_cell(cell_t && cell, matrix_coordinate_type coordinate) noexcept
320 {
322 invoke_comparator(cell, std::move(coordinate));
323 }
325 void reset_optimum() noexcept
326 {
329 }
330
342 template <typename cell_t>
343 void invoke_comparator(cell_t && cell, matrix_coordinate_type coordinate) noexcept
344 {
345 compare_and_set_optimum(optimal_score, optimal_coordinate, cell.best_score(), std::move(coordinate));
346 }
347};
348} // 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:122
Implements the tracker to store the global optimum for a particular alignment computation.
Definition: policy_optimum_tracker.hpp:189
void reset_optimum() noexcept
Resets the optimum such that a new alignment can be computed.
Definition: policy_optimum_tracker.hpp:325
~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:230
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:343
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:319
bool test_last_row_cell
Whether cells of the last row shall be tracked.
Definition: policy_optimum_tracker.hpp:208
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:196
typename traits_type::score_type score_type
The configured score type.
Definition: policy_optimum_tracker.hpp:194
policy_optimum_tracker()=default
Defaulted.
score_type optimal_score
The tracked score of the global optimum.
Definition: policy_optimum_tracker.hpp:199
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:276
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:203
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:206
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:296
matrix_coordinate_type optimal_coordinate
The matrix coordinate of the tracked optimum.
Definition: policy_optimum_tracker.hpp:201
bool test_last_column_cell
Whether cells of the last column shall be tracked.
Definition: policy_optimum_tracker.hpp:210
decltype(auto) track_cell(cell_t &&cell, matrix_coordinate_type coordinate) noexcept
Tracks any cell within the alignment matrix.
Definition: policy_optimum_tracker.hpp:253
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:29
A traits type for the alignment algorithm that exposes static information stored within the alignment...
Definition: alignment/pairwise/detail/type_traits.hpp:83
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:136
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:146
A strong type for designated initialisation of the column index of a matrix.
Definition: matrix_coordinate.hpp:32
A function object that compares and possibly updates the alignment optimum with the current cell.
Definition: policy_optimum_tracker.hpp:110
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:154
size_t target_row_index
The row index indicating the last row of the alignment matrix.
Definition: policy_optimum_tracker.hpp:113
size_t target_col_index
The column index indicating the last column of the alignment matrix.
Definition: policy_optimum_tracker.hpp:115
A function object that compares and possibly updates the alignment optimum with the current cell.
Definition: policy_optimum_tracker.hpp:39
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:61
Provides type traits for working with templates.
Provides seqan3::tuple_like.