SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
policy_affine_gap_with_trace_recursion.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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
16
17namespace seqan3::detail
18{
19
25template <typename alignment_configuration_t>
26class policy_affine_gap_with_trace_recursion : protected policy_affine_gap_recursion<alignment_configuration_t>
27{
28protected:
31
32 // Import base types.
33 using typename base_t::affine_score_tuple_t;
34 using typename base_t::score_type;
35 using typename base_t::traits_type;
36
43
44 // Import base member.
49
61
63 explicit policy_affine_gap_with_trace_recursion(alignment_configuration_t const & config) : base_t{config}
64 {}
66
68 template <typename affine_cell_t>
70 affine_cell_t previous_cell,
71 score_type const sequence_score) const noexcept
72 {
73 diagonal_score += sequence_score;
74 score_type horizontal_score = previous_cell.horizontal_score();
75 score_type vertical_score = previous_cell.vertical_score();
77
78 diagonal_score = (diagonal_score < vertical_score)
79 ? (best_trace = previous_cell.vertical_trace(), vertical_score)
80 : (best_trace |= previous_cell.vertical_trace(), diagonal_score);
81 diagonal_score =
82 (diagonal_score < horizontal_score)
83 ? (best_trace = previous_cell.horizontal_trace() | (best_trace & trace_directions::carry_up_open),
84 horizontal_score)
85 : (best_trace |= previous_cell.horizontal_trace(), diagonal_score);
86
87 score_type tmp = diagonal_score + gap_open_score;
88 vertical_score += gap_extension_score;
89 horizontal_score += gap_extension_score;
90
91 // store the vertical_score and horizontal_score value in the next path
92 trace_directions next_vertical_trace = trace_directions::up;
93 trace_directions next_horizontal_trace = trace_directions::left;
94
95 vertical_score =
96 (vertical_score < tmp) ? (next_vertical_trace = trace_directions::up_open, tmp) : vertical_score;
97 horizontal_score =
98 (horizontal_score < tmp) ? (next_horizontal_trace = trace_directions::left_open, tmp) : horizontal_score;
99
100 return {{diagonal_score, horizontal_score, vertical_score},
101 {best_trace, next_horizontal_trace, next_vertical_trace}};
102 }
103
106 {
111 }
112
114 template <typename affine_cell_t>
115 affine_cell_type initialise_first_column_cell(affine_cell_t previous_cell) const noexcept
116 {
117 return {base_t::initialise_first_column_cell(previous_cell),
118 {previous_cell.vertical_trace(),
121 }
122
124 template <typename affine_cell_t>
125 affine_cell_type initialise_first_row_cell(affine_cell_t previous_cell) const noexcept
126 {
127 return {base_t::initialise_first_row_cell(previous_cell),
128 {previous_cell.horizontal_trace(),
131 }
132};
133} // namespace seqan3::detail
A proxy for an affine score matrix cell.
Definition: affine_cell_proxy.hpp:117
decltype(auto) horizontal_score() &noexcept
Access the horizontal score of the wrapped score matrix cell.
Definition: affine_cell_proxy.hpp:213
decltype(auto) vertical_trace() &noexcept
Access the vertical score of the wrapped score matrix cell.
Definition: affine_cell_proxy.hpp:310
decltype(auto) horizontal_trace() &noexcept
Access the horizontal score of the wrapped score matrix cell.
Definition: affine_cell_proxy.hpp:285
Implements the alignment recursion function for the alignment algorithm using affine gap costs.
Definition: policy_affine_gap_recursion.hpp:45
bool first_row_is_free
Initialisation state of the first row of the alignment.
Definition: policy_affine_gap_recursion.hpp:64
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:197
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:152
score_type gap_extension_score
The score for a gap extension.
Definition: policy_affine_gap_recursion.hpp:59
typename traits_type::score_type score_type
The configured score type.
Definition: policy_affine_gap_recursion.hpp:52
score_type gap_open_score
The score for a gap opening including the gap extension.
Definition: policy_affine_gap_recursion.hpp:61
bool first_column_is_free
Initialisation state of the first column of the alignment.
Definition: policy_affine_gap_recursion.hpp:66
std::tuple< score_type, score_type, score_type > affine_score_tuple_t
The internal tuple storing the scores of an affine cell.
Definition: policy_affine_gap_recursion.hpp:54
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:174
alignment_configuration_traits< alignment_configuration_t > traits_type
The configuration traits type.
Definition: policy_affine_gap_recursion.hpp:48
Implements the alignment recursion function for the alignment algorithm using affine gap costs with t...
Definition: policy_affine_gap_with_trace_recursion.hpp:27
policy_affine_gap_with_trace_recursion(policy_affine_gap_with_trace_recursion const &)=default
Defaulted.
policy_affine_gap_with_trace_recursion(alignment_configuration_t const &config)
Defaulted.
Definition: policy_affine_gap_with_trace_recursion.hpp:63
policy_affine_gap_with_trace_recursion & operator=(policy_affine_gap_with_trace_recursion const &)=default
Defaulted.
bool first_row_is_free
Initialisation state of the first row of the alignment.
Definition: policy_affine_gap_recursion.hpp:64
policy_affine_gap_with_trace_recursion(policy_affine_gap_with_trace_recursion &&)=default
Defaulted.
typename traits_type::trace_type trace_type
The trace type to use.
Definition: policy_affine_gap_with_trace_recursion.hpp:38
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_with_trace_recursion.hpp:115
score_type gap_extension_score
The score for a gap extension.
Definition: policy_affine_gap_recursion.hpp:59
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_with_trace_recursion.hpp:105
score_type gap_open_score
The score for a gap opening including the gap extension.
Definition: policy_affine_gap_recursion.hpp:61
bool first_column_is_free
Initialisation state of the first column of the alignment.
Definition: policy_affine_gap_recursion.hpp:66
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_with_trace_recursion.hpp:69
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_with_trace_recursion.hpp:125
policy_affine_gap_with_trace_recursion & operator=(policy_affine_gap_with_trace_recursion &&)=default
Defaulted.
trace_directions
The possible directions a trace can have. The values can be combined by the logical |-operator.
Definition: trace_directions.hpp:29
@ up
Trace comes from the above entry.
@ left
Trace comes from the left entry.
@ diagonal
Trace comes from the diagonal entry.
@ carry_up_open
Carry bit for the last up open even if it is not the maximum value.
@ 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 internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides seqan3::detail::policy_affine_gap_recursion.
std::conditional_t< is_vectorised, simd_type_t< original_score_type >, trace_directions > trace_type
The trace directions type for the alignment algorithm.
Definition: alignment/pairwise/detail/type_traits.hpp:138