SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
policy_affine_gap_with_trace_recursion_banded.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
17 namespace seqan3::detail
18 {
19 
25 template <typename alignment_configuration_t>
26 class policy_affine_gap_with_trace_recursion_banded :
27  protected policy_affine_gap_with_trace_recursion<alignment_configuration_t>
28 {
29 protected:
31  using base_t = policy_affine_gap_with_trace_recursion<alignment_configuration_t>;
32  // Import base types.
33  using typename base_t::traits_type;
34  using typename base_t::score_type;
35  using typename base_t::affine_cell_type;
36 
37  // Import base member.
38  using base_t::gap_extension_score;
39  using base_t::gap_open_score;
40 
44  policy_affine_gap_with_trace_recursion_banded() = default;
46  policy_affine_gap_with_trace_recursion_banded(policy_affine_gap_with_trace_recursion_banded const &) = default;
48  policy_affine_gap_with_trace_recursion_banded(policy_affine_gap_with_trace_recursion_banded &&) = default;
49  policy_affine_gap_with_trace_recursion_banded & operator=(policy_affine_gap_with_trace_recursion_banded const &)
50  = default;
51  policy_affine_gap_with_trace_recursion_banded & operator=(policy_affine_gap_with_trace_recursion_banded &&)
52  = default;
53  ~policy_affine_gap_with_trace_recursion_banded() = default;
54 
56  explicit policy_affine_gap_with_trace_recursion_banded(alignment_configuration_t const & config) : base_t{config}
57  {}
59 
61  template <typename affine_cell_t>
62  affine_cell_type initialise_band_first_cell(score_type diagonal_score,
63  affine_cell_t previous_cell,
64  score_type const sequence_score) const noexcept
65  {
66  diagonal_score += sequence_score;
67  score_type horizontal_score = previous_cell.horizontal_score();
68  trace_directions best_trace{};
69 
70  best_trace = previous_cell.horizontal_trace();
71  diagonal_score = (diagonal_score < horizontal_score)
72  ? horizontal_score
73  : (best_trace |= trace_directions::diagonal, diagonal_score);
74 
75  score_type from_optimal_score = diagonal_score + gap_open_score;
76  trace_directions next_horizontal_trace = trace_directions::left;
77 
78  horizontal_score += gap_extension_score;
79  horizontal_score = (horizontal_score < from_optimal_score)
80  ? (next_horizontal_trace = trace_directions::left_open, from_optimal_score)
81  : horizontal_score;
82 
83  return {{diagonal_score, horizontal_score, from_optimal_score},
84  {best_trace, next_horizontal_trace, trace_directions::up_open}};
85  }
86 };
87 } // namespace seqan3::detail
Provides seqan3::detail::policy_affine_gap_with_trace_recursion.