SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
find_optimum_policy.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
13#pragma once
14
15#include <type_traits>
16
20
21namespace seqan3::detail
22{
23
34template <typename alignment_algorithm_t>
36{
37private:
40
42 bool test_every_cell{false};
44 bool test_last_row_cell{false};
47
51 constexpr find_optimum_policy() = default;
52 constexpr find_optimum_policy(find_optimum_policy const &) = default;
53 constexpr find_optimum_policy(find_optimum_policy &&) = default;
54 constexpr find_optimum_policy & operator=(find_optimum_policy const &) = default;
57
59 template <typename configuration_t>
60 find_optimum_policy(configuration_t const & config)
61 {
62 if constexpr (configuration_t::template exists<align_cfg::method_local>())
63 test_every_cell = true;
64
65 auto method_global_config = config.get_or(align_cfg::method_global{});
66 test_last_row_cell = method_global_config.free_end_gaps_sequence1_trailing;
67 test_last_column_cell = method_global_config.free_end_gaps_sequence2_trailing;
68 }
70
71protected:
83 template <typename cell_t, typename score_t>
84 constexpr void check_score_of_cell([[maybe_unused]] cell_t const & current_cell,
85 [[maybe_unused]] alignment_algorithm_state<score_t> & state) const noexcept
86 {
88 check_and_update(current_cell, state);
89 }
90
92 template <typename other_alignment_algorithm_t, typename score_t, typename is_local_t>
93 friend class affine_gap_policy;
94
95 template <typename other_alignment_algorithm_t, simd_concept score_t, typename is_local_t>
96 friend class simd_affine_gap_policy;
97
99 template <typename other_alignment_algorithm_t>
101
114 template <typename cell_t, typename score_t>
115 constexpr void
116 check_score_of_last_row_cell([[maybe_unused]] cell_t const & last_row_cell,
117 [[maybe_unused]] alignment_algorithm_state<score_t> & state) const noexcept
118 {
119 // Only search in last row if requested and not done already.
121 check_and_update(last_row_cell, state);
122 }
123
136 template <typename alignment_column_t, typename score_t>
137 constexpr void
138 check_score_of_cells_in_last_column([[maybe_unused]] alignment_column_t && last_column,
139 [[maybe_unused]] alignment_algorithm_state<score_t> & state) const noexcept
140 {
141 // Only check last cell if not done before.
143 for (auto && cell : last_column)
144 check_and_update(cell, state);
145 }
146
159 template <typename cell_t, typename score_t>
160 constexpr void check_score_of_last_cell([[maybe_unused]] cell_t const & last_cell,
161 [[maybe_unused]] alignment_algorithm_state<score_t> & state) const noexcept
162 {
163 // Only check last cell if not done before.
165 check_and_update(last_cell, state);
166 }
167
176 template <typename cell_t, typename score_t>
177 constexpr void check_and_update(cell_t const & cell, alignment_algorithm_state<score_t> & state) const noexcept
178 {
179 auto const & [score_cell, trace_cell] = cell;
180 state.optimum.update_if_new_optimal_score(score_cell.current,
181 column_index_type{trace_cell.coordinate.first},
182 row_index_type{trace_cell.coordinate.second});
183 }
184};
185
186} // namespace seqan3::detail
Provides global and local alignment configurations.
Provides seqan3::detail::alignment_algorithm_state.
Provides seqan3::detail::alignment_optimum.
Sets the global alignment method.
Definition: align_config_method.hpp:122
The CRTP-policy that implements the initialisation of the dynamic programming matrix with affine gaps...
Definition: affine_gap_init_policy.hpp:37
The CRTP-policy that computes a single cell in the alignment matrix.
Definition: affine_gap_policy.hpp:47
The CRTP-policy to determine the optimum of the dynamic programming matrix.
Definition: find_optimum_policy.hpp:36
~find_optimum_policy()=default
Defaulted.
constexpr void check_score_of_cells_in_last_column(alignment_column_t &&last_column, alignment_algorithm_state< score_t > &state) const noexcept
Checks all cells of the last alignment column for a new alignment optimum.
Definition: find_optimum_policy.hpp:138
constexpr find_optimum_policy & operator=(find_optimum_policy &&)=default
Defaulted.
constexpr void check_score_of_last_cell(cell_t const &last_cell, alignment_algorithm_state< score_t > &state) const noexcept
Checks if the last cell of the alignment matrix is a new optimum in the alignment.
Definition: find_optimum_policy.hpp:160
friend alignment_algorithm_t
Befriends the derived class to grant it access to the private members.
Definition: find_optimum_policy.hpp:39
constexpr void check_and_update(cell_t const &cell, alignment_algorithm_state< score_t > &state) const noexcept
Tests if the score in the current cell is greater than the current alignment optimum.
Definition: find_optimum_policy.hpp:177
constexpr void check_score_of_last_row_cell(cell_t const &last_row_cell, alignment_algorithm_state< score_t > &state) const noexcept
Checks if a cell in the last row of the alignment matrix is a new optimum in the alignment.
Definition: find_optimum_policy.hpp:116
constexpr void check_score_of_cell(cell_t const &current_cell, alignment_algorithm_state< score_t > &state) const noexcept
Checks if a given cell is a new optimum in the alignment.
Definition: find_optimum_policy.hpp:84
bool test_last_column_cell
Whether cells of the last column shall be tracked.
Definition: find_optimum_policy.hpp:46
constexpr find_optimum_policy()=default
Defaulted.
bool test_every_cell
Whether every cell of the alignment matrix shall be tracked.
Definition: find_optimum_policy.hpp:42
bool test_last_row_cell
Whether cells of the last row shall be tracked.
Definition: find_optimum_policy.hpp:44
constexpr find_optimum_policy & operator=(find_optimum_policy const &)=default
Defaulted.
constexpr find_optimum_policy(find_optimum_policy &&)=default
Defaulted.
find_optimum_policy(configuration_t const &config)
Initialises the policy with the configuration.
Definition: find_optimum_policy.hpp:60
constexpr find_optimum_policy(find_optimum_policy const &)=default
Defaulted.
The CRTP-policy that computes a batch of cells in the alignment matrix using simd instructions.
Definition: simd_affine_gap_policy.hpp:54
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
A strong type for designated initialisation of the column index of a matrix.
Definition: matrix_coordinate.hpp:32
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:61