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>
47class alignment_trace_matrix_full :
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
56 using matrix_base_t = alignment_trace_matrix_base<trace_t>;
58 using range_base_t =
59 alignment_matrix_column_major_range_base<alignment_trace_matrix_full<trace_t, coordinate_only>>;
60
62 friend range_base_t;
63
64protected:
65 using typename matrix_base_t::coordinate_type;
66 using typename matrix_base_t::element_type;
67 using typename range_base_t::alignment_column_type;
69 using column_data_view_type =
70 std::conditional_t<coordinate_only,
71 decltype(std::views::iota(coordinate_type{}, coordinate_type{})),
74 std::views::iota(coordinate_type{}, coordinate_type{})))>;
75
76public:
81 using value_type =
82 alignment_trace_matrix_proxy<coordinate_type,
85 using reference = value_type;
87 using iterator = typename range_base_t::iterator;
89 using sentinel = typename range_base_t::sentinel;
90 using typename matrix_base_t::size_type;
92
96 constexpr alignment_trace_matrix_full() = default;
97 constexpr alignment_trace_matrix_full(alignment_trace_matrix_full const &) = default;
98 constexpr alignment_trace_matrix_full(alignment_trace_matrix_full &&) = default;
99 constexpr alignment_trace_matrix_full & operator=(alignment_trace_matrix_full const &) = default;
100 constexpr alignment_trace_matrix_full & operator=(alignment_trace_matrix_full &&) = default;
101 ~alignment_trace_matrix_full() = default;
102
116 template <std::ranges::forward_range first_sequence_t, std::ranges::forward_range second_sequence_t>
117 constexpr alignment_trace_matrix_full(first_sequence_t && first,
118 second_sequence_t && second,
119 [[maybe_unused]] trace_t const initial_value = trace_t{})
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.
127 matrix_base_t::data = typename matrix_base_t::pool_type{number_rows{matrix_base_t::num_rows},
128 number_cols{matrix_base_t::num_cols}};
129 matrix_base_t::cache_left.resize(matrix_base_t::num_rows, initial_value);
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>;
145 using trace_iterator_t = trace_iterator<matrix_iter_t>;
146 using path_t = std::ranges::subrange<trace_iterator_t, std::default_sentinel_t>;
147
148 if (trace_begin.row >= matrix_base_t::num_rows || trace_begin.col >= matrix_base_t::num_cols)
149 throw std::invalid_argument{"The given coordinate exceeds the matrix in vertical or horizontal direction."};
150
151 return path_t{trace_iterator_t{matrix_base_t::data.begin() + matrix_offset{trace_begin}},
152 std::default_sentinel};
153 }
154
155private:
157 constexpr alignment_column_type initialise_column(size_type const column_index) noexcept
158 {
159 coordinate_type row_begin{column_index_type{column_index}, row_index_type{0u}};
160 coordinate_type row_end{column_index_type{column_index}, row_index_type{matrix_base_t::num_rows}};
161 if constexpr (coordinate_only)
162 {
163 return alignment_column_type{
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(
171 std::span<element_type>{std::addressof(matrix_base_t::data[current_position]), matrix_base_t::num_rows},
172 std::span<element_type>{matrix_base_t::cache_left},
173 std::views::iota(std::move(row_begin), std::move(row_end)));
174 return alignment_column_type{*this, column_data_view_type{col}};
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.
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
Provides seqan3::detail::trace_iterator.
Provides seqan3::views::zip.
Hide me