SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
trace_matrix_full.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#include <span>
14#include <vector>
15
25
26namespace seqan3::detail
27{
28
47template <typename trace_t>
48 requires std::same_as<trace_t, trace_directions>
50{
51private:
53 using matrix_t =
54 two_dimensional_matrix<trace_t, aligned_allocator<trace_t, sizeof(trace_t)>, matrix_major_order::column>;
58 using virtual_column_t = decltype(views::repeat_n(trace_t{}, 1));
59
60 class iterator;
61
69 size_t column_count{};
71 size_t row_count{};
72
73public:
77 trace_matrix_full() = default;
82 ~trace_matrix_full() = default;
83
85
108 template <std::integral column_index_t, std::integral row_index_t>
110 {
111 this->column_count = column_count.get();
112 this->row_count = row_count.get();
113 complete_matrix.resize(number_rows{this->row_count}, number_cols{this->column_count});
114 horizontal_column.resize(this->row_count);
115 vertical_column = views::repeat_n(trace_t{}, this->row_count);
116 }
117
124 auto trace_path(matrix_coordinate const & trace_begin) const
125 {
126 using matrix_iter_t = std::ranges::iterator_t<matrix_t const>;
127 using trace_iterator_t = trace_iterator<matrix_iter_t>;
128 using path_t = std::ranges::subrange<trace_iterator_t, std::default_sentinel_t>;
129
130 if (trace_begin.row >= row_count || trace_begin.col >= column_count)
131 throw std::invalid_argument{"The given coordinate exceeds the matrix in vertical or horizontal direction."};
132
133 return path_t{trace_iterator_t{complete_matrix.begin() + matrix_offset{trace_begin}}, std::default_sentinel};
134 }
135
141 {
142 return iterator{*this, 0u};
143 }
144
146 iterator begin() const = delete;
147
150 {
151 return iterator{*this, column_count};
152 }
153
155 iterator end() const = delete;
157};
158
168template <typename trace_t>
169 requires std::same_as<trace_t, trace_directions>
171{
172private:
176 using matrix_column_type = decltype(views::zip(std::declval<single_trace_column_type>(),
177 std::declval<physical_column_t &>(),
178 std::declval<virtual_column_t &>()));
181
182 // Defines a proxy that can be converted to the value type.
183 class column_proxy;
184
186 trace_matrix_full * host_ptr{nullptr};
188 size_t current_column_id{};
189
190public:
199 using pointer = void;
205
209 iterator() noexcept = default;
210 iterator(iterator const &) noexcept = default;
211 iterator(iterator &&) noexcept = default;
212 iterator & operator=(iterator const &) noexcept = default;
213 iterator & operator=(iterator &&) noexcept = default;
214 ~iterator() = default;
215
221 explicit iterator(trace_matrix_full & host_matrix, size_t const initial_column_id) noexcept :
222 host_ptr{std::addressof(host_matrix)},
223 current_column_id{initial_column_id}
224 {}
226
232 {
233 auto column_begin = host_ptr->complete_matrix.data() + current_column_id * host_ptr->row_count;
234 single_trace_column_type single_trace_column{column_begin, column_begin + host_ptr->row_count};
235
236 return column_proxy{
237 views::zip(std::move(single_trace_column), host_ptr->horizontal_column, host_ptr->vertical_column)};
238 }
240
246 {
247 ++current_column_id;
248 return *this;
249 }
250
252 void operator++(int)
253 {
254 ++(*this);
255 }
257
262 friend bool operator==(iterator const & lhs, iterator const & rhs) noexcept
263 {
264 return lhs.current_column_id == rhs.current_column_id;
265 }
266
268 friend bool operator!=(iterator const & lhs, iterator const & rhs) noexcept
269 {
270 return !(lhs == rhs);
271 }
273};
274
283template <typename trace_t>
284 requires std::same_as<trace_t, trace_directions>
285class trace_matrix_full<trace_t>::iterator::column_proxy : public std::ranges::view_interface<column_proxy>
286{
287private:
290
291public:
295 column_proxy() = default;
296 column_proxy(column_proxy const &) = default;
298 column_proxy & operator=(column_proxy const &) = default;
300 ~column_proxy() = default;
301
306 explicit column_proxy(matrix_column_type && column) noexcept : column{std::move(column)}
307 {}
309
314 std::ranges::iterator_t<matrix_column_type> begin()
315 {
316 return column.begin();
317 }
319 std::ranges::iterator_t<matrix_column_type> begin() const = delete;
320
322 std::ranges::sentinel_t<matrix_column_type> end()
323 {
324 return column.end();
325 }
326
328 std::ranges::sentinel_t<matrix_column_type> end() const = delete;
330
332 constexpr operator matrix_column_value_t() const
333 {
334 matrix_column_value_t target{};
336 return target;
337 }
338};
339
340} // namespace seqan3::detail
T addressof(T... args)
Provides seqan3::aligned_allocator.
T back_inserter(T... args)
Allocates uninitialized storage whose memory-alignment is specified by alignment.
Definition aligned_allocator.hpp:74
constexpr value_t & get() &noexcept
Returns the underlying value.
Definition strong_type.hpp:201
A trace iterator an unbanded trace matrix.
Definition trace_iterator.hpp:30
The proxy returned as reference type.
Definition trace_matrix_full.hpp:286
std::ranges::iterator_t< matrix_column_type > begin()
Returns an iterator to the begin of the column.
Definition trace_matrix_full.hpp:314
column_proxy(matrix_column_type &&column) noexcept
Initialises the proxy with the respective column.
Definition trace_matrix_full.hpp:306
std::ranges::iterator_t< matrix_column_type > begin() const =delete
Const iterator is not accessible.
std::ranges::sentinel_t< matrix_column_type > end() const =delete
Const sentinel is not accessible.
matrix_column_type column
The represented column.
Definition trace_matrix_full.hpp:289
column_proxy & operator=(column_proxy const &)=default
Defaulted.
column_proxy(column_proxy const &)=default
Defaulted.
std::ranges::sentinel_t< matrix_column_type > end()
Returns a sentinel marking the end of the column.
Definition trace_matrix_full.hpp:322
column_proxy & operator=(column_proxy &&)=default
Defaulted.
Trace matrix iterator for the pairwise alignment using the full trace matrix.
Definition trace_matrix_full.hpp:171
iterator() noexcept=default
Defaulted.
iterator & operator++()
Move this to the next column.
Definition trace_matrix_full.hpp:245
friend bool operator==(iterator const &lhs, iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition trace_matrix_full.hpp:262
void operator++(int)
Move this to the next column.
Definition trace_matrix_full.hpp:252
void pointer
The pointer type.
Definition trace_matrix_full.hpp:199
friend bool operator!=(iterator const &lhs, iterator const &rhs) noexcept
Tests whether lhs != rhs.
Definition trace_matrix_full.hpp:268
decltype(views::zip(std::declval< single_trace_column_type >(), std::declval< physical_column_t & >(), std::declval< virtual_column_t & >())) matrix_column_type
The type of the zipped score column.
Definition trace_matrix_full.hpp:178
reference operator*() const
Returns the range over the current column.
Definition trace_matrix_full.hpp:231
Trace matrix for the pairwise alignment using the full trace matrix.
Definition trace_matrix_full.hpp:50
iterator end() const =delete
This score matrix is not const-iterable.
trace_matrix_full(trace_matrix_full &&)=default
Defaulted.
size_t column_count
The number of columns for this matrix.
Definition trace_matrix_full.hpp:69
trace_matrix_full & operator=(trace_matrix_full &&)=default
Defaulted.
virtual_column_t vertical_column
The virtual column over the vertical traces.
Definition trace_matrix_full.hpp:67
iterator begin()
Returns the iterator pointing to the first column.
Definition trace_matrix_full.hpp:140
iterator end()
Returns the iterator pointing behind the last column.
Definition trace_matrix_full.hpp:149
decltype(views::repeat_n(trace_t{}, 1)) virtual_column_t
The type of the virtual score column which only stores one value.
Definition trace_matrix_full.hpp:58
~trace_matrix_full()=default
Defaulted.
trace_matrix_full()=default
Defaulted.
size_t row_count
The number of rows for this matrix.
Definition trace_matrix_full.hpp:71
void resize(column_index_type< column_index_t > const column_count, row_index_type< row_index_t > const row_count)
Resizes the matrix.
Definition trace_matrix_full.hpp:109
trace_matrix_full & operator=(trace_matrix_full const &)=default
Defaulted.
trace_matrix_full(trace_matrix_full const &)=default
Defaulted.
matrix_t complete_matrix
The full trace matrix.
Definition trace_matrix_full.hpp:63
auto trace_path(matrix_coordinate const &trace_begin) const
Returns a trace path starting from the given coordinate and ending in the cell with seqan3::detail::t...
Definition trace_matrix_full.hpp:124
iterator begin() const =delete
This score matrix is not const-iterable.
physical_column_t horizontal_column
The column over the horizontal traces.
Definition trace_matrix_full.hpp:65
constexpr iterator begin() noexcept
Returns an iterator pointing to the first element of the matrix.
Definition two_dimensional_matrix.hpp:270
void resize(number_rows const row_dim, number_cols const col_dim)
Resizes the underlying matrix storage to the given matrix dimensions.
Definition two_dimensional_matrix.hpp:234
T copy(T... args)
@ column
The corresponding alignment coordinate will be incrementable/decrementable in the column index.
@ column
Accesses matrix in column major order.
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
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::views::repeat_n.
T resize(T... args)
A strong type for designated initialisation of the column index of a matrix.
Definition matrix_coordinate.hpp:29
A representation of a location or offset within a two-dimensional matrix.
Definition matrix_coordinate.hpp:87
Strong type for setting the column dimension of a matrix.
Definition two_dimensional_matrix.hpp:29
Strong type for setting the row dimension of a matrix.
Definition two_dimensional_matrix.hpp:37
A strong type for designated initialisation of the row index of a matrix.
Definition matrix_coordinate.hpp:58
Provides type traits for working with templates.
Provides the declaration of seqan3::detail::trace_directions.
Provides seqan3::detail::trace_iterator.
Provides seqan3::detail::two_dimensional_matrix.
Provides concepts that do not have equivalents in C++20.
Provides seqan3::views::zip.
Hide me