SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
affine_gap_init_policy.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
10#pragma once
11
12#include <tuple>
13
17
18namespace seqan3::detail
19{
20
32template <typename alignment_algorithm_t>
34{
35private:
38
43
48 constexpr affine_gap_init_policy() noexcept = default;
49 constexpr affine_gap_init_policy(affine_gap_init_policy const &) noexcept = default;
50 constexpr affine_gap_init_policy(affine_gap_init_policy &&) noexcept = default;
51 constexpr affine_gap_init_policy & operator=(affine_gap_init_policy const &) noexcept = default;
52 constexpr affine_gap_init_policy & operator=(affine_gap_init_policy &&) noexcept = default;
53 ~affine_gap_init_policy() noexcept = default;
54
56 template <typename config_t>
57 affine_gap_init_policy(config_t const & config)
58 {
59 bool is_local = config.template exists<align_cfg::method_local>();
60 auto method_global_config = config.get_or(align_cfg::method_global{});
61 first_row_is_free = method_global_config.free_end_gaps_sequence1_leading | is_local;
62 first_column_is_free = method_global_config.free_end_gaps_sequence2_leading | is_local;
63 }
65
80 template <typename cell_t, typename score_t>
81 constexpr auto init_origin_cell(cell_t && origin_cell, alignment_algorithm_state<score_t> & state) const noexcept
82 {
83 // score_cell = seqan3::detail::alignment_score_matrix_proxy
84 // trace_cell = seqan3::detail::alignment_trace_matrix_proxy
85 auto & [score_cell, trace_cell] = origin_cell;
86
87 // Initialise the first cell.
88 score_cell.current = convert_to_simd_maybe<score_t>(0);
89 trace_cell.current = convert_to_simd_maybe<score_t>(trace_directions::none);
90
91 static_cast<alignment_algorithm_t const &>(*this).check_score_of_cell(origin_cell, state);
92
93 // Initialise the vertical matrix cell according to the traits settings.
95 {
96 score_cell.up = convert_to_simd_maybe<score_t>(0);
97 trace_cell.up = convert_to_simd_maybe<score_t>(trace_directions::none);
98 }
99 else // Initialise with gap_open score
100 {
101 score_cell.up = state.gap_open_score;
102 trace_cell.up = convert_to_simd_maybe<score_t>(trace_directions::up_open);
103 }
104
105 // Initialise the horizontal matrix cell according to the traits settings.
107 {
108 score_cell.w_left = convert_to_simd_maybe<score_t>(0);
109 trace_cell.w_left = convert_to_simd_maybe<score_t>(trace_directions::none);
110 }
111 else // Initialise with gap_open score
112 {
113 score_cell.w_left = state.gap_open_score;
114 trace_cell.w_left = convert_to_simd_maybe<score_t>(trace_directions::left_open);
115 }
116 }
117
132 template <typename cell_t, typename score_t>
133 constexpr auto init_column_cell(cell_t && column_cell, alignment_algorithm_state<score_t> & state) const noexcept
134 {
135 // score_cell = seqan3::detail::alignment_score_matrix_proxy
136 // trace_cell = seqan3::detail::alignment_trace_matrix_proxy
137 auto & [score_cell, trace_cell] = column_cell;
138
139 score_cell.current = score_cell.up;
140 trace_cell.current = trace_cell.up;
141
142 static_cast<alignment_algorithm_t const &>(*this).check_score_of_cell(column_cell, state);
143
144 // Initialise the vertical matrix cell according to the traits settings.
146 {
147 score_cell.up = convert_to_simd_maybe<score_t>(0);
148 }
149 else
150 {
151 score_cell.up += state.gap_extension_score;
152 trace_cell.up = convert_to_simd_maybe<score_t>(trace_directions::up);
153 }
154
155 score_cell.w_left = score_cell.current + state.gap_open_score;
156 trace_cell.w_left = convert_to_simd_maybe<score_t>(trace_directions::left_open);
157 }
158
173 template <typename cell_t, typename score_t>
174 constexpr auto init_row_cell(cell_t && row_cell, alignment_algorithm_state<score_t> & state) const noexcept
175 {
176 // score_cell = seqan3::detail::alignment_score_matrix_proxy
177 // trace_cell = seqan3::detail::alignment_trace_matrix_proxy
178 auto & [score_cell, trace_cell] = row_cell;
179
180 score_cell.current = score_cell.r_left;
181 trace_cell.current = trace_cell.r_left;
182
183 static_cast<alignment_algorithm_t const &>(*this).check_score_of_cell(row_cell, state);
184
185 score_cell.up = score_cell.current + state.gap_open_score;
186 trace_cell.up = convert_to_simd_maybe<score_t>(trace_directions::up_open);
187
189 {
190 score_cell.w_left = convert_to_simd_maybe<score_t>(0);
191 trace_cell.w_left = convert_to_simd_maybe<score_t>(trace_directions::none);
192 }
193 else
194 {
195 score_cell.w_left = score_cell.r_left + state.gap_extension_score;
196 trace_cell.w_left = convert_to_simd_maybe<score_t>(trace_directions::left);
197 }
198 }
199
200private:
212 template <typename score_t, typename value_t>
213 constexpr auto convert_to_simd_maybe(value_t const value) const noexcept
214 {
215 if constexpr (simd_concept<score_t>)
216 {
217 using scalar_t = typename simd_traits<score_t>::scalar_type;
218 return simd::fill<score_t>(static_cast<scalar_t>(value));
219 }
220 else
221 {
222 return value;
223 }
224 }
225};
226
227} // namespace seqan3::detail
Provides global and local alignment configurations.
Provides seqan3::detail::alignment_algorithm_state.
Sets the global alignment method.
Definition align_config_method.hpp:119
The CRTP-policy that implements the initialisation of the dynamic programming matrix with affine gaps...
Definition affine_gap_init_policy.hpp:34
constexpr auto init_origin_cell(cell_t &&origin_cell, alignment_algorithm_state< score_t > &state) const noexcept
Initialises the first cell of the dynamic programming matrix.
Definition affine_gap_init_policy.hpp:81
constexpr auto init_column_cell(cell_t &&column_cell, alignment_algorithm_state< score_t > &state) const noexcept
Initialises a cell in the first column of the dynamic programming matrix.
Definition affine_gap_init_policy.hpp:133
bool first_row_is_free
Initialisation state of the first row of the alignment.
Definition affine_gap_init_policy.hpp:40
constexpr auto convert_to_simd_maybe(value_t const value) const noexcept
Converts the given value into a simd vector or just returns the value if alignment is not executed in...
Definition affine_gap_init_policy.hpp:213
constexpr affine_gap_init_policy() noexcept=default
Defaulted.
constexpr auto init_row_cell(cell_t &&row_cell, alignment_algorithm_state< score_t > &state) const noexcept
Initialises a cell in the first row of the dynamic programming matrix.
Definition affine_gap_init_policy.hpp:174
friend alignment_algorithm_t
Befriends the derived class to grant it access to the private members.
Definition affine_gap_init_policy.hpp:37
bool first_column_is_free
Initialisation state of the first column of the alignment.
Definition affine_gap_init_policy.hpp:42
@ up
Trace comes from the above entry.
@ left
Trace comes from the left entry.
@ left_open
Trace comes from the left entry, while opening the gap.
@ up_open
Trace comes from the above entry, while opening the gap.
The generic simd concept.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Local state for the standard alignment algorithm.
Definition alignment_algorithm_state.hpp:32
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38
Provides the declaration of seqan3::detail::trace_directions.
Hide me