SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
qualified.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
18 
19 namespace seqan3
20 {
21 
57 template <writable_alphabet sequence_alphabet_t, writable_quality_alphabet quality_alphabet_t>
58 class qualified :
59  public alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
60  sequence_alphabet_t,
61  quality_alphabet_t>
62 {
63 private:
65  using base_type = alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
66  sequence_alphabet_t,
67  quality_alphabet_t>;
68 
69 public:
74  using sequence_alphabet_type = sequence_alphabet_t;
79  using quality_alphabet_type = quality_alphabet_t;
80 
85  using char_type = alphabet_char_t<sequence_alphabet_type>;
90  using phred_type = alphabet_phred_t<quality_alphabet_type>;
91 
95  constexpr qualified() noexcept = default;
96  constexpr qualified(qualified const &) noexcept = default;
97  constexpr qualified(qualified &&) noexcept = default;
98  constexpr qualified & operator=(qualified const &) noexcept = default;
99  constexpr qualified & operator=(qualified &&) noexcept = default;
100  ~qualified() noexcept = default;
101 
102  // Inherit from base:
103  using base_type::alphabet_size;
104  using base_type::base_type; // non-default constructors
105  using base_type::to_rank;
106  using base_type::operator=;
107 
109  SEQAN3_DOXYGEN_ONLY((constexpr qualified(component_type const alph) noexcept {}))
111  SEQAN3_DOXYGEN_ONLY((constexpr qualified(indirect_component_type const alph) noexcept {}))
113  SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(component_type const alph) noexcept {}))
115  SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(indirect_component_type const alph) noexcept {}))
117 
125  constexpr qualified & assign_char(char_type const c) noexcept
126  {
127  base_type::assign_rank((seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{}))
128  * base_type::cummulative_alph_sizes[0])
129  + (base_type::template to_component_rank<1>() * base_type::cummulative_alph_sizes[1]));
130 
131  // The above is noticeably faster than (no subtraction and no division):
132  // base_type::template assign_component_rank<0>(
133  // seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})));
134  return *this;
135  }
136 
141  constexpr qualified & assign_phred(phred_type const c) noexcept
142  {
143  seqan3::assign_phred_to(c, get<1>(*this));
144  return *this;
145  }
147 
155  constexpr phred_type to_phred() const noexcept
156  {
157  return rank_to_phred[to_rank()];
158  }
159 
164  constexpr char_type to_char() const noexcept
165  {
166  return rank_to_char(to_rank());
167  }
168 
175  constexpr qualified complement() const noexcept
176  requires nucleotide_alphabet<sequence_alphabet_t>
177  {
178  return qualified{seqan3::complement(get<0>(*this)), get<1>(*this)};
179  }
181 
186  static constexpr bool char_is_valid(char_type const c) noexcept
187  {
188  return char_is_valid_for<sequence_alphabet_type>(c);
189  }
190 
191 private:
193  static constexpr std::array<char_type, alphabet_size> rank_to_char_table{
194  []() constexpr {std::array<char_type, alphabet_size> ret{};
195 
196  for (size_t i = 0; i < alphabet_size; ++i)
197  {
198  size_t seq_rank = (i / base_type::cummulative_alph_sizes[0]) % seqan3::alphabet_size<quality_alphabet_type>;
199 
201  }
202 
203  return ret;
204 }()
205 }; // namespace seqan3
206 
208 static constexpr std::array<char_type, alphabet_size> rank_to_phred{
209  []() constexpr {std::array<char_type, alphabet_size> ret{};
210 
211 for (size_t i = 0; i < alphabet_size; ++i)
212 {
213  size_t qual_rank = (i / base_type::cummulative_alph_sizes[1]) % seqan3::alphabet_size<quality_alphabet_type>;
214 
216 }
217 
218 return ret;
219 }
220 ()
221 }
222 ;
223 
225 static constexpr char_type rank_to_char(typename base_type::rank_type const rank)
226 {
227  return rank_to_char_table[rank];
228 }
229 }
230 ;
231 
235 template <typename sequence_alphabet_type, typename quality_alphabet_type>
238 
239 } // namespace seqan3
Provides seqan3::nucleotide_alphabet.
Quality alphabet concept.
Provides seqan3::alphabet_tuple_base.
Joins an arbitrary alphabet with a quality alphabet.
Definition: qualified.hpp:62
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character is valid in the sequence alphabet.
Definition: qualified.hpp:186
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition: qualified.hpp:164
constexpr phred_type to_phred() const noexcept
Return the Phred score value. This reads the internal quality letter.
Definition: qualified.hpp:155
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: qualified.hpp:85
constexpr qualified(indirect_component_type const alph) noexcept
Definition: qualified.hpp:111
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:79
alphabet_phred_t< quality_alphabet_type > phred_type
Equals the phred_type of the quality_alphabet_type.
Definition: qualified.hpp:90
constexpr qualified complement() const noexcept requires nucleotide_alphabet< sequence_alphabet_t >
Return a qualified where the quality is preserved, but the sequence letter is complemented.
Definition: qualified.hpp:175
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: qualified.hpp:74
constexpr qualified & assign_phred(phred_type const c) noexcept
Assign from a Phred score value. This modifies the internal quality letter.
Definition: qualified.hpp:141
constexpr qualified & assign_char(char_type const c) noexcept
Assign from a character. This modifies the internal sequence letter.
Definition: qualified.hpp:125
constexpr auto complement
Return the complement of a nucleotide object.
Definition: alphabet/nucleotide/concept.hpp:105
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition: alphabet/quality/concept.hpp:100
constexpr auto assign_phred_to
Assign a Phred score to a quality alphabet object.
Definition: alphabet/quality/concept.hpp:230
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: alphabet/concept.hpp:524
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: alphabet/concept.hpp:386
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: alphabet/concept.hpp:293
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: alphabet/concept.hpp:155
A concept that indicates whether an alphabet represents nucleotides.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29