SeqAn3 3.4.1-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
score_matrix_single_column.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <ranges>
13#include <vector>
14
22
23namespace seqan3::detail
24{
25
48template <typename score_t>
51{
52private:
54 using physical_column_t = std::vector<score_t, aligned_allocator<score_t, alignof(score_t)>>;
56 using virtual_column_t = decltype(views::repeat_n(score_t{}, 1));
57
58 class matrix_iterator;
59
61 physical_column_t optimal_column{};
63 physical_column_t horizontal_column{};
65 virtual_column_t vertical_column{};
67 size_t number_of_columns{};
68
69public:
79
81
108 template <std::integral column_index_t, std::integral row_index_t>
109 void resize(column_index_type<column_index_t> const number_of_columns,
110 row_index_type<row_index_t> const number_of_rows,
111 score_t const initial_value = score_t{})
112 {
113 this->number_of_columns = number_of_columns.get();
114 optimal_column.clear();
115 horizontal_column.clear();
117 optimal_column.resize(number_of_rows.get(), initial_value);
119 horizontal_column.resize(number_of_rows.get(), initial_value);
120 vertical_column = views::repeat_n(initial_value, number_of_rows.get());
121 }
122
128 {
129 return matrix_iterator{*this, 0u};
130 }
131
133 matrix_iterator begin() const = delete;
134
137 {
138 return matrix_iterator{*this, number_of_columns};
139 }
140
142 matrix_iterator end() const = delete;
144};
145
157template <typename score_t>
160{
161private:
163 using matrix_column_t = decltype(views::zip(std::declval<physical_column_t &>(),
164 std::declval<physical_column_t &>(),
165 std::declval<virtual_column_t &>()));
166
168 static constexpr auto transform_to_affine_cell = std::views::transform(
169 [](auto && tpl) -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
170 {
171 using fwd_tuple_t = decltype(tpl);
172 return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
173 });
174
176 score_matrix_single_column * host_ptr{nullptr};
178 size_t current_column_id{};
179
180public:
185 using value_type = decltype(std::declval<matrix_column_t>() | transform_to_affine_cell);
189 using pointer = void;
195
199 matrix_iterator() noexcept = default;
200 matrix_iterator(matrix_iterator const &) noexcept = default;
201 matrix_iterator(matrix_iterator &&) noexcept = default;
202 matrix_iterator & operator=(matrix_iterator const &) noexcept = default;
203 matrix_iterator & operator=(matrix_iterator &&) noexcept = default;
204 ~matrix_iterator() = default;
205
211 explicit matrix_iterator(score_matrix_single_column & host_matrix, size_t const initial_column_id) noexcept :
212 host_ptr{std::addressof(host_matrix)},
213 current_column_id{initial_column_id}
214 {}
216
222 {
223 return views::zip(host_ptr->optimal_column, host_ptr->horizontal_column, host_ptr->vertical_column)
224 | transform_to_affine_cell;
225 }
227
233 {
234 ++current_column_id;
235 return *this;
236 }
237
239 void operator++(int)
240 {
241 ++(*this);
242 }
244
249 friend bool operator==(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
250 {
251 return lhs.current_column_id == rhs.current_column_id;
252 }
253
255 friend bool operator!=(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
256 {
257 return !(lhs == rhs);
258 }
260};
261
262} // namespace seqan3::detail
T addressof(T... args)
Provides seqan3::detail::affine_cell_proxy.
Provides seqan3::aligned_allocator.
Allocates uninitialized storage whose memory-alignment is specified by alignment.
Definition aligned_allocator.hpp:70
A proxy for an affine score matrix cell.
Definition affine_cell_proxy.hpp:114
Score matrix iterator for the pairwise alignment using only a single column.
Definition score_matrix_single_column.hpp:160
decltype(std::declval< matrix_column_t >()|transform_to_affine_cell) value_type
The value type.
Definition score_matrix_single_column.hpp:185
reference operator*() const
Returns the range over the current column.
Definition score_matrix_single_column.hpp:221
void pointer
The pointer type.
Definition score_matrix_single_column.hpp:189
value_type reference
The reference type.
Definition score_matrix_single_column.hpp:187
friend bool operator!=(matrix_iterator const &lhs, matrix_iterator const &rhs) noexcept
Tests whether lhs != rhs.
Definition score_matrix_single_column.hpp:255
matrix_iterator & operator++()
Move this to the next column.
Definition score_matrix_single_column.hpp:232
friend bool operator==(matrix_iterator const &lhs, matrix_iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition score_matrix_single_column.hpp:249
decltype(views::zip(std::declval< physical_column_t & >(), std::declval< physical_column_t & >(), std::declval< virtual_column_t & >())) matrix_column_t
The type of the zipped score column.
Definition score_matrix_single_column.hpp:165
void operator++(int)
Move this to the next column.
Definition score_matrix_single_column.hpp:239
Score matrix for the pairwise alignment using only a single column.
Definition score_matrix_single_column.hpp:51
decltype(views::repeat_n(score_t{}, 1)) virtual_column_t
The type of the virtual score column which only stores one value.
Definition score_matrix_single_column.hpp:56
score_matrix_single_column(score_matrix_single_column &&)=default
Defaulted.
void resize(column_index_type< column_index_t > const number_of_columns, row_index_type< row_index_t > const number_of_rows, score_t const initial_value=score_t{})
Resizes the matrix.
Definition score_matrix_single_column.hpp:109
matrix_iterator begin()
Returns the iterator pointing to the first column.
Definition score_matrix_single_column.hpp:127
score_matrix_single_column & operator=(score_matrix_single_column const &)=default
Defaulted.
matrix_iterator end()
Returns the iterator pointing behind the last column.
Definition score_matrix_single_column.hpp:136
matrix_iterator end() const =delete
This score matrix is not const-iterable.
matrix_iterator begin() const =delete
This score matrix is not const-iterable.
score_matrix_single_column(score_matrix_single_column const &)=default
Defaulted.
score_matrix_single_column & operator=(score_matrix_single_column &&)=default
Defaulted.
constexpr value_t & get() &noexcept
Returns the underlying value.
Definition strong_type.hpp:198
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
A type that satisfies std::is_arithmetic_v<t>.
The generic simd concept.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START(...)
Denotes the start of a block where diagnostics are ignored.
Definition platform.hpp:268
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
Denotes the end of a block where diagnostics are ignored.
Definition platform.hpp:277
Provides seqan3::views::repeat_n.
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::simd::simd_concept.
Provides seqan3::views::zip.
Hide me