SeqAn3  3.0.1
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 
17 
18 namespace seqan3
19 {
20 
54 template <writable_alphabet sequence_alphabet_t, writable_quality_alphabet quality_alphabet_t>
55 class qualified :
56  public alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
57  sequence_alphabet_t, quality_alphabet_t>
58 {
59 private:
62  sequence_alphabet_t, quality_alphabet_t>;
63 
64 public:
66  using sequence_alphabet_type = sequence_alphabet_t;
68  using quality_alphabet_type = quality_alphabet_t;
69 
74 
78  constexpr qualified() noexcept = default;
79  constexpr qualified(qualified const &) noexcept = default;
80  constexpr qualified(qualified &&) noexcept = default;
81  constexpr qualified & operator =(qualified const &) noexcept = default;
82  constexpr qualified & operator =(qualified &&) noexcept = default;
83  ~qualified() noexcept = default;
84 
85  // Inherit from base:
86  using base_type::base_type; // non-default constructors
87  using base_type::alphabet_size;
88  using base_type::to_rank;
89  using base_type::operator=;
90 
92  SEQAN3_DOXYGEN_ONLY(( constexpr qualified(component_type const alph) noexcept {} ))
94  SEQAN3_DOXYGEN_ONLY(( constexpr qualified(indirect_component_type const alph) noexcept {} ))
96  SEQAN3_DOXYGEN_ONLY(( constexpr qualified & operator=(component_type const alph) noexcept {} ))
98  SEQAN3_DOXYGEN_ONLY(( constexpr qualified & operator=(indirect_component_type const alph) noexcept {} ))
100 
104  constexpr qualified & assign_char(char_type const c) noexcept
106  {
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  // seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})));
115  return *this;
116  }
117 
119  constexpr qualified & assign_phred(phred_type const c) noexcept
120  {
121  seqan3::assign_phred_to(c, get<1>(*this));
122  return *this;
123  }
125 
129  constexpr phred_type to_phred() const noexcept
131  {
132  return rank_to_phred[to_rank()];
133  }
134 
136  constexpr char_type to_char() const noexcept
137  {
138  return rank_to_char[to_rank()];
139  }
140 
145  constexpr qualified complement() const noexcept
146  requires nucleotide_alphabet<sequence_alphabet_t>
147  {
148  return qualified{seqan3::complement(get<0>(*this)), get<1>(*this)};
149  }
151 
153  static constexpr bool char_is_valid(char_type const c) noexcept
154  {
155  return char_is_valid_for<sequence_alphabet_type>(c);
156  }
157 
158 protected:
160 
162  static std::array<char_type, alphabet_size> constexpr rank_to_char
163  {
164  [] () constexpr
165  {
167 
168  for (size_t i = 0; i < alphabet_size; ++i)
169  {
170  size_t seq_rank = (i / base_type::cummulative_alph_sizes[0]) %
171  seqan3::alphabet_size<quality_alphabet_type>;
172 
174  }
175 
176  return ret;
177  }()
178  };
179 
181  static std::array<char_type, alphabet_size> constexpr rank_to_phred
182  {
183  [] () constexpr
184  {
186 
187  for (size_t i = 0; i < alphabet_size; ++i)
188  {
189  size_t qual_rank = (i / base_type::cummulative_alph_sizes[1]) %
190  seqan3::alphabet_size<quality_alphabet_type>;
191 
193  }
194 
195  return ret;
196  }()
197  };
198 };
199 
202 template <typename sequence_alphabet_type, typename quality_alphabet_type>
203 qualified(sequence_alphabet_type &&, quality_alphabet_type &&)
204  -> qualified<std::decay_t<sequence_alphabet_type>, std::decay_t<quality_alphabet_type>>;
205 
206 } // namespace seqan3
seqan3::assign_rank_to
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition: concept.hpp:238
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:66
seqan3::alphabet_base::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:174
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:94
seqan3::qualified::to_char
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition: qualified.hpp:136
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:320
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:142
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:105
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:119
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:130
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::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:329
std::array< char_type, alphabet_size >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
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:153
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:55
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:416
seqan3::alphabet_base::assign_rank
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:165
seqan3::complement
constexpr auto complement
Return the complement of a nucleotide object.
Definition: concept.hpp:93
seqan3::qualified::phred_type
alphabet_phred_t< quality_alphabet_type > phred_type
Equals the phred_type of the quality_alphabet_type.
Definition: qualified.hpp:73
seqan3::alphabet_base::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:116
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:145
seqan3::qualified::quality_alphabet_type
quality_alphabet_t quality_alphabet_type
Second template parameter as member type.
Definition: qualified.hpp:68
seqan3::qualified::char_type
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition: qualified.hpp:71