SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
qualified.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
55 template <writable_alphabet sequence_alphabet_t, writable_quality_alphabet quality_alphabet_t>
56 class qualified :
57  public alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
58  sequence_alphabet_t, quality_alphabet_t>
59 {
60 private:
63  sequence_alphabet_t, quality_alphabet_t>;
64 
65 public:
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:
87  using base_type::base_type; // non-default constructors
88  using base_type::alphabet_size;
89  using base_type::to_rank;
90  using base_type::operator=;
91 
93  SEQAN3_DOXYGEN_ONLY(( constexpr qualified(component_type const alph) noexcept {} ))
95  SEQAN3_DOXYGEN_ONLY(( constexpr qualified(indirect_component_type const alph) noexcept {} ))
97  SEQAN3_DOXYGEN_ONLY(( constexpr qualified & operator=(component_type const alph) noexcept {} ))
99  SEQAN3_DOXYGEN_ONLY(( constexpr qualified & operator=(indirect_component_type const alph) noexcept {} ))
101 
105  constexpr qualified & assign_char(char_type const c) noexcept
107  {
110  base_type::cummulative_alph_sizes[0]) +
111  (base_type::template to_component_rank<1>() * base_type::cummulative_alph_sizes[1]));
112 
113  // The above is noticeably faster than (no subtraction and no division):
114  // base_type::template assign_component_rank<0>(
115  // seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})));
116  return *this;
117  }
118 
120  constexpr qualified & assign_phred(phred_type const c) noexcept
121  {
122  seqan3::assign_phred_to(c, get<1>(*this));
123  return *this;
124  }
126 
130  constexpr phred_type to_phred() const noexcept
132  {
133  return rank_to_phred[to_rank()];
134  }
135 
137  constexpr char_type to_char() const noexcept
138  {
139  return rank_to_char[to_rank()];
140  }
141 
146  constexpr qualified complement() const noexcept
147  requires nucleotide_alphabet<sequence_alphabet_t>
148  {
149  return qualified{seqan3::complement(get<0>(*this)), get<1>(*this)};
150  }
152 
154  static constexpr bool char_is_valid(char_type const c) noexcept
155  {
156  return char_is_valid_for<sequence_alphabet_type>(c);
157  }
158 
159 protected:
161 
163  static std::array<char_type, alphabet_size> constexpr rank_to_char
164  {
165  [] () constexpr
166  {
168 
169  for (size_t i = 0; i < alphabet_size; ++i)
170  {
171  size_t seq_rank = (i / base_type::cummulative_alph_sizes[0]) %
172  seqan3::alphabet_size<quality_alphabet_type>;
173 
175  }
176 
177  return ret;
178  }()
179  };
180 
182  static std::array<char_type, alphabet_size> constexpr rank_to_phred
183  {
184  [] () constexpr
185  {
187 
188  for (size_t i = 0; i < alphabet_size; ++i)
189  {
190  size_t qual_rank = (i / base_type::cummulative_alph_sizes[1]) %
191  seqan3::alphabet_size<quality_alphabet_type>;
192 
194  }
195 
196  return ret;
197  }()
198  };
199 };
200 
203 template <typename sequence_alphabet_type, typename quality_alphabet_type>
206 
207 } // namespace seqan3
seqan3::assign_rank_to
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:239
seqan3::qualified::qualified
constexpr qualified() noexcept=default
Defaulted.
concept.hpp
Provides seqan3::nucleotide_alphabet.
seqan3::qualified::sequence_alphabet_type
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: qualified.hpp:67
seqan3::alphabet_base< qualified< sequence_alphabet_t, quality_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::alphabet_size
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:176
seqan3::alphabet_tuple_base
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:120
seqan3::qualified::qualified
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
seqan3::qualified::to_char
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition: qualified.hpp:137
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:321
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:143
seqan3::qualified::assign_char
constexpr qualified & assign_char(char_type const c) noexcept
Assign from a character. This modifies the internal sequence letter.
Definition: qualified.hpp:106
seqan3::qualified::assign_phred
constexpr qualified & assign_phred(phred_type const c) noexcept
Assign from a phred value. This modifies the internal quality letter.
Definition: qualified.hpp:120
concept.hpp
Quality alphabet concept.
nucleotide_alphabet
A concept that indicates whether an alphabet represents nucleotides.
seqan3::qualified::to_phred
constexpr phred_type to_phred() const noexcept
Return the phred value. This reads the internal quality letter.
Definition: qualified.hpp:131
seqan3::alphabet_phred_t
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: concept.hpp:99
seqan3::qualified::qualified
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.
seqan3::alphabet_char_t
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: concept.hpp:330
std::array< char_type, alphabet_size >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::qualified::char_is_valid
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character is valid in the sequence alphabet.
Definition: qualified.hpp:154
seqan3::to_phred
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:89
std::decay_t
seqan3::assign_phred_to
constexpr auto assign_phred_to
Assign a phred score to a quality alphabet object.
Definition: concept.hpp:189
seqan3::qualified
Joins an arbitrary alphabet with a quality alphabet.
Definition: qualified.hpp:59
alphabet_tuple_base.hpp
Provides seqan3::alphabet_tuple_base.
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:417
seqan3::alphabet_base< qualified< sequence_alphabet_t, quality_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::assign_rank
constexpr qualified< sequence_alphabet_t, quality_alphabet_t > & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:167
seqan3::complement
constexpr auto complement
Return the complement of a nucleotide object.
Definition: concept.hpp:95
seqan3::qualified::phred_type
alphabet_phred_t< quality_alphabet_type > phred_type
Equals the phred_type of the quality_alphabet_type.
Definition: qualified.hpp:74
seqan3::alphabet_base< qualified< sequence_alphabet_t, quality_alphabet_t >,(1 *... *alphabet_size< component_types >), void >::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:118
seqan3::qualified::complement
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:146
seqan3::qualified::quality_alphabet_type
quality_alphabet_t quality_alphabet_type
Second template parameter as member type.
Definition: qualified.hpp:69
seqan3::qualified::char_type
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: qualified.hpp:72