SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alignment_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 <iterator>
13#include <ranges>
14
20
21namespace seqan3::detail
22{
23
46template <typename trace_t, bool coordinate_only = false>
48 protected alignment_trace_matrix_base<trace_t>,
49 public alignment_matrix_column_major_range_base<alignment_trace_matrix_full<trace_t, coordinate_only>>
50{
51private:
52 static_assert(std::same_as<trace_t, trace_directions> || simd_concept<trace_t>,
53 "Value type must either be a trace_directions object or a simd vector.");
54
60
63
64protected:
71 decltype(std::views::iota(coordinate_type{}, coordinate_type{})),
74 std::views::iota(coordinate_type{}, coordinate_type{})))>;
75
76public:
81 using value_type =
92
96 constexpr alignment_trace_matrix_full() = default;
102
116 template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
118 second_sequence_t && second,
120 {
121 matrix_base_t::num_cols = static_cast<size_type>(std::ranges::distance(first) + 1);
122 matrix_base_t::num_rows = static_cast<size_type>(std::ranges::distance(second) + 1);
123
124 if constexpr (!coordinate_only)
125 {
126 // Allocate the matrix here.
128 number_cols{matrix_base_t::num_cols}};
130 }
131 }
133
140 auto trace_path(matrix_coordinate const & trace_begin)
141 {
142 static_assert(!coordinate_only, "Requested trace but storing the trace was disabled!");
143
144 using matrix_iter_t = std::ranges::iterator_t<typename matrix_base_t::pool_type>;
146 using path_t = std::ranges::subrange<trace_iterator_t, std::default_sentinel_t>;
147
149 throw std::invalid_argument{"The given coordinate exceeds the matrix in vertical or horizontal direction."};
150
152 std::default_sentinel};
153 }
154
155private:
157 constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
158 {
161 if constexpr (coordinate_only)
162 {
164 *this,
165 column_data_view_type{std::views::iota(std::move(row_begin), std::move(row_end))}};
166 }
167 else
168 {
169 matrix_coordinate current_position{row_index_type{0u}, column_index_type{column_index}};
170 auto col = views::zip(
173 std::views::iota(std::move(row_begin), std::move(row_end)));
175 }
176 }
177
179 template <std::random_access_iterator iter_t>
180 constexpr value_type make_proxy(iter_t host_iter) noexcept
181 {
182 if constexpr (coordinate_only)
183 {
184 return {*host_iter, std::ignore, std::ignore, std::ignore, std::ignore};
185 }
186 else
187 {
188 return {
189 std::get<2>(*host_iter), // the coordinate.
190 std::get<0>(*host_iter), // the current entry.
191 std::get<1>(*host_iter), // the last left cell to read from.
192 std::get<1>(*host_iter), // the next left cell to write to.
193 matrix_base_t::cache_up, // the last up cell to read/write from/to.
194 };
195 }
196 }
197};
198
199} // namespace seqan3::detail
T addressof(T... args)
Provides seqan3::detail::alignment_matrix_column_major_range_base.
Provides seqan3::detail::alignment_trace_matrix_base.
Provides seqan3::detail::alignment_trace_matrix_proxy.
Represents a column within an alignment matrix.
Definition alignment_matrix_column_major_range_base.hpp:75
Provides a range interface for alignment matrices.
Definition alignment_matrix_column_major_range_base.hpp:60
std::default_sentinel_t sentinel
The type of sentinel.
Definition alignment_matrix_column_major_range_base.hpp:477
iterator_type iterator
The type of the iterator.
Definition alignment_matrix_column_major_range_base.hpp:475
An alignment traceback matrix storing the entire traceback matrix.
Definition alignment_trace_matrix_full.hpp:50
advanceable_alignment_coordinate< advanceable_alignment_coordinate_state::row > coordinate_type
The coordinate type.
Definition alignment_trace_matrix_base.hpp:42
constexpr value_type make_proxy(iter_t host_iter) noexcept
Creates the proxy value returned when dereferencing the alignment-column-iterator.
Definition alignment_trace_matrix_full.hpp:180
constexpr alignment_trace_matrix_full(first_sequence_t &&first, second_sequence_t &&second, trace_t const initial_value=trace_t{})
Construction from two ranges.
Definition alignment_trace_matrix_full.hpp:117
size_t size_type
The size type.
Definition alignment_trace_matrix_base.hpp:52
constexpr alignment_trace_matrix_full(alignment_trace_matrix_full const &)=default
Defaulted.
auto trace_path(matrix_coordinate const &trace_begin)
Returns a trace path starting from the given coordinate and ending in the cell with seqan3::detail::t...
Definition alignment_trace_matrix_full.hpp:140
typename range_base_t::iterator iterator
The type of the iterator.
Definition alignment_trace_matrix_full.hpp:87
alignment_trace_matrix_proxy< coordinate_type, std::conditional_t< coordinate_only, detail::ignore_t const, trace_t > > value_type
The proxy type of an alignment matrix.
Definition alignment_trace_matrix_full.hpp:83
friend range_base_t
Befriend the range base class.
Definition alignment_trace_matrix_full.hpp:62
typename range_base_t::sentinel sentinel
The type of sentinel.
Definition alignment_trace_matrix_full.hpp:89
constexpr alignment_trace_matrix_full & operator=(alignment_trace_matrix_full &&)=default
Defaulted.
constexpr alignment_trace_matrix_full(alignment_trace_matrix_full &&)=default
Defaulted.
constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
Returns the current alignment-column at the given column_index.
Definition alignment_trace_matrix_full.hpp:157
constexpr alignment_trace_matrix_full()=default
Defaulted.
constexpr alignment_trace_matrix_full & operator=(alignment_trace_matrix_full const &)=default
Defaulted.
constexpr iterator begin() noexcept
Returns an iterator pointing to the first element of the matrix.
Definition two_dimensional_matrix.hpp:270
T declval(T... args)
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
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T resize(T... args)
A crtp-base class for alignment traceback matrices.
Definition alignment_trace_matrix_base.hpp:36
advanceable_alignment_coordinate< advanceable_alignment_coordinate_state::row > coordinate_type
The coordinate type.
Definition alignment_trace_matrix_base.hpp:42
std::conditional_t< detail::simd_concept< trace_t >, aligned_allocator< element_type, sizeof(element_type)>, std::allocator< element_type > > allocator_type
The allocator type. Uses seqan3::aligned_allocator if storing seqan3::detail::simd_concepttypes.
Definition alignment_trace_matrix_base.hpp:48
size_t size_type
The size type.
Definition alignment_trace_matrix_base.hpp:52
std::vector< element_type, allocator_type > cache_left
Internal cache for the trace values to the left.
Definition alignment_trace_matrix_base.hpp:58
size_type num_rows
The number of num_rows.
Definition alignment_trace_matrix_base.hpp:64
element_type cache_up
Internal cache for the last trace value above.
Definition alignment_trace_matrix_base.hpp:60
trace_t element_type
The actual element type.
Definition alignment_trace_matrix_base.hpp:44
size_type num_cols
The number of columns.
Definition alignment_trace_matrix_base.hpp:62
pool_type data
The linearised matrix storing the trace data in column-major-order.
Definition alignment_trace_matrix_base.hpp:56
two_dimensional_matrix< element_type, allocator_type, matrix_major_order::column > pool_type
The type of the underlying memory pool.
Definition alignment_trace_matrix_base.hpp:50
A proxy type for a unified access to the traceback matrix during alignment computation.
Definition alignment_trace_matrix_proxy.hpp:33
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 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 seqan3::detail::trace_iterator.
Provides seqan3::views::zip.
Hide me