SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
score_matrix_single_column.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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 <seqan3/std/ranges>
16#include <vector>
17
25
26namespace seqan3::detail
27{
28
51template <typename score_t>
56{
57private:
59 using physical_column_t = std::vector<score_t, aligned_allocator<score_t, alignof(score_t)>>;
61 using virtual_column_t = decltype(views::repeat_n(score_t{}, 1));
62
63 class matrix_iterator;
64
66 physical_column_t optimal_column{};
68 physical_column_t horizontal_column{};
70 virtual_column_t vertical_column{};
72 size_t number_of_columns{};
73
74public:
84
86
113 template <std::integral column_index_t, std::integral row_index_t>
114 void resize(column_index_type<column_index_t> const number_of_columns,
115 row_index_type<row_index_t> const number_of_rows,
116 score_t const initial_value = score_t{})
117 {
118 this->number_of_columns = number_of_columns.get();
119 optimal_column.clear();
120 horizontal_column.clear();
121 optimal_column.resize(number_of_rows.get(), initial_value);
122 horizontal_column.resize(number_of_rows.get(), initial_value);
123 vertical_column = views::repeat_n(initial_value, number_of_rows.get());
124 }
125
131 {
132 return matrix_iterator{*this, 0u};
133 }
134
136 matrix_iterator begin() const = delete;
137
140 {
141 return matrix_iterator{*this, number_of_columns};
142 }
143
145 matrix_iterator end() const = delete;
147};
148
160template <typename score_t>
165{
166private:
167
169 using matrix_column_t = decltype(views::zip(std::declval<physical_column_t &>(),
170 std::declval<physical_column_t &>(),
171 std::declval<virtual_column_t &>()));
172
174 static constexpr auto transform_to_affine_cell = std::views::transform([] (auto && tpl)
175 -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
176 {
177 using fwd_tuple_t = decltype(tpl);
178 return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
179 });
180
182 score_matrix_single_column * host_ptr{nullptr};
184 size_t current_column_id{};
185
186public:
191 using value_type = decltype(std::declval<matrix_column_t>() | transform_to_affine_cell);
195 using pointer = void;
201
205 matrix_iterator() noexcept = default;
206 matrix_iterator(matrix_iterator const &) noexcept = default;
207 matrix_iterator(matrix_iterator &&) noexcept = default;
208 matrix_iterator & operator=(matrix_iterator const &) noexcept = default;
209 matrix_iterator & operator=(matrix_iterator &&) noexcept = default;
210 ~matrix_iterator() = default;
211
217 explicit matrix_iterator(score_matrix_single_column & host_matrix, size_t const initial_column_id) noexcept :
218 host_ptr{std::addressof(host_matrix)},
219 current_column_id{initial_column_id}
220 {}
222
228 {
229 return views::zip(host_ptr->optimal_column, host_ptr->horizontal_column, host_ptr->vertical_column)
230 | transform_to_affine_cell;
231 }
233
239 {
240 ++current_column_id;
241 return *this;
242 }
243
245 void operator++(int)
246 {
247 ++(*this);
248 }
250
255 friend bool operator==(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
256 {
257 return lhs.current_column_id == rhs.current_column_id;
258 }
259
261 friend bool operator!=(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
262 {
263 return !(lhs == rhs);
264 }
266};
267
268} // 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:77
A proxy for an affine score matrix cell.
Definition: affine_cell_proxy.hpp:122
Score matrix iterator for the pairwise alignment using only a single column.
Definition: score_matrix_single_column.hpp:165
decltype(std::declval< matrix_column_t >()|transform_to_affine_cell) value_type
The value type.
Definition: score_matrix_single_column.hpp:191
reference operator*() const
Returns the range over the current column.
Definition: score_matrix_single_column.hpp:227
void pointer
The pointer type.
Definition: score_matrix_single_column.hpp:195
value_type reference
The reference type.
Definition: score_matrix_single_column.hpp:193
friend bool operator!=(matrix_iterator const &lhs, matrix_iterator const &rhs) noexcept
Tests whether lhs != rhs.
Definition: score_matrix_single_column.hpp:261
matrix_iterator & operator++()
Move this to the next column.
Definition: score_matrix_single_column.hpp:238
friend bool operator==(matrix_iterator const &lhs, matrix_iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition: score_matrix_single_column.hpp:255
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:171
void operator++(int)
Move this to the next column.
Definition: score_matrix_single_column.hpp:245
Score matrix for the pairwise alignment using only a single column.
Definition: score_matrix_single_column.hpp:56
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:61
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:114
matrix_iterator begin()
Returns the iterator pointing to the first column.
Definition: score_matrix_single_column.hpp:130
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:139
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:202
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: traits.hpp:495
constexpr auto zip
A zip view.
Definition: zip.hpp:29
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:91
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:29
The <ranges> header from C++20's standard library.
Provides seqan3::views::repeat_n.
A strong type for designated initialisation of the column index of a matrix.
Definition: matrix_coordinate.hpp:34
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:65
Provides concepts that do not have equivalents in C++20.
Provides seqan3::simd::simd_concept.
Provides seqan3::views::zip.