SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
find_optimum_policy.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
19 
20 namespace seqan3::detail
21 {
22 
31 struct default_find_optimum_trait
32 {
34  using find_in_every_cell_type = std::false_type;
36  using find_in_last_row_type = std::false_type;
38  using find_in_last_column_type = std::false_type;
39 };
40 
53 template <typename alignment_algorithm_t, typename traits_type = default_find_optimum_trait>
54 class find_optimum_policy
55 {
56 private:
58  friend alignment_algorithm_t;
59 
63  constexpr find_optimum_policy() = default;
64  constexpr find_optimum_policy(find_optimum_policy const &) = default;
65  constexpr find_optimum_policy(find_optimum_policy &&) = default;
66  constexpr find_optimum_policy & operator=(find_optimum_policy const &) = default;
67  constexpr find_optimum_policy & operator=(find_optimum_policy &&) = default;
68  ~find_optimum_policy() = default;
69 
71 protected:
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  {
87  if constexpr (traits_type::find_in_every_cell_type::value)
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, typename score_t, typename is_local_t>
96  friend class simd_affine_gap_policy;
97 
99  template <typename other_alignment_algorithm_t, typename other_traits_type>
100  friend class affine_gap_init_policy;
101 
114  template <typename cell_t, typename score_t>
115  constexpr void check_score_of_last_row_cell([[maybe_unused]] cell_t const & last_row_cell,
116  [[maybe_unused]] alignment_algorithm_state<score_t> & state) const
117  noexcept
118  {
119  // Only search in last row if requested and not done already.
120  if constexpr (!traits_type::find_in_every_cell_type::value && traits_type::find_in_last_row_type::value)
121  check_and_update(last_row_cell, state);
122  }
123 
136  template <typename alignment_column_t, typename score_t>
137  constexpr void check_score_of_cells_in_last_column([[maybe_unused]] alignment_column_t && last_column,
138  [[maybe_unused]] alignment_algorithm_state<score_t> & state)
139  const noexcept
140  {
141  // Only check last cell if not done before.
142  if constexpr (!traits_type::find_in_every_cell_type::value && traits_type::find_in_last_column_type::value)
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.
164  if constexpr (!traits_type::find_in_every_cell_type::value &&
165  !traits_type::find_in_last_row_type::value &&
166  !traits_type::find_in_last_column_type::value)
167  {
168  check_and_update(last_cell, state);
169  }
170  }
171 
180  template <typename cell_t, typename score_t>
181  constexpr void check_and_update(cell_t const & cell, alignment_algorithm_state<score_t> & state) const noexcept
182  {
183  auto const & [score_cell, trace_cell] = cell;
184  state.optimum.update_if_new_optimal_score(score_cell.current,
185  column_index_type{trace_cell.coordinate.first},
186  row_index_type{trace_cell.coordinate.second});
187  }
188 };
189 
190 } // namespace seqan3::detail
std::false_type
alignment_optimum.hpp
Provides seqan3::detail::alignment_optimum.
alignment_algorithm_state.hpp
Provides seqan3::detail::alignment_algorithm_state.