24namespace seqan3::detail
56template <simd_concept simd_score_t, semialphabet alphabet_t,
typename alignment_t>
57 requires (std::same_as<alignment_t, align_cfg::method_local> || std::same_as<alignment_t, align_cfg::method_global>)
58class simd_matrix_scoring_scheme
62 using scalar_type =
typename simd_traits<simd_score_t>::scalar_type;
64 using simd_score_profile_type = simd_score_t;
66 using simd_alphabet_ranks_type = simd_score_t;
69 "The selected simd scalar type is not large enough to represent the given alphabet including an "
70 "additional padding symbol!");
73 "The selected simd scalar type is not large enough to represent the given alphabet including an "
74 "additional padding symbol!");
77 static constexpr bool is_global = std::same_as<alignment_t, align_cfg::method_global>;
79 static constexpr size_t index_offset = seqan3::alphabet_size<alphabet_t> + 1;
81 static constexpr scalar_type score_for_padding_symbol = (is_global) ? 1 : -1;
88 static constexpr scalar_type padding_symbol =
static_cast<scalar_type
>(seqan3::alphabet_size<alphabet_t>);
93 constexpr simd_matrix_scoring_scheme() =
default;
94 constexpr simd_matrix_scoring_scheme(simd_matrix_scoring_scheme
const &) =
default;
95 constexpr simd_matrix_scoring_scheme(simd_matrix_scoring_scheme &&) =
default;
96 constexpr simd_matrix_scoring_scheme & operator=(simd_matrix_scoring_scheme
const &) =
default;
97 constexpr simd_matrix_scoring_scheme & operator=(simd_matrix_scoring_scheme &&) =
default;
98 ~simd_matrix_scoring_scheme() =
default;
101 template <
typename scoring_scheme_t>
102 constexpr explicit simd_matrix_scoring_scheme(scoring_scheme_t
const & scoring_scheme)
104 initialise_from_scalar_scoring_scheme(scoring_scheme);
108 template <
typename scoring_scheme_t>
109 constexpr simd_matrix_scoring_scheme & operator=(scoring_scheme_t
const & scoring_scheme)
111 initialise_from_scalar_scoring_scheme(scoring_scheme);
140 constexpr simd_score_t score(simd_score_profile_type
const & score_profile,
141 simd_alphabet_ranks_type
const & ranks)
const noexcept
143 simd_score_t
const matrix_index = score_profile + ranks;
144 simd_score_t result{};
146 for (
size_t idx = 0; idx < simd_traits<simd_score_t>::length; ++idx)
147 result[idx] = scoring_scheme_data.data()[matrix_index[idx]];
154 constexpr scalar_type padding_match_score() const noexcept
156 return score_for_padding_symbol;
169 constexpr simd_score_profile_type make_score_profile(simd_alphabet_ranks_type
const & ranks)
const noexcept
171 return ranks * simd::fill<simd_score_t>(index_offset);
183 template <
typename scoring_scheme_t>
185 constexpr void initialise_from_scalar_scoring_scheme(scoring_scheme_t
const & scoring_scheme)
187 using score_t =
decltype(std::declval<scoring_scheme_t const &>().score(alphabet_t{}, alphabet_t{}));
190 [[maybe_unused]]
auto check_score_range = [&]([[maybe_unused]] score_t score)
195 if constexpr (
sizeof(scalar_type) <
sizeof(score_t))
200 if (score > max_score_value || score < min_score_value)
202 "for the selected scalar type of the simd type."};
207 scoring_scheme_data.resize(index_offset * index_offset, score_for_padding_symbol);
211 auto data_it = scoring_scheme_data.begin();
212 for (alphabet_size_t lhs_rank = 0; lhs_rank < seqan3::alphabet_size<alphabet_t>; ++lhs_rank)
214 for (alphabet_size_t rhs_rank = 0; rhs_rank < seqan3::alphabet_size<alphabet_t>; ++rhs_rank, ++data_it)
219 check_score_range(tmp_score);
220 *data_it = tmp_score;
Provides algorithms to modify seqan3::simd::simd_type.
Provides global and local alignment configurations.
Core alphabet concept and free function/type trait wrappers.
Adaptions of concepts from the Cereal library.
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:293
A concept that requires that type be able to score two letters.
Provides seqan3::scoring_scheme_for.
Provides seqan3::simd::simd_concept.