18#include <seqan3/utility/simd/algorithm.hpp>
19#include <seqan3/utility/simd/concept.hpp>
21namespace seqan3::detail
53template <simd_concept simd_score_t, semialphabet alphabet_t,
typename alignment_t>
54 requires (std::same_as<alignment_t, align_cfg::method_local> || std::same_as<alignment_t, align_cfg::method_global>)
55class simd_matrix_scoring_scheme
59 using scalar_type =
typename simd_traits<simd_score_t>::scalar_type;
61 using simd_score_profile_type = simd_score_t;
63 using simd_alphabet_ranks_type = simd_score_t;
66 "The selected simd scalar type is not large enough to represent the given alphabet including an "
67 "additional padding symbol!");
70 "The selected simd scalar type is not large enough to represent the given alphabet including an "
71 "additional padding symbol!");
74 static constexpr bool is_global = std::same_as<alignment_t, align_cfg::method_global>;
78 static constexpr scalar_type score_for_padding_symbol = (is_global) ? 1 : -1;
81 std::vector<scalar_type> scoring_scheme_data{};
90 constexpr simd_matrix_scoring_scheme() =
default;
91 constexpr simd_matrix_scoring_scheme(simd_matrix_scoring_scheme
const &) =
default;
92 constexpr simd_matrix_scoring_scheme(simd_matrix_scoring_scheme &&) =
default;
93 constexpr simd_matrix_scoring_scheme & operator=(simd_matrix_scoring_scheme
const &) =
default;
94 constexpr simd_matrix_scoring_scheme & operator=(simd_matrix_scoring_scheme &&) =
default;
95 ~simd_matrix_scoring_scheme() =
default;
98 template <
typename scoring_scheme_t>
99 constexpr explicit simd_matrix_scoring_scheme(scoring_scheme_t
const & scoring_scheme)
101 initialise_from_scalar_scoring_scheme(scoring_scheme);
105 template <
typename scoring_scheme_t>
106 constexpr simd_matrix_scoring_scheme & operator=(scoring_scheme_t
const & scoring_scheme)
108 initialise_from_scalar_scoring_scheme(scoring_scheme);
137 constexpr simd_score_t score(simd_score_profile_type
const & score_profile,
138 simd_alphabet_ranks_type
const & ranks)
const noexcept
140 simd_score_t
const matrix_index = score_profile + ranks;
141 simd_score_t result{};
143 for (
size_t idx = 0; idx < simd_traits<simd_score_t>::length; ++idx)
144 result[idx] = scoring_scheme_data.
data()[matrix_index[idx]];
151 constexpr scalar_type padding_match_score() const noexcept
153 return score_for_padding_symbol;
166 constexpr simd_score_profile_type make_score_profile(simd_alphabet_ranks_type
const & ranks)
const noexcept
168 return ranks * simd::fill<simd_score_t>(index_offset);
180 template <
typename scoring_scheme_t>
181 requires scoring_scheme_for<scoring_scheme_t, alphabet_t>
182 constexpr void initialise_from_scalar_scoring_scheme(scoring_scheme_t
const & scoring_scheme)
187 [[maybe_unused]]
auto check_score_range = [&]([[maybe_unused]] score_t score)
192 if constexpr (
sizeof(scalar_type) <
sizeof(score_t))
197 if (score > max_score_value || score < min_score_value)
198 throw std::invalid_argument{
"The selected scoring scheme score overflows "
199 "for the selected scalar type of the simd type."};
204 scoring_scheme_data.
resize(index_offset * index_offset, score_for_padding_symbol);
208 auto data_it = scoring_scheme_data.
begin();
209 for (alphabet_size_t lhs_rank = 0; lhs_rank < seqan3::alphabet_size<alphabet_t>; ++lhs_rank)
211 for (alphabet_size_t rhs_rank = 0; rhs_rank < seqan3::alphabet_size<alphabet_t>; ++rhs_rank, ++data_it)
216 check_score_range(tmp_score);
217 *data_it = tmp_score;
Provides global and local alignment configurations.
Core alphabet concept and free function/type trait wrappers.
Adaptions of concepts from the Cereal library.
scoring_scheme(scheme_t) -> scoring_scheme< std::remove_cvref_t< scheme_t > >
Deduces the scoring scheme type from the constructor argument.
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition alphabet/concept.hpp:834
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:288
Provides seqan3::scoring_scheme_for.