19#include <seqan3/utility/simd/algorithm.hpp>
20#include <seqan3/utility/simd/concept.hpp>
22namespace seqan3::detail
40template <
typename alignment_configuration_t>
41class policy_affine_gap_recursion
45 using traits_type = alignment_configuration_traits<alignment_configuration_t>;
47 using original_score_type =
typename traits_type::original_score_type;
49 using score_type =
typename traits_type::score_type;
53 using affine_cell_type = affine_cell_proxy<affine_score_tuple_t>;
56 score_type gap_extension_score{};
58 score_type gap_open_score{};
61 bool first_row_is_free{};
63 bool first_column_is_free{};
68 policy_affine_gap_recursion() =
default;
69 policy_affine_gap_recursion(policy_affine_gap_recursion
const &) =
default;
70 policy_affine_gap_recursion(policy_affine_gap_recursion &&) =
default;
71 policy_affine_gap_recursion & operator=(policy_affine_gap_recursion
const &) =
default;
72 policy_affine_gap_recursion & operator=(policy_affine_gap_recursion &&) =
default;
73 ~policy_affine_gap_recursion() =
default;
84 explicit policy_affine_gap_recursion(alignment_configuration_t
const & config)
87 auto const & selected_gap_scheme =
88 config.get_or(align_cfg::gap_cost_affine{align_cfg::open_score{-10}, align_cfg::extension_score{-1}});
90 gap_extension_score = maybe_convert_to_simd(selected_gap_scheme.extension_score);
91 gap_open_score = maybe_convert_to_simd(selected_gap_scheme.open_score) + gap_extension_score;
93 auto method_global_config = config.get_or(align_cfg::method_global{});
94 first_row_is_free = method_global_config.free_end_gaps_sequence1_leading;
95 first_column_is_free = method_global_config.free_end_gaps_sequence2_leading;
116 template <
typename affine_cell_t>
117 affine_cell_type compute_inner_cell(score_type diagonal_score,
118 affine_cell_t previous_cell,
119 score_type
const sequence_score)
const noexcept
121 diagonal_score += sequence_score;
122 score_type horizontal_score = previous_cell.horizontal_score();
123 score_type vertical_score = previous_cell.vertical_score();
125 diagonal_score = (diagonal_score < vertical_score) ? vertical_score : diagonal_score;
126 diagonal_score = (diagonal_score < horizontal_score) ? horizontal_score : diagonal_score;
128 score_type tmp = diagonal_score + gap_open_score;
129 vertical_score += gap_extension_score;
130 horizontal_score += gap_extension_score;
133 vertical_score = (vertical_score < tmp) ? tmp : vertical_score;
134 horizontal_score = (horizontal_score < tmp) ? tmp : horizontal_score;
136 return {diagonal_score, horizontal_score, vertical_score};
149 affine_cell_type initialise_origin_cell() const noexcept
151 return {score_type{},
152 first_row_is_free ? score_type{} : gap_open_score,
153 first_column_is_free ? score_type{} : gap_open_score};
170 template <
typename affine_cell_t>
171 affine_cell_type initialise_first_column_cell(affine_cell_t previous_cell)
const noexcept
173 score_type new_vertical = previous_cell.vertical_score() + gap_extension_score;
174 return {previous_cell.vertical_score(),
175 previous_cell.vertical_score() + gap_open_score,
176 first_column_is_free ? previous_cell.vertical_score() : new_vertical};
193 template <
typename affine_cell_t>
194 affine_cell_type initialise_first_row_cell(affine_cell_t previous_cell)
const noexcept
196 score_type new_horizontal_score = previous_cell.horizontal_score() + gap_extension_score;
197 return {previous_cell.horizontal_score(),
198 first_row_is_free ? previous_cell.horizontal_score() : new_horizontal_score,
199 previous_cell.horizontal_score() + gap_open_score};
212 score_type lowest_viable_score() const noexcept
214 if constexpr (simd_concept<score_type>)
215 assert(gap_open_score[0] <= 0 && gap_extension_score[0] <= 0);
217 assert(gap_open_score <= 0 && gap_extension_score <= 0);
220 - (gap_open_score + gap_extension_score);
230 template <
typename score_t>
232 constexpr auto maybe_convert_to_simd(score_t && score)
const noexcept
234 if constexpr (simd_concept<score_type>)
235 return simd::fill<score_type>(std::forward<score_t>(score));
237 return std::forward<score_t>(score);
Provides seqan3::detail::affine_cell_proxy.
Provides seqan3::align_config::gap_cost_affine.
Provides helper type traits for the configuration and execution of the alignment algorithm.
A type that satisfies std::is_arithmetic_v<t>.
Provides type traits for working with templates.