SeqAn3 3.3.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// -----------------------------------------------------------------------------------------------------
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
15#include <ranges>
16#include <span>
17#include <vector>
18
28
29namespace seqan3::detail
30{
31
50template <typename trace_t>
51 requires std::same_as<trace_t, trace_directions>
53{
54private:
56 using matrix_t =
57 two_dimensional_matrix<trace_t, aligned_allocator<trace_t, sizeof(trace_t)>, matrix_major_order::column>;
61 using virtual_column_t = decltype(views::repeat_n(trace_t{}, 1));
62
63 class iterator;
64
72 size_t column_count{};
74 size_t row_count{};
75
76public:
80 trace_matrix_full() = default;
85 ~trace_matrix_full() = default;
86
88
111 template <std::integral column_index_t, std::integral row_index_t>
113 {
114 this->column_count = column_count.get();
115 this->row_count = row_count.get();
116 complete_matrix.resize(number_rows{this->row_count}, number_cols{this->column_count});
117 horizontal_column.resize(this->row_count);
118 vertical_column = views::repeat_n(trace_t{}, this->row_count);
119 }
120
127 auto trace_path(matrix_coordinate const & trace_begin) const
128 {
129 using matrix_iter_t = std::ranges::iterator_t<matrix_t const>;
130 using trace_iterator_t = trace_iterator<matrix_iter_t>;
131 using path_t = std::ranges::subrange<trace_iterator_t, std::default_sentinel_t>;
132
133 if (trace_begin.row >= row_count || trace_begin.col >= column_count)
134 throw std::invalid_argument{"The given coordinate exceeds the matrix in vertical or horizontal direction."};
135
136 return path_t{trace_iterator_t{complete_matrix.begin() + matrix_offset{trace_begin}}, std::default_sentinel};
137 }
138
144 {
145 return iterator{*this, 0u};
146 }
147
149 iterator begin() const = delete;
150
153 {
154 return iterator{*this, column_count};
155 }
156
158 iterator end() const = delete;
160};
161
171template <typename trace_t>
172 requires std::same_as<trace_t, trace_directions>
174{
175private:
179 using matrix_column_type = decltype(views::zip(std::declval<single_trace_column_type>(),
180 std::declval<physical_column_t &>(),
181 std::declval<virtual_column_t &>()));
184
185 // Defines a proxy that can be converted to the value type.
186 class column_proxy;
187
189 trace_matrix_full * host_ptr{nullptr};
191 size_t current_column_id{};
192
193public:
202 using pointer = void;
208
212 iterator() noexcept = default;
213 iterator(iterator const &) noexcept = default;
214 iterator(iterator &&) noexcept = default;
215 iterator & operator=(iterator const &) noexcept = default;
216 iterator & operator=(iterator &&) noexcept = default;
217 ~iterator() = default;
218
224 explicit iterator(trace_matrix_full & host_matrix, size_t const initial_column_id) noexcept :
225 host_ptr{std::addressof(host_matrix)},
226 current_column_id{initial_column_id}
227 {}
229
235 {
236 auto column_begin = host_ptr->complete_matrix.data() + current_column_id * host_ptr->row_count;
237 single_trace_column_type single_trace_column{column_begin, column_begin + host_ptr->row_count};
238
239 return column_proxy{
240 views::zip(std::move(single_trace_column), host_ptr->horizontal_column, host_ptr->vertical_column)};
241 }
243
249 {
250 ++current_column_id;
251 return *this;
252 }
253
255 void operator++(int)
256 {
257 ++(*this);
258 }
260
265 friend bool operator==(iterator const & lhs, iterator const & rhs) noexcept
266 {
267 return lhs.current_column_id == rhs.current_column_id;
268 }
269
271 friend bool operator!=(iterator const & lhs, iterator const & rhs) noexcept
272 {
273 return !(lhs == rhs);
274 }
276};
277
286template <typename trace_t>
287 requires std::same_as<trace_t, trace_directions>
288class trace_matrix_full<trace_t>::iterator::column_proxy : public std::ranges::view_interface<column_proxy>
289{
290private:
293
294public:
298 column_proxy() = default;
299 column_proxy(column_proxy const &) = default;
301 column_proxy & operator=(column_proxy const &) = default;
303 ~column_proxy() = default;
304
309 explicit column_proxy(matrix_column_type && column) noexcept : column{std::move(column)}
310 {}
312
317 std::ranges::iterator_t<matrix_column_type> begin()
318 {
319 return column.begin();
320 }
322 std::ranges::iterator_t<matrix_column_type> begin() const = delete;
323
325 std::ranges::sentinel_t<matrix_column_type> end()
326 {
327 return column.end();
328 }
329
331 std::ranges::sentinel_t<matrix_column_type> end() const = delete;
333
335 constexpr operator matrix_column_value_t() const
336 {
337 matrix_column_value_t target{};
339 return target;
340 }
341};
342
343} // 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:77
A trace iterator an unbanded trace matrix.
Definition: trace_iterator.hpp:33
The proxy returned as reference type.
Definition: trace_matrix_full.hpp:289
std::ranges::iterator_t< matrix_column_type > begin()
Returns an iterator to the begin of the column.
Definition: trace_matrix_full.hpp:317
column_proxy(matrix_column_type &&column) noexcept
Initialises the proxy with the respective column.
Definition: trace_matrix_full.hpp:309
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.
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:325
column_proxy & operator=(column_proxy &&)=default
Defaulted.
Trace matrix iterator for the pairwise alignment using the full trace matrix.
Definition: trace_matrix_full.hpp:174
iterator() noexcept=default
Defaulted.
iterator & operator++()
Move this to the next column.
Definition: trace_matrix_full.hpp:248
friend bool operator==(iterator const &lhs, iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition: trace_matrix_full.hpp:265
void operator++(int)
Move this to the next column.
Definition: trace_matrix_full.hpp:255
void pointer
The pointer type.
Definition: trace_matrix_full.hpp:202
friend bool operator!=(iterator const &lhs, iterator const &rhs) noexcept
Tests whether lhs != rhs.
Definition: trace_matrix_full.hpp:271
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:181
reference operator*() const
Returns the range over the current column.
Definition: trace_matrix_full.hpp:234
Trace matrix for the pairwise alignment using the full trace matrix.
Definition: trace_matrix_full.hpp:53
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:72
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:70
iterator begin()
Returns the iterator pointing to the first column.
Definition: trace_matrix_full.hpp:143
iterator end()
Returns the iterator pointing behind the last column.
Definition: trace_matrix_full.hpp:152
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:61
~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:74
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:112
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:66
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:127
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:68
constexpr iterator begin() noexcept
Returns an iterator pointing to the first element of the matrix.
Definition: two_dimensional_matrix.hpp:273
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:237
T copy(T... args)
@ column
The corresponding alignment coordinate will be incrementable/decrementable in the column index.
@ column
Accesses matrix in column major order.
constexpr auto zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition: zip.hpp:573
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:91
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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:32
A representation of a location or offset within a two-dimensional matrix.
Definition: matrix_coordinate.hpp:90
Strong type for setting the column dimension of a matrix.
Definition: two_dimensional_matrix.hpp:32
Strong type for setting the row dimension of a matrix.
Definition: two_dimensional_matrix.hpp:40
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:61
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.