SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
qualified.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
15
16namespace seqan3
17{
18
54template <writable_alphabet sequence_alphabet_t, writable_quality_alphabet quality_alphabet_t>
55class qualified :
56 public alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
57 sequence_alphabet_t,
58 quality_alphabet_t>
59{
60private:
63 sequence_alphabet_t,
64 quality_alphabet_t>;
65
66public:
71 using sequence_alphabet_type = sequence_alphabet_t;
76 using quality_alphabet_type = quality_alphabet_t;
77
88
92 constexpr qualified() noexcept = default;
93 constexpr qualified(qualified const &) noexcept = default;
94 constexpr qualified(qualified &&) noexcept = default;
95 constexpr qualified & operator=(qualified const &) noexcept = default;
96 constexpr qualified & operator=(qualified &&) noexcept = default;
97 ~qualified() noexcept = default;
98
99 // Inherit from base:
101 using base_type::base_type; // non-default constructors
102 using base_type::to_rank;
103 using base_type::operator=;
104
106 SEQAN3_DOXYGEN_ONLY((constexpr qualified(component_type const alph) noexcept {}))
108 SEQAN3_DOXYGEN_ONLY((constexpr qualified(indirect_component_type const alph) noexcept {}))
110 SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(component_type const alph) noexcept {}))
112 SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(indirect_component_type const alph) noexcept {}))
114
122 constexpr qualified & assign_char(char_type const c) noexcept
123 {
126 + (base_type::template to_component_rank<1>() * base_type::cummulative_alph_sizes[1]));
127
128 // The above is noticeably faster than (no subtraction and no division):
129 // base_type::template assign_component_rank<0>(
130 // seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})));
131 return *this;
132 }
133
138 constexpr qualified & assign_phred(phred_type const c) noexcept
139 {
140 seqan3::assign_phred_to(c, get<1>(*this));
141 return *this;
142 }
144
152 constexpr phred_type to_phred() const noexcept
153 {
154 return rank_to_phred[to_rank()];
155 }
156
161 constexpr char_type to_char() const noexcept
162 {
163 return rank_to_char(to_rank());
164 }
165
172 constexpr qualified complement() const noexcept
173 requires nucleotide_alphabet<sequence_alphabet_t>
174 {
175 return qualified{seqan3::complement(get<0>(*this)), get<1>(*this)};
176 }
178
183 static constexpr bool char_is_valid(char_type const c) noexcept
184 {
185 return char_is_valid_for<sequence_alphabet_type>(c);
186 }
187
188private:
190 static constexpr char_type rank_to_char(typename base_type::rank_type const rank)
191 {
192 return rank_to_char_table[rank];
193 }
194
195 // clang-format off
198 {
199 []() constexpr {
201
202 for (size_t i = 0; i < alphabet_size; ++i)
203 {
204 size_t const seq_rank = (i / base_type::cummulative_alph_sizes[0]) %
205 seqan3::alphabet_size<quality_alphabet_type>;
206
208 }
209
210 return ret;
211 }()
212 };
213
216 {
217 []() constexpr {
219
220 for (size_t i = 0; i < alphabet_size; ++i)
221 {
222 size_t qual_rank = (i / base_type::cummulative_alph_sizes[1]) %
223 seqan3::alphabet_size<quality_alphabet_type>;
224
226 }
227
228 return ret;
229 }()
230 };
231};
232// clang-format on
233
237template <typename sequence_alphabet_type, typename quality_alphabet_type>
240
241} // namespace seqan3
Provides seqan3::nucleotide_alphabet.
Quality alphabet concept.
Provides seqan3::alphabet_tuple_base.
static constexpr detail::min_viable_uint_t< size > alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition alphabet_base.hpp:196
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
rank_type rank
The value of the alphabet letter is stored as the rank.
Definition alphabet_base.hpp:258
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition alphabet_tuple_base.hpp:113
static constexpr std::array< rank_type, component_list::size()> cummulative_alph_sizes
The cumulative alphabet size products are cached.
Definition alphabet_tuple_base.hpp:608
Joins an arbitrary alphabet with a quality alphabet.
Definition qualified.hpp:59
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character is valid in the sequence alphabet.
Definition qualified.hpp:183
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition qualified.hpp:161
constexpr phred_type to_phred() const noexcept
Return the Phred score value. This reads the internal quality letter.
Definition qualified.hpp:152
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition qualified.hpp:82
constexpr qualified(indirect_component_type const alph) noexcept
Construction via a value of a subtype that is assignable to one of the components.
Definition qualified.hpp:108
constexpr qualified complement() const noexcept
Return a qualified where the quality is preserved, but the sequence letter is complemented.
Definition qualified.hpp:172
constexpr qualified & assign_phred(phred_type const c) noexcept
Assign from a Phred score value. This modifies the internal quality letter.
Definition qualified.hpp:138
constexpr qualified() noexcept=default
Defaulted.
qualified(sequence_alphabet_type &&, quality_alphabet_type &&) -> qualified< std::decay_t< sequence_alphabet_type >, std::decay_t< quality_alphabet_type > >
Type deduction guide enables usage of qualified without specifying template args.
quality_alphabet_t quality_alphabet_type
Second template parameter as member type.
Definition qualified.hpp:76
constexpr qualified & assign_char(char_type const c) noexcept
Assign from a character. This modifies the internal sequence letter.
Definition qualified.hpp:122
static constexpr char_type rank_to_char(typename base_type::rank_type const rank)
Returns the character representation of rank.
Definition qualified.hpp:190
alphabet_phred_t< quality_alphabet_type > phred_type
Equals the phred_type of the quality_alphabet_type.
Definition qualified.hpp:87
static constexpr std::array< char_type, alphabet_size > rank_to_char_table
The lookup table used in rank_to_char.
Definition qualified.hpp:198
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition qualified.hpp:71
static constexpr std::array< char_type, alphabet_size > rank_to_phred
Rank to Phred conversion table.
Definition qualified.hpp:216
constexpr auto complement
Return the complement of a nucleotide object.
Definition alphabet/nucleotide/concept.hpp:102
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition alphabet/quality/concept.hpp:97
decltype(seqan3::to_phred(std::declval< alphabet_type >())) alphabet_phred_t
The phred_type of the alphabet; defined as the return type of seqan3::to_phred.
Definition alphabet/quality/concept.hpp:111
constexpr auto assign_phred_to
Assign a Phred score to a quality alphabet object.
Definition alphabet/quality/concept.hpp:227
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:521
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:383
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:290
decltype(seqan3::to_char(std::declval< alphabet_type const >())) alphabet_char_t
The char_type of the alphabet; defined as the return type of seqan3::to_char.
Definition alphabet/concept.hpp:397
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
A concept that indicates whether an alphabet represents nucleotides.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Hide me