SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
policy_affine_gap_recursion.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
11#pragma once
12
13#include <tuple>
14
21
22namespace seqan3::detail
23{
24
40template <typename alignment_configuration_t>
42{
43protected:
59
64
74
84 explicit policy_affine_gap_recursion(alignment_configuration_t const & config)
85 {
86 // Get the gap scheme from the config or choose -1 and -10 as default.
87 auto const & selected_gap_scheme =
89
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;
92
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;
96 }
98
116 template <typename affine_cell_t>
118 affine_cell_t previous_cell,
119 score_type const sequence_score) const noexcept
120 {
121 diagonal_score += sequence_score;
122 score_type horizontal_score = previous_cell.horizontal_score();
123 score_type vertical_score = previous_cell.vertical_score();
124
125 diagonal_score = (diagonal_score < vertical_score) ? vertical_score : diagonal_score;
126 diagonal_score = (diagonal_score < horizontal_score) ? horizontal_score : diagonal_score;
127
128 score_type tmp = diagonal_score + gap_open_score;
129 vertical_score += gap_extension_score;
130 horizontal_score += gap_extension_score;
131
132 // store the vertical_score and horizontal_score value in the next path
133 vertical_score = (vertical_score < tmp) ? tmp : vertical_score;
134 horizontal_score = (horizontal_score < tmp) ? tmp : horizontal_score;
135
136 return {diagonal_score, horizontal_score, vertical_score};
137 }
138
155
170 template <typename affine_cell_t>
171 affine_cell_type initialise_first_column_cell(affine_cell_t previous_cell) const noexcept
172 {
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};
177 }
178
193 template <typename affine_cell_t>
194 affine_cell_type initialise_first_row_cell(affine_cell_t previous_cell) const noexcept
195 {
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};
200 }
201
213 {
214 if constexpr (simd_concept<score_type>)
215 assert(gap_open_score[0] <= 0 && gap_extension_score[0] <= 0);
216 else
217 assert(gap_open_score <= 0 && gap_extension_score <= 0);
218
221 }
222
230 template <typename score_t>
232 constexpr auto maybe_convert_to_simd(score_t && score) const noexcept
233 {
234 if constexpr (simd_concept<score_type>)
235 return simd::fill<score_type>(std::forward<score_t>(score));
236 else // Return unmodified.
237 return std::forward<score_t>(score);
238 }
239};
240} // namespace seqan3::detail
Provides seqan3::detail::affine_cell_proxy.
Provides algorithms to modify seqan3::simd::simd_type.
Provides seqan3::align_config::gap_cost_affine.
Provides helper type traits for the configuration and execution of the alignment algorithm.
A configuration element for the affine gap cost scheme.
Definition align_config_gap_cost_affine.hpp:72
Sets the global alignment method.
Definition align_config_method.hpp:119
A proxy for an affine score matrix cell.
Definition affine_cell_proxy.hpp:114
decltype(auto) vertical_score() &noexcept
Access the vertical score of the wrapped score matrix cell.
Definition affine_cell_proxy.hpp:231
decltype(auto) horizontal_score() &noexcept
Access the horizontal score of the wrapped score matrix cell.
Definition affine_cell_proxy.hpp:210
Implements the alignment recursion function for the alignment algorithm using affine gap costs.
Definition policy_affine_gap_recursion.hpp:42
affine_cell_type compute_inner_cell(score_type diagonal_score, affine_cell_t previous_cell, score_type const sequence_score) const noexcept
Computes an inner cell of the alignment matrix.
Definition policy_affine_gap_recursion.hpp:117
policy_affine_gap_recursion(policy_affine_gap_recursion &&)=default
Defaulted.
bool first_row_is_free
Initialisation state of the first row of the alignment.
Definition policy_affine_gap_recursion.hpp:61
policy_affine_gap_recursion & operator=(policy_affine_gap_recursion const &)=default
Defaulted.
affine_cell_type initialise_first_row_cell(affine_cell_t previous_cell) const noexcept
Initialises the first cell of a alignment matrix column.
Definition policy_affine_gap_recursion.hpp:194
affine_cell_type initialise_origin_cell() const noexcept
Initialises the first cell of the alignment matrix in the top left corner of the matrix.
Definition policy_affine_gap_recursion.hpp:149
score_type gap_extension_score
The score for a gap extension.
Definition policy_affine_gap_recursion.hpp:56
typename traits_type::score_type score_type
The configured score type.
Definition policy_affine_gap_recursion.hpp:49
score_type gap_open_score
The score for a gap opening including the gap extension.
Definition policy_affine_gap_recursion.hpp:58
bool first_column_is_free
Initialisation state of the first column of the alignment.
Definition policy_affine_gap_recursion.hpp:63
typename traits_type::original_score_type original_score_type
The configured original score type.
Definition policy_affine_gap_recursion.hpp:47
score_type lowest_viable_score() const noexcept
Returns the lowest viable score.
Definition policy_affine_gap_recursion.hpp:212
policy_affine_gap_recursion & operator=(policy_affine_gap_recursion &&)=default
Defaulted.
constexpr auto maybe_convert_to_simd(score_t &&score) const noexcept
Converts the given score type to a simd vector if the alignment is executed in vectorised mode.
Definition policy_affine_gap_recursion.hpp:232
policy_affine_gap_recursion(policy_affine_gap_recursion const &)=default
Defaulted.
affine_cell_type initialise_first_column_cell(affine_cell_t previous_cell) const noexcept
Initialises a cell of the first alignment matrix column.
Definition policy_affine_gap_recursion.hpp:171
policy_affine_gap_recursion(alignment_configuration_t const &config)
Construction and initialisation using the alignment configuration.
Definition policy_affine_gap_recursion.hpp:84
A type that satisfies std::is_arithmetic_v<t>.
The generic simd concept.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
A strong type of underlying type int32_t that represents the score (usually negative) of any characte...
Definition align_config_gap_cost_affine.hpp:48
A strong type of underlying type int32_t that represents a score (usually negative) that is incurred ...
Definition align_config_gap_cost_affine.hpp:31
A traits type for the alignment algorithm that exposes static information stored within the alignment...
Definition alignment/pairwise/detail/type_traits.hpp:80
std::conditional_t< is_vectorised, simd_type_t< original_score_type >, original_score_type > score_type
The score type for the alignment algorithm.
Definition alignment/pairwise/detail/type_traits.hpp:133
typename std::remove_reference_t< decltype(std::declval< configuration_t >().get_or(align_cfg::score_type< int32_t >{}))>::type original_score_type
The original score type selected by the user.
Definition alignment/pairwise/detail/type_traits.hpp:131
Provides type traits for working with templates.
Provides seqan3::simd::simd_concept.
Hide me