SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
simd_match_mismatch_scoring_scheme.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 <concepts>
13
21
22namespace seqan3::detail
23{
24
62template <simd_concept simd_score_t, semialphabet alphabet_t, typename alignment_t>
63 requires (seqan3::alphabet_size<alphabet_t> > 1)
64 && (std::same_as<alignment_t, align_cfg::method_local> || std::same_as<alignment_t, align_cfg::method_global>)
66{
67private:
71 using alphabet_ranks_type = simd_score_t;
72
73public:
75 static constexpr scalar_type padding_symbol = static_cast<scalar_type>(1u << (bits_of<scalar_type> - 1));
76
92
94 template <typename scoring_scheme_t>
96 constexpr explicit simd_match_mismatch_scoring_scheme(scoring_scheme_t const & scoring_scheme)
97 {
99 }
100
102 template <typename scoring_scheme_t>
104 constexpr simd_match_mismatch_scoring_scheme & operator=(scoring_scheme_t const & scoring_scheme)
105 {
107 return *this;
108 }
110
140 constexpr simd_score_t score(alphabet_ranks_type const & ranks1, alphabet_ranks_type const & ranks2) const noexcept
141 {
143 // For global and local alignment there are slightly different formulas because
144 // in global alignment padded characters always match
145 if constexpr (std::same_as<alignment_t, align_cfg::method_global>)
146 mask = (ranks1 ^ ranks2) <= simd::fill<simd_score_t>(0);
147 else // and in local alignment type padded characters always mismatch.
148 mask = (ranks1 ^ ranks2) == simd::fill<simd_score_t>(0);
149
151 }
153
155 constexpr auto padding_match_score() noexcept
156 {
157 return match_score[0];
158 }
159
161 template <typename alphabet_ranks_t>
162 requires std::same_as<std::remove_cvref_t<alphabet_ranks_t>, alphabet_ranks_type>
163 constexpr alphabet_ranks_t make_score_profile(alphabet_ranks_t && ranks) const noexcept
164 {
165 return std::forward<alphabet_ranks_t>(ranks);
166 }
167
168private:
184 template <typename scoring_scheme_t>
185 constexpr void initialise_from_scalar_scoring_scheme(scoring_scheme_t const & scoring_scheme)
186 {
187 using score_t = decltype(std::declval<scoring_scheme_t const &>().score(alphabet_t{}, alphabet_t{}));
188 using simd_scalar_t = typename simd_traits<simd_score_t>::scalar_type;
189
190 score_t scalar_match_score =
191 scoring_scheme.score(seqan3::assign_rank_to(0, alphabet_t{}), seqan3::assign_rank_to(0, alphabet_t{}));
192 score_t scalar_mismatch_score =
193 scoring_scheme.score(seqan3::assign_rank_to(0, alphabet_t{}), seqan3::assign_rank_to(1, alphabet_t{}));
194
195 // Check if the scoring scheme match and mismatch scores do not overflow with the respective scalar type.
196 if constexpr (sizeof(simd_scalar_t) < sizeof(score_t))
197 {
198 if (scalar_match_score > static_cast<score_t>(std::numeric_limits<simd_scalar_t>::max())
199 || scalar_mismatch_score < static_cast<score_t>(std::numeric_limits<simd_scalar_t>::lowest()))
200 {
201 throw std::invalid_argument{"The selected scoring scheme score overflows "
202 "for the selected scalar type of the simd type."};
203 }
204 }
205
206 match_score = simd::fill<simd_score_t>(static_cast<simd_scalar_t>(scalar_match_score));
207 mismatch_score = simd::fill<simd_score_t>(static_cast<simd_scalar_t>(scalar_mismatch_score));
208 }
209
210 simd_score_t match_score;
211 simd_score_t mismatch_score;
212};
213
214} // namespace seqan3::detail
Provides algorithms to modify seqan3::simd::simd_type.
Provides global and local alignment configurations.
Core alphabet concept and free function/type trait wrappers.
Provides utility functions for bit twiddling.
Adaptions of concepts from the Cereal library.
A vectorised scoring scheme handling matches and mismatches only.
Definition simd_match_mismatch_scoring_scheme.hpp:66
constexpr void initialise_from_scalar_scoring_scheme(scoring_scheme_t const &scoring_scheme)
Initialises the simd vector match score and mismatch score from the given scoring scheme.
Definition simd_match_mismatch_scoring_scheme.hpp:185
constexpr simd_match_mismatch_scoring_scheme(scoring_scheme_t const &scoring_scheme)
Initialises the simd vector match score and mismatch score from the given scoring scheme.
Definition simd_match_mismatch_scoring_scheme.hpp:96
typename simd_traits< simd_score_t >::scalar_type scalar_type
The underlying scalar type of the simd vector.
Definition simd_match_mismatch_scoring_scheme.hpp:69
constexpr simd_match_mismatch_scoring_scheme & operator=(scoring_scheme_t const &scoring_scheme)
Initialises the simd vector match score and mismatch score from the given scoring scheme.
Definition simd_match_mismatch_scoring_scheme.hpp:104
constexpr simd_score_t score(alphabet_ranks_type const &ranks1, alphabet_ranks_type const &ranks2) const noexcept
Computes the score for two simd vectors.
Definition simd_match_mismatch_scoring_scheme.hpp:140
simd_score_t alphabet_ranks_type
The type of the simd vector representing the alphabet ranks of one sequence batch.
Definition simd_match_mismatch_scoring_scheme.hpp:71
constexpr simd_match_mismatch_scoring_scheme(simd_match_mismatch_scoring_scheme const &)=default
Defaulted.
constexpr simd_match_mismatch_scoring_scheme & operator=(simd_match_mismatch_scoring_scheme &&)=default
Defaulted.
constexpr simd_match_mismatch_scoring_scheme & operator=(simd_match_mismatch_scoring_scheme const &)=default
Defaulted.
constexpr simd_match_mismatch_scoring_scheme()=default
Defaulted.
constexpr alphabet_ranks_t make_score_profile(alphabet_ranks_t &&ranks) const noexcept
Returns the given simd vector without changing it (no-op).
Definition simd_match_mismatch_scoring_scheme.hpp:163
simd_score_t match_score
The simd vector for a match score.
Definition simd_match_mismatch_scoring_scheme.hpp:210
constexpr auto padding_match_score() noexcept
Returns the match score used for padded symbols.
Definition simd_match_mismatch_scoring_scheme.hpp:155
simd_score_t mismatch_score
The simd vector for a mismatch score.
Definition simd_match_mismatch_scoring_scheme.hpp:211
static constexpr scalar_type padding_symbol
The padding symbol used to fill up smaller sequences in a simd batch.
Definition simd_match_mismatch_scoring_scheme.hpp:75
constexpr simd_match_mismatch_scoring_scheme(simd_match_mismatch_scoring_scheme &&)=default
Defaulted.
Implementation of a masked alphabet to be used for tuple composites.
Definition mask.hpp:35
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:290
A concept that requires that type be able to score two letters.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::scoring_scheme_for.
A strong type of underlying type score_type that represents the score of two matching characters.
Definition scoring_scheme_base.hpp:38
A strong type of underlying type score_type that represents the score two different characters.
Definition scoring_scheme_base.hpp:63
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38
Provides seqan3::simd::simd_concept.
Hide me