SeqAn3 3.4.3-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alignment_matrix_policy.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2026 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2026 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <limits>
13#include <tuple>
14
20
21namespace seqan3::detail
22{
23
43template <typename alignment_algorithm_t, typename score_matrix_t, typename trace_matrix_t>
45{
46private:
49
53 constexpr alignment_matrix_policy() = default;
54 constexpr alignment_matrix_policy(alignment_matrix_policy const &) = default;
59
61 template <typename configuration_t>
62 alignment_matrix_policy(configuration_t const & /*config*/)
63 {}
65
78 template <typename sequence1_t, typename sequence2_t>
79 constexpr void allocate_matrix(sequence1_t && sequence1, sequence2_t && sequence2)
80 {
81 score_matrix = score_matrix_t{sequence1, sequence2};
82 trace_matrix = trace_matrix_t{sequence1, sequence2};
83
85 }
86
108 template <typename sequence1_t, typename sequence2_t, typename score_t>
109 constexpr void allocate_matrix(sequence1_t && sequence1,
110 sequence2_t && sequence2,
113 {
114 assert(state.gap_extension_score <= 0); // We expect it to never be positive.
115
117 score_matrix = score_matrix_t{sequence1, sequence2, band, inf};
118 trace_matrix = trace_matrix_t{sequence1, sequence2, band};
119
121 }
122
124 constexpr void initialise_matrix_iterator() noexcept
125 {
128 }
129
142 template <typename sequence1_t, typename sequence2_t>
143 constexpr auto
144 slice_sequences(sequence1_t & sequence1, sequence2_t & sequence2, align_cfg::band_fixed_size const & band) noexcept
145 {
146 size_t seq1_size = std::ranges::distance(sequence1);
147 size_t seq2_size = std::ranges::distance(sequence2);
148
149 auto trim_sequence1 = [&]() constexpr
150 {
151 seq1_slice_offset = std::max<std::ptrdiff_t>(band.lower_diagonal - 1, 0);
152 size_t end_pos = std::min<std::ptrdiff_t>(band.upper_diagonal + seq2_size, seq1_size);
153 return sequence1 | views::slice(seq1_slice_offset, end_pos);
154 };
155
156 auto trim_sequence2 = [&]() constexpr
157 {
158 seq2_slice_offset = std::abs(std::min<std::ptrdiff_t>(band.upper_diagonal + 1, 0));
159 size_t end_pos = std::min<std::ptrdiff_t>(seq1_size - band.lower_diagonal, seq2_size);
160 return sequence2 | views::slice(seq2_slice_offset, end_pos);
161 };
162
163 return std::tuple{trim_sequence1(), trim_sequence2()};
164 }
165
174 constexpr auto current_alignment_column() noexcept
175 {
176 assert(!std::ranges::empty(*score_matrix_iter));
177 assert(!std::ranges::empty(*trace_matrix_iter));
178
180 }
181
188 constexpr void next_alignment_column() noexcept
189 {
192 }
193
201 constexpr size_t to_original_sequence1_position(size_t position) const noexcept
202 {
203 return position + seq1_slice_offset;
204 }
205
213 constexpr size_t to_original_sequence2_position(size_t position) const noexcept
214 {
215 return position + seq2_slice_offset;
216 }
217
218 score_matrix_t score_matrix{};
219 trace_matrix_t trace_matrix{};
220
221 typename score_matrix_t::iterator score_matrix_iter{};
222 typename trace_matrix_t::iterator trace_matrix_iter{};
223
226};
227} // namespace seqan3::detail
Provides seqan3::detail::align_config_band.
Provides seqan3::detail::alignment_algorithm_state.
Provides various type traits on generic types.
Configuration element for setting a fixed size band.
Definition align_config_band.hpp:60
Manages the alignment and score matrix.
Definition alignment_matrix_policy.hpp:45
size_t seq2_slice_offset
The offset of the second sequence slice;.
Definition alignment_matrix_policy.hpp:225
score_matrix_t::iterator score_matrix_iter
The matrix iterator over the score matrix.
Definition alignment_matrix_policy.hpp:221
constexpr alignment_matrix_policy(alignment_matrix_policy const &)=default
Defaulted.
constexpr void allocate_matrix(sequence1_t &&sequence1, sequence2_t &&sequence2, align_cfg::band_fixed_size const &band, alignment_algorithm_state< score_t > const &state)
Allocates the memory of the underlying matrices.
Definition alignment_matrix_policy.hpp:109
constexpr auto current_alignment_column() noexcept
Returns the current alignment column.
Definition alignment_matrix_policy.hpp:174
constexpr void initialise_matrix_iterator() noexcept
Initialises the score and trace matrix iterator after allocating the matrices.
Definition alignment_matrix_policy.hpp:124
constexpr alignment_matrix_policy()=default
Defaulted.
trace_matrix_t trace_matrix
The trace matrix if needed.
Definition alignment_matrix_policy.hpp:219
constexpr size_t to_original_sequence2_position(size_t position) const noexcept
Converts a sliced position in the alignment matrix to the corresponding position in the original sequ...
Definition alignment_matrix_policy.hpp:213
~alignment_matrix_policy()=default
Defaulted.
constexpr void next_alignment_column() noexcept
Moves to the next alignment column.
Definition alignment_matrix_policy.hpp:188
trace_matrix_t::iterator trace_matrix_iter
The matrix iterator over the trace matrix.
Definition alignment_matrix_policy.hpp:222
constexpr alignment_matrix_policy & operator=(alignment_matrix_policy &&)=default
Defaulted.
constexpr alignment_matrix_policy(alignment_matrix_policy &&)=default
Defaulted.
alignment_matrix_policy(configuration_t const &)
Initialise the policy.
Definition alignment_matrix_policy.hpp:62
friend alignment_algorithm_t
Allow alignment algorithm to instantiate this crtp base class.
Definition alignment_matrix_policy.hpp:48
constexpr alignment_matrix_policy & operator=(alignment_matrix_policy const &)=default
Defaulted.
score_matrix_t score_matrix
The scoring matrix.
Definition alignment_matrix_policy.hpp:218
size_t seq1_slice_offset
The offset of the first sequence slice.
Definition alignment_matrix_policy.hpp:224
constexpr auto slice_sequences(sequence1_t &sequence1, sequence2_t &sequence2, align_cfg::band_fixed_size const &band) noexcept
Slices the sequences according to the band parameters.
Definition alignment_matrix_policy.hpp:144
constexpr void allocate_matrix(sequence1_t &&sequence1, sequence2_t &&sequence2)
}
Definition alignment_matrix_policy.hpp:79
constexpr size_t to_original_sequence1_position(size_t position) const noexcept
Converts a sliced position in the alignment matrix to the corresponding position in the original sequ...
Definition alignment_matrix_policy.hpp:201
@ band
ID for the band option.
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:137
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
T lowest(T... args)
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::views::slice.
Local state for the standard alignment algorithm.
Definition alignment_algorithm_state.hpp:32
score_type gap_extension_score
The cached gap extension score.
Definition alignment_algorithm_state.hpp:34
Provides seqan3::views::zip.
Hide me