SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
combined_score_and_trace_matrix.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
10#pragma once
11
12#include <ranges>
13
19
20namespace seqan3::detail
21{
41template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
42 requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
43 && std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
45{
46private:
49
50 class iterator;
51 class sentinel;
52
54 score_matrix_t score_matrix{};
56 trace_matrix_t trace_matrix{};
57
58public:
68
70
91 template <std::integral column_index_t, std::integral row_index_t>
93 row_index_type<row_index_t> const row_count,
94 score_type const initial_score = score_type{})
95 {
96 score_matrix_t tmp_score_matrix{};
97 tmp_score_matrix.resize(column_count, row_count, initial_score);
98
99 trace_matrix_t tmp_trace_matrix{};
100 tmp_trace_matrix.resize(column_count, row_count);
101
102 score_matrix = std::move(tmp_score_matrix);
103 trace_matrix = std::move(tmp_trace_matrix);
104 }
105
111 {
112 return iterator{score_matrix.begin(), trace_matrix.begin()};
113 }
114
116 iterator begin() const = delete;
117
120 {
121 return sentinel{score_matrix.end()};
122 }
123
125 sentinel end() const = delete;
127
136 auto trace_path(matrix_coordinate const & from_coordinate) const
137 {
138 return trace_matrix.trace_path(from_coordinate);
139 }
140};
141
153template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
154 requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
155 && std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
157{
158private:
160 using score_matrix_reference_type = std::ranges::range_reference_t<score_matrix_t>;
162 using trace_matrix_reference_type = std::ranges::range_reference_t<trace_matrix_t>;
163
164 static_assert(std::ranges::viewable_range<score_matrix_reference_type>);
165 static_assert(std::ranges::viewable_range<trace_matrix_reference_type>);
166
169 decltype(views::zip(std::declval<score_matrix_reference_type>(), std::declval<trace_matrix_reference_type>()));
171 using score_matrix_iter_type = std::ranges::iterator_t<score_matrix_t>;
173 using trace_matrix_iter_type = std::ranges::iterator_t<trace_matrix_t>;
174
175 // Befriend the base class.
176 template <std::ranges::input_range other_score_matrix_t, std::ranges::input_range other_trace_matrix_t>
177 requires (std::ranges::input_range<std::ranges::range_reference_t<other_score_matrix_t>>
178 && std::ranges::input_range<std::ranges::range_reference_t<other_trace_matrix_t>>)
180
182 static constexpr auto transform_to_combined_matrix_cell = std::views::transform(
183 [](auto && tpl) -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
184 {
185 using fwd_tuple_t = decltype(tpl);
186 return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
187 });
188
193
194public:
199 using value_type = decltype(std::declval<combined_column_type>() | transform_to_combined_matrix_cell);
203 using pointer = void;
209
213 iterator() = default;
214 iterator(iterator const &) = default;
215 iterator(iterator &&) = default;
216 iterator & operator=(iterator const &) = default;
217 iterator & operator=(iterator &&) = default;
218 ~iterator() = default;
219
225 explicit iterator(score_matrix_iter_type score_matrix_it, trace_matrix_iter_type trace_matrix_it) noexcept :
226 score_matrix_it{std::move(score_matrix_it)},
227 trace_matrix_it{std::move(trace_matrix_it)}
228 {}
230
236 {
237 return views::zip(*score_matrix_it, *trace_matrix_it) | transform_to_combined_matrix_cell;
238 }
240
246 {
247 ++score_matrix_it;
248 ++trace_matrix_it;
249 return *this;
250 }
251
253 void operator++(int)
254 {
255 ++(*this);
256 }
258};
259
267template <std::ranges::input_range score_matrix_t, std::ranges::input_range trace_matrix_t>
268 requires (std::ranges::input_range<std::ranges::range_reference_t<score_matrix_t>>
269 && std::ranges::input_range<std::ranges::range_reference_t<trace_matrix_t>>)
271{
272private:
274 using score_matrix_sentinel_type = std::ranges::sentinel_t<score_matrix_t>;
275
277 score_matrix_sentinel_type score_matrix_sentinel{};
278
279public:
283 sentinel() = default;
284 sentinel(sentinel const &) = default;
285 sentinel(sentinel &&) = default;
286 sentinel & operator=(sentinel const &) = default;
287 sentinel & operator=(sentinel &&) = default;
288 ~sentinel() = default;
289
294 explicit sentinel(score_matrix_sentinel_type score_matrix_sentinel) noexcept :
295 score_matrix_sentinel{std::move(score_matrix_sentinel)}
296 {}
298
303 friend bool operator==(iterator const & lhs, sentinel const & rhs) noexcept
304 {
305 return rhs.equal(lhs);
306 }
307
309 friend bool operator==(sentinel const & lhs, iterator const & rhs) noexcept
310 {
311 return rhs == lhs;
312 }
313
315 friend bool operator!=(iterator const & lhs, sentinel const & rhs) noexcept
316 {
317 return !(lhs == rhs);
318 }
319
321 friend bool operator!=(sentinel const & lhs, iterator const & rhs) noexcept
322 {
323 return !(lhs == rhs);
324 }
326
327private:
337 constexpr bool equal(iterator const & iter) const noexcept
338 {
339 return iter.score_matrix_it == score_matrix_sentinel;
340 }
341};
342
343} // namespace seqan3::detail
Provides seqan3::detail::affine_cell_proxy.
A proxy for an affine score matrix cell.
Definition affine_cell_proxy.hpp:114
Combined score and trace matrix iterator for the pairwise sequence alignment.
Definition combined_score_and_trace_matrix.hpp:157
void operator++(int)
Advance the iterator to the next alignment matrix column.
Definition combined_score_and_trace_matrix.hpp:253
std::ranges::iterator_t< trace_matrix_t > trace_matrix_iter_type
The type of the trace matrix iterator.
Definition combined_score_and_trace_matrix.hpp:173
iterator & operator=(iterator &&)=default
Defaulted.
iterator & operator++()
Advance the iterator to the next alignment matrix column.
Definition combined_score_and_trace_matrix.hpp:245
value_type reference
The reference type.
Definition combined_score_and_trace_matrix.hpp:201
reference operator*() const
Returns the range over the current column.
Definition combined_score_and_trace_matrix.hpp:235
void pointer
The pointer type.
Definition combined_score_and_trace_matrix.hpp:203
std::ranges::range_reference_t< score_matrix_t > score_matrix_reference_type
The reference type of the score matrix.
Definition combined_score_and_trace_matrix.hpp:160
iterator & operator=(iterator const &)=default
Defaulted.
decltype(std::declval< combined_column_type >()|transform_to_combined_matrix_cell) value_type
The value type.
Definition combined_score_and_trace_matrix.hpp:199
score_matrix_iter_type score_matrix_it
The current iterator over the score matrix.
Definition combined_score_and_trace_matrix.hpp:190
std::ranges::iterator_t< score_matrix_t > score_matrix_iter_type
The type of the score matrix iterator.
Definition combined_score_and_trace_matrix.hpp:171
iterator(score_matrix_iter_type score_matrix_it, trace_matrix_iter_type trace_matrix_it) noexcept
Initialises the iterator from the underlying matrix.
Definition combined_score_and_trace_matrix.hpp:225
std::ranges::range_reference_t< trace_matrix_t > trace_matrix_reference_type
The reference type of the trace matrix.
Definition combined_score_and_trace_matrix.hpp:162
trace_matrix_iter_type trace_matrix_it
The current iterator over the trace matrix.
Definition combined_score_and_trace_matrix.hpp:192
decltype(views::zip(std::declval< score_matrix_reference_type >(), std::declval< trace_matrix_reference_type >())) combined_column_type
The combined column type.
Definition combined_score_and_trace_matrix.hpp:169
The sentinel type for the seqan3::detail::combined_score_and_trace_matrix.
Definition combined_score_and_trace_matrix.hpp:271
friend bool operator==(iterator const &lhs, sentinel const &rhs) noexcept
Checks if the iterator reached the end of the matrix.
Definition combined_score_and_trace_matrix.hpp:303
friend bool operator!=(iterator const &lhs, sentinel const &rhs) noexcept
Checks if the iterator did not reach the end of the matrix.
Definition combined_score_and_trace_matrix.hpp:315
constexpr bool equal(iterator const &iter) const noexcept
Compares the stored score matrix sentinel with the given iterator.
Definition combined_score_and_trace_matrix.hpp:337
friend bool operator!=(sentinel const &lhs, iterator const &rhs) noexcept
Checks if the iterator did not reach the end of the matrix.
Definition combined_score_and_trace_matrix.hpp:321
sentinel & operator=(sentinel const &)=default
Defaulted.
friend bool operator==(sentinel const &lhs, iterator const &rhs) noexcept
Checks if the iterator reached the end of the matrix.
Definition combined_score_and_trace_matrix.hpp:309
sentinel(score_matrix_sentinel_type score_matrix_sentinel) noexcept
Initialises the sentinel from the underlying matrix.
Definition combined_score_and_trace_matrix.hpp:294
sentinel & operator=(sentinel &&)=default
Defaulted.
std::ranges::sentinel_t< score_matrix_t > score_matrix_sentinel_type
The sentinel type of the underlying score matrix.
Definition combined_score_and_trace_matrix.hpp:274
An alignment matrix that combines a score matrix with a trace matrix into a common interface.
Definition combined_score_and_trace_matrix.hpp:45
sentinel end() const =delete
This alignment matrix is not const-iterable.
auto trace_path(matrix_coordinate const &from_coordinate) const
Returns a trace path starting from the given coordinate and ending in the cell with seqan3::detail::t...
Definition combined_score_and_trace_matrix.hpp:136
combined_score_and_trace_matrix & operator=(combined_score_and_trace_matrix const &)=default
Defaulted.
void resize(column_index_type< column_index_t > const column_count, row_index_type< row_index_t > const row_count, score_type const initial_score=score_type{})
Resizes the matrix.
Definition combined_score_and_trace_matrix.hpp:92
combined_score_and_trace_matrix(combined_score_and_trace_matrix &&)=default
Defaulted.
iterator begin()
Returns the iterator pointing to the first alignment column.
Definition combined_score_and_trace_matrix.hpp:110
combined_score_and_trace_matrix & operator=(combined_score_and_trace_matrix &&)=default
Defaulted.
combined_score_and_trace_matrix(combined_score_and_trace_matrix const &)=default
Defaulted.
iterator begin() const =delete
This score matrix is not const-iterable.
sentinel end()
Returns the sentinel pointing behind the last alignment column.
Definition combined_score_and_trace_matrix.hpp:119
Provides various transformation traits used by the range module.
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
A strong type for designated initialisation of the column index of a matrix.
Definition matrix_coordinate.hpp:29
A strong type for designated initialisation of the row index of a matrix.
Definition matrix_coordinate.hpp:58
Provides concepts that do not have equivalents in C++20.
Provides seqan3::views::zip.
Hide me