BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
qualified.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
19
20namespace bio::alphabet
21{
22
56template <writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
57class qualified :
58 public tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>, sequence_alphabet_t, quality_alphabet_t>
59{
60private:
62 using base_type =
63 tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>, sequence_alphabet_t, quality_alphabet_t>;
64
65public:
67 using sequence_alphabet_type = sequence_alphabet_t;
69 using quality_alphabet_type = quality_alphabet_t;
70
75
79 constexpr qualified() noexcept = default;
80 constexpr qualified(qualified const &) noexcept = default;
81 constexpr qualified(qualified &&) noexcept = default;
82 constexpr qualified & operator=(qualified const &) noexcept = default;
83 constexpr qualified & operator=(qualified &&) noexcept = default;
84 ~qualified() noexcept = default;
85
86 // Inherit from base:
88 using base_type::base_type; // non-default constructors
89 using base_type::to_rank;
90 using base_type::operator=;
91
93 BIOCPP_DOXYGEN_ONLY((constexpr qualified(component_type const alph) noexcept {}))
95 BIOCPP_DOXYGEN_ONLY((constexpr qualified(indirect_component_type const alph) noexcept {}))
97 BIOCPP_DOXYGEN_ONLY((constexpr qualified & operator=(component_type const alph) noexcept {}))
99 BIOCPP_DOXYGEN_ONLY((constexpr qualified & operator=(indirect_component_type const alph) noexcept {}))
101
106 constexpr qualified & assign_char(char_type const c) noexcept
107 {
109 base_type::cummulative_alph_sizes[0]) +
110 (base_type::template to_component_rank<1>() * base_type::cummulative_alph_sizes[1]));
111
112 // The above is noticeably faster than (no subtraction and no division):
113 // base_type::template assign_component_rank<0>(
114 // bio::alphabet::to_rank(bio::alphabet::assign_char_to(c, sequence_alphabet_type{})));
115 return *this;
116 }
117
119 constexpr qualified & assign_phred(phred_type const c) noexcept
120 {
121 bio::alphabet::assign_phred_to(c, get<1>(*this));
122 return *this;
123 }
125
130 constexpr phred_type to_phred() const noexcept { return rank_to_phred[to_rank()]; }
131
133 constexpr char_type to_char() const noexcept { return rank_to_char[to_rank()]; }
134
139 constexpr qualified complement() const noexcept
140 requires nucleotide<sequence_alphabet_t>
141 {
142 return qualified{bio::alphabet::complement(get<0>(*this)), get<1>(*this)};
143 }
145
147 static constexpr bool char_is_valid(char_type const c) noexcept
148 {
149 return char_is_valid_for<sequence_alphabet_type>(c);
150 }
151
152protected:
154
156 static constexpr std::array<char_type, alphabet_size> rank_to_char = []() constexpr
157 {
159
160 for (size_t i = 0; i < alphabet_size; ++i)
161 {
162 size_t seq_rank = (i / base_type::cummulative_alph_sizes[0]) % bio::alphabet::size<quality_alphabet_type>;
163
165 }
166
167 return ret;
168 }();
169
171 static constexpr std::array<char_type, alphabet_size> rank_to_phred = []() constexpr
172 {
174
175 for (size_t i = 0; i < alphabet_size; ++i)
176 {
177 size_t qual_rank = (i / base_type::cummulative_alph_sizes[1]) % bio::alphabet::size<quality_alphabet_type>;
178
180 }
181
182 return ret;
183 }();
184};
185
188template <typename sequence_alphabet_type, typename quality_alphabet_type>
191
192} // namespace bio::alphabet
Provides bio::alphabet::nucleotide.
Quality alphabet concept.
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: base.hpp:168
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
Joins an arbitrary alphabet with a quality alphabet.
Definition: qualified.hpp:59
constexpr qualified & assign_phred(phred_type const c) noexcept
Assign from a phred value. This modifies the internal quality letter.
Definition: qualified.hpp:119
constexpr qualified complement() const noexcept
Return a qualified where the quality is preserved, but the sequence letter is complemented.
Definition: qualified.hpp:139
constexpr qualified & assign_char(char_type const c) noexcept
Assign from a character. This modifies the internal sequence letter.
Definition: qualified.hpp:106
char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: qualified.hpp:72
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character is valid in the sequence alphabet.
Definition: qualified.hpp:147
constexpr phred_type to_phred() const noexcept
Return the phred value. This reads the internal quality letter.
Definition: qualified.hpp:130
quality_alphabet_t quality_alphabet_type
Second template parameter as member type.
Definition: qualified.hpp:69
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.
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition: qualified.hpp:133
constexpr qualified() noexcept=default
Defaulted.
phred_t< quality_alphabet_type > phred_type
Equals the phred_type of the quality_alphabet_type.
Definition: qualified.hpp:74
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:95
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: qualified.hpp:67
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: tuple_base.hpp:96
A concept that indicates whether an alphabet represents nucleotides.
Definition: concept.hpp:113
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:192
constexpr auto assign_char_to
Assign a char to an alphabet object.
Definition: concept.hpp:260
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
decltype(bio::alphabet::to_char(std::declval< alphabet_type const >())) char_t
The char_type of the alphabet; defined as the return type of bio::alphabet::to_char.
Definition: concept.hpp:212
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:138
constexpr auto complement
Return the complement of a nucleotide object.
Definition: concept.hpp:68
constexpr auto assign_phred_to
Assign a phred score to a quality alphabet object.
Definition: concept.hpp:128
decltype(bio::alphabet::to_phred(std::declval< alphabet_type >())) phred_t
The phred_type of the alphabet; defined as the return type of bio::alphabet::to_phred.
Definition: concept.hpp:86
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:65
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::tuple_base.