SeqAn3 3.4.0-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-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 <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 slice_sequences(sequence1_t & sequence1,
144 sequence2_t & sequence2,
145 align_cfg::band_fixed_size const & band) const noexcept
146 {
147 size_t seq1_size = std::ranges::distance(sequence1);
148 size_t seq2_size = std::ranges::distance(sequence2);
149
150 auto trim_sequence1 = [&]() constexpr
151 {
152 size_t begin_pos = std::max<std::ptrdiff_t>(band.lower_diagonal - 1, 0);
153 size_t end_pos = std::min<std::ptrdiff_t>(band.upper_diagonal + seq2_size, seq1_size);
154 return sequence1 | views::slice(begin_pos, end_pos);
155 };
156
157 auto trim_sequence2 = [&]() constexpr
158 {
159 size_t begin_pos = std::abs(std::min<std::ptrdiff_t>(band.upper_diagonal + 1, 0));
160 size_t end_pos = std::min<std::ptrdiff_t>(seq1_size - band.lower_diagonal, seq2_size);
161 return sequence2 | views::slice(begin_pos, end_pos);
162 };
163
164 return std::tuple{trim_sequence1(), trim_sequence2()};
165 }
166
175 constexpr auto current_alignment_column() noexcept
176 {
177 assert(!std::ranges::empty(*score_matrix_iter));
178 assert(!std::ranges::empty(*trace_matrix_iter));
179
181 }
182
189 constexpr void next_alignment_column() noexcept
190 {
193 }
194
195 score_matrix_t score_matrix{};
196 trace_matrix_t trace_matrix{};
197
198 typename score_matrix_t::iterator score_matrix_iter{};
199 typename trace_matrix_t::iterator trace_matrix_iter{};
200};
201} // 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
score_matrix_t::iterator score_matrix_iter
The matrix iterator over the score matrix.
Definition alignment_matrix_policy.hpp:198
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:175
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:196
~alignment_matrix_policy()=default
Defaulted.
constexpr void next_alignment_column() noexcept
Moves to the next alignment column.
Definition alignment_matrix_policy.hpp:189
trace_matrix_t::iterator trace_matrix_iter
The matrix iterator over the trace matrix.
Definition alignment_matrix_policy.hpp:199
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:195
constexpr auto slice_sequences(sequence1_t &sequence1, sequence2_t &sequence2, align_cfg::band_fixed_size const &band) const noexcept
Slices the sequences according to the band parameters.
Definition alignment_matrix_policy.hpp:143
constexpr void allocate_matrix(sequence1_t &&sequence1, sequence2_t &&sequence2)
}
Definition alignment_matrix_policy.hpp:79
@ 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:175
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