SeqAn3
The Modern C++ library for sequence analysis.
unbanded_score_dp_matrix_policy.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
15 #include <vector>
16 #include <tuple>
17 
18 #include <range/v3/view/iota.hpp>
19 #include <range/v3/view/repeat_n.hpp>
20 #include <range/v3/view/transform.hpp>
21 #include <range/v3/view/zip.hpp>
22 
26 #include <seqan3/std/span>
27 #include <seqan3/std/ranges>
28 
29 namespace seqan3::detail
30 {
31 
37 template <typename derived_t, typename allocator_t>
38 class unbanded_score_dp_matrix_policy
39 {
40 private:
41 
43  friend derived_t;
44 
48  using cell_type = typename allocator_t::value_type;
51  using score_matrix_type = std::vector<cell_type, allocator_t>;
53 
58  constexpr unbanded_score_dp_matrix_policy() = default;
59  constexpr unbanded_score_dp_matrix_policy(unbanded_score_dp_matrix_policy const &) = default;
60  constexpr unbanded_score_dp_matrix_policy(unbanded_score_dp_matrix_policy &&) = default;
61  constexpr unbanded_score_dp_matrix_policy & operator=(unbanded_score_dp_matrix_policy const &) = default;
63  constexpr unbanded_score_dp_matrix_policy & operator=(unbanded_score_dp_matrix_policy &&) = default;
64  ~unbanded_score_dp_matrix_policy() = default;
65 
73  template <typename first_range_t, typename second_range_t>
74  constexpr void allocate_matrix(first_range_t & first_range, second_range_t & second_range)
75  {
76  dimension_first_range = std::ranges::distance(first_range) + 1;
77  dimension_second_range = std::ranges::distance(second_range) + 1;
78 
79  current_column_index = 0;
80 
81  // We use only one column to compute the score.
82  score_matrix.resize(dimension_second_range);
83  }
84 
86  constexpr auto current_column() noexcept
87  {
88  advanceable_alignment_coordinate<advanceable_alignment_coordinate_state::row>
89  col_begin{column_index_type{current_column_index}, row_index_type{0u}};
90  advanceable_alignment_coordinate<advanceable_alignment_coordinate_state::row>
91  col_end{column_index_type{current_column_index}, row_index_type{dimension_second_range}};
92 
93  return std::view::zip(std::span{score_matrix},
94  std::view::iota(col_begin, col_end),
95  ranges::view::repeat_n(std::ignore, dimension_second_range) | std::view::common);
96  }
97 
99  constexpr void go_next_column() noexcept
100  {
101  ++current_column_index;
102  }
103 
105  score_matrix_type score_matrix{};
107  size_t dimension_first_range = 0;
109  size_t dimension_second_range = 0;
111  size_t current_column_index = 0;
112 };
113 
121 inline const auto view_get_score_column = ranges::view::transform([](auto && elem)
122 {
123  using std::get;
124  return get<0>(std::forward<decltype(elem)>(elem));
125 });
126 } // namespace seqan3::detail
::ranges::distance distance
Alias for ranges::distance. Returns the number of hops from first to last.
Definition: iterator:321
constexpr auto zip
A range adaptor that transforms a tuple of range into a range of tuples.
Definition: ranges:948
Provides various shortcuts for common std::ranges functions.
constexpr auto common
A range adaptor that makes any range model std::ranges::CommonRange (at the expense of some performan...
Definition: ranges:447
Adaptations of concepts from the Ranges TS.
Provides std::span from the C++20 standard library.
constexpr auto iota
Generates a sequence of elements by repeatedly incrementing an initial value.
Definition: ranges:647
Definition: aligned_sequence_concept.hpp:35
auto const get
A view calling std::get on each element in a range.
Definition: get.hpp:66
Provides seqan3::detail::alignment_coordinate.
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:97
Provides various transformation traits used by the range module.
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: ranges:911