SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
alignment_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 <iterator>
16#include <ranges>
17
23
24namespace seqan3::detail
25{
26
49template <typename trace_t, bool coordinate_only = false>
51 protected alignment_trace_matrix_base<trace_t>,
52 public alignment_matrix_column_major_range_base<alignment_trace_matrix_full<trace_t, coordinate_only>>
53{
54private:
55 static_assert(std::same_as<trace_t, trace_directions> || simd_concept<trace_t>,
56 "Value type must either be a trace_directions object or a simd vector.");
57
63
66
67protected:
68 using typename matrix_base_t::coordinate_type;
69 using typename matrix_base_t::element_type;
73 std::conditional_t<coordinate_only,
78
79public:
84 using value_type =
93 using typename matrix_base_t::size_type;
95
99 constexpr alignment_trace_matrix_full() = default;
105
119 template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
120 constexpr alignment_trace_matrix_full(first_sequence_t && first,
121 second_sequence_t && second,
122 [[maybe_unused]] trace_t const initial_value = trace_t{})
123 {
124 matrix_base_t::num_cols = static_cast<size_type>(std::ranges::distance(first) + 1);
125 matrix_base_t::num_rows = static_cast<size_type>(std::ranges::distance(second) + 1);
126
127 if constexpr (!coordinate_only)
128 {
129 // Allocate the matrix here.
131 number_cols{matrix_base_t::num_cols}};
133 }
134 }
136
143 auto trace_path(matrix_coordinate const & trace_begin)
144 {
145 static_assert(!coordinate_only, "Requested trace but storing the trace was disabled!");
146
147 using matrix_iter_t = std::ranges::iterator_t<typename matrix_base_t::pool_type>;
148 using trace_iterator_t = trace_iterator<matrix_iter_t>;
149 using path_t = std::ranges::subrange<trace_iterator_t, std::default_sentinel_t>;
150
151 if (trace_begin.row >= matrix_base_t::num_rows || trace_begin.col >= matrix_base_t::num_cols)
152 throw std::invalid_argument{"The given coordinate exceeds the matrix in vertical or horizontal direction."};
153
154 return path_t{trace_iterator_t{matrix_base_t::data.begin() + matrix_offset{trace_begin}},
155 std::default_sentinel};
156 }
157
158private:
160 constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
161 {
162 coordinate_type row_begin{column_index_type{column_index}, row_index_type{0u}};
164 if constexpr (coordinate_only)
165 {
166 return alignment_column_type{
167 *this,
168 column_data_view_type{std::views::iota(std::move(row_begin), std::move(row_end))}};
169 }
170 else
171 {
172 matrix_coordinate current_position{row_index_type{0u}, column_index_type{column_index}};
173 auto col = views::zip(
176 std::views::iota(std::move(row_begin), std::move(row_end)));
177 return alignment_column_type{*this, column_data_view_type{col}};
178 }
179 }
180
182 template <std::random_access_iterator iter_t>
183 constexpr value_type make_proxy(iter_t host_iter) noexcept
184 {
185 if constexpr (coordinate_only)
186 {
187 return {*host_iter, std::ignore, std::ignore, std::ignore, std::ignore};
188 }
189 else
190 {
191 return {
192 std::get<2>(*host_iter), // the coordinate.
193 std::get<0>(*host_iter), // the current entry.
194 std::get<1>(*host_iter), // the last left cell to read from.
195 std::get<1>(*host_iter), // the next left cell to write to.
196 matrix_base_t::cache_up, // the last up cell to read/write from/to.
197 };
198 }
199 }
200};
201
202} // 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.
Implements an internal alignment coordinate that can be used as an argument to the std::ranges::iota_...
Definition: advanceable_alignment_coordinate.hpp:66
Represents a column within an alignment matrix.
Definition: alignment_matrix_column_major_range_base.hpp:78
Provides a range interface for alignment matrices.
Definition: alignment_matrix_column_major_range_base.hpp:63
std::default_sentinel_t sentinel
The type of sentinel.
Definition: alignment_matrix_column_major_range_base.hpp:480
iterator_type iterator
The type of the iterator.
Definition: alignment_matrix_column_major_range_base.hpp:478
An alignment traceback matrix storing the entire traceback matrix.
Definition: alignment_trace_matrix_full.hpp:53
advanceable_alignment_coordinate< advanceable_alignment_coordinate_state::row > coordinate_type
The coordinate type.
Definition: alignment_trace_matrix_base.hpp:45
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:183
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:120
size_t size_type
The size type.
Definition: alignment_trace_matrix_base.hpp:55
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:143
typename range_base_t::iterator iterator
The type of the iterator.
Definition: alignment_trace_matrix_full.hpp:90
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:86
friend range_base_t
Befriend the range base class.
Definition: alignment_trace_matrix_full.hpp:65
typename range_base_t::sentinel sentinel
The type of sentinel.
Definition: alignment_trace_matrix_full.hpp:92
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:160
constexpr alignment_trace_matrix_full()=default
Defaulted.
constexpr alignment_trace_matrix_full & operator=(alignment_trace_matrix_full const &)=default
Defaulted.
A trace iterator an unbanded trace matrix.
Definition: trace_iterator.hpp:33
constexpr iterator begin() noexcept
Returns an iterator pointing to the first element of the matrix.
Definition: two_dimensional_matrix.hpp:273
T declval(T... args)
constexpr simd_t iota(typename simd_traits< simd_t >::scalar_type const offset)
Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2,...
Definition: algorithm.hpp:319
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
The generic simd concept.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
T resize(T... args)
A crtp-base class for alignment traceback matrices.
Definition: alignment_trace_matrix_base.hpp:39
advanceable_alignment_coordinate< advanceable_alignment_coordinate_state::row > coordinate_type
The coordinate type.
Definition: alignment_trace_matrix_base.hpp:45
size_t size_type
The size type.
Definition: alignment_trace_matrix_base.hpp:55
std::vector< element_type, allocator_type > cache_left
Internal cache for the trace values to the left.
Definition: alignment_trace_matrix_base.hpp:61
size_type num_rows
The number of num_rows.
Definition: alignment_trace_matrix_base.hpp:67
element_type cache_up
Internal cache for the last trace value above.
Definition: alignment_trace_matrix_base.hpp:63
trace_t element_type
The actual element type.
Definition: alignment_trace_matrix_base.hpp:47
size_type num_cols
The number of columns.
Definition: alignment_trace_matrix_base.hpp:65
pool_type data
The linearised matrix storing the trace data in column-major-order.
Definition: alignment_trace_matrix_base.hpp:59
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:53
A proxy type for a unified access to the traceback matrix during alignment computation.
Definition: alignment_trace_matrix_proxy.hpp:36
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 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 seqan3::detail::trace_iterator.
Provides seqan3::views::zip.