SeqAn3
The Modern C++ library for sequence analysis.
affine_gap_init_policy.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 <tuple>
16 
18 
19 namespace seqan3::detail
20 {
21 
30 struct default_affine_init_traits
31 {
33  using free_first_leading_t = std::false_type;
35  using free_second_leading_t = std::false_type;
36 };
37 
44 template <typename derived_t, typename traits_type = default_affine_init_traits>
45 class affine_gap_init_policy
46 {
47 private:
48 
50  friend derived_t;
55  constexpr affine_gap_init_policy() noexcept = default;
56  constexpr affine_gap_init_policy(affine_gap_init_policy const &) noexcept = default;
57  constexpr affine_gap_init_policy(affine_gap_init_policy &&) noexcept = default;
58  constexpr affine_gap_init_policy & operator=(affine_gap_init_policy const &) noexcept = default;
59  constexpr affine_gap_init_policy & operator=(affine_gap_init_policy &&) noexcept = default;
60  ~affine_gap_init_policy() noexcept = default;
61 
69  template <typename cell_t, typename cache_t>
70  constexpr auto init_origin_cell(cell_t && current_cell, cache_t & cache) const noexcept
71  {
72  using std::get;
73 
74  auto & [main_score, hz_score, hz_trace] = get<0>(current_cell);
75  auto & prev_cell = get<0>(cache);
76  auto & vt_score = get<1>(prev_cell);
77 
78  main_score = 0;
79  get<2>(current_cell) = trace_directions::none; // store the trace direction
80 
81  // Initialise the vertical matrix cell according to the traits settings.
82  if constexpr (traits_type::free_second_leading_t::value)
83  {
84  vt_score = 0;
85  get<2>(prev_cell) = trace_directions::none; // cache vertical trace
86  }
87  else
88  {
89  vt_score = get<1>(cache);
90  get<2>(prev_cell) = trace_directions::up_open; // cache vertical trace
91  }
92 
93  // Initialise the horizontal matrix cell according to the traits settings.
94  if constexpr (traits_type::free_first_leading_t::value)
95  {
96  hz_score = 0;
97  hz_trace = trace_directions::none; // cache horizontal trace
98  }
99  else
100  {
101  hz_score = get<1>(cache);
102  hz_trace = trace_directions::left_open; // cache horizontal trace
103  }
104  }
105 
112  template <typename cell_t, typename cache_t>
113  constexpr auto init_column_cell(cell_t && current_cell, cache_t & cache) const noexcept
114  {
115  using std::get;
116 
117  auto & [main_score, hz_score, hz_trace] = get<0>(current_cell);
118  auto & prev_cell = get<0>(cache);
119  auto & vt_score = get<1>(prev_cell);
120 
121  main_score = vt_score;
122  get<2>(current_cell) = get<2>(prev_cell); // store the trace direction
123 
124  // Initialise the vertical matrix cell according to the traits settings.
125  if constexpr (traits_type::free_second_leading_t::value)
126  {
127  vt_score = 0;
128  get<2>(prev_cell) = trace_directions::none; // cache vertical trace
129  }
130  else
131  {
132  vt_score += get<2>(cache);
133  get<2>(prev_cell) = trace_directions::up; // cache vertical trace
134  }
135 
136  hz_score = main_score + get<1>(cache);
137  hz_trace = trace_directions::left_open; // cache horizontal trace
138  }
139 
146  template <typename cell_t, typename cache_t>
147  constexpr auto init_row_cell(cell_t && current_cell, cache_t & cache) const noexcept
148  {
149  using std::get;
150 
151  auto & [main_score, hz_score, hz_trace] = get<0>(current_cell);
152  auto & [prev_score, vt_score, vt_trace] = get<0>(cache);
153 
154  prev_score = main_score;
155  main_score = hz_score;
156  get<2>(current_cell) = hz_trace; // store the trace direction
157 
158  vt_score += main_score + get<1>(cache);
159  vt_trace = trace_directions::up_open; // cache vertical trace
160  // Initialise the horizontal matrix cell according to the traits settings.
161  if constexpr (traits_type::free_first_leading_t::value)
162  {
163  hz_score = 0;
164  hz_trace = trace_directions::none;
165  }
166  else
167  {
168  hz_score += get<2>(cache);
169  hz_trace = trace_directions::left;
170  }
171  }
172 };
173 
174 } // namespace seqan3::detail
Provides the declaration of seqan3::detail::trace_directions.
Definition: aligned_sequence_concept.hpp:35
auto const get
A view calling std::get on each element in a range.
Definition: get.hpp:66