SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
aa20.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
15 #include <vector>
16 
20 
21 namespace seqan3
22 {
23 
61 class aa20 : public aminoacid_base<aa20, 20>
62 {
63 private:
66 
68  friend base_t;
70  friend base_t::base_t;
72 
73 public:
77  constexpr aa20() noexcept = default;
78  constexpr aa20(aa20 const &) noexcept = default;
79  constexpr aa20(aa20 &&) noexcept = default;
80  constexpr aa20 & operator=(aa20 const &) noexcept = default;
81  constexpr aa20 & operator=(aa20 &&) noexcept = default;
82  ~aa20() noexcept = default;
83 
84  using base_t::base_t;
86 
87 protected:
89  static constexpr char_type rank_to_char[alphabet_size]
90  {
91  'A',
92  'C',
93  'D',
94  'E',
95  'F',
96  'G',
97  'H',
98  'I',
99  'K',
100  'L',
101  'M',
102  'N',
103  'P',
104  'Q',
105  'R',
106  'S',
107  'T',
108  'V',
109  'W',
110  'Y',
111  };
112 
115  {
116  [] () constexpr
117  {
119 
120  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
121  for (auto & c : ret)
122  c = 15; // value of 'S', because that appears most frequently
123 
124  // reverse mapping for characters and their lowercase
125  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
126  {
127  ret[static_cast<rank_type>( rank_to_char[rnk]) ] = rnk;
128  ret[static_cast<rank_type>(to_lower(rank_to_char[rnk]))] = rnk;
129  }
130 
131  ret['B'] = ret['D']; ret['b'] = ret['D']; // Convert b (either D/N) to D, since D occurs more frequently.
132  ret['J'] = ret['L']; ret['j'] = ret['L']; // Convert j (either I/L) to L, since L occurs more frequently.
133  ret['O'] = ret['L']; ret['o'] = ret['L']; // Convert Pyrrolysine to lysine.
134  ret['U'] = ret['C']; ret['u'] = ret['C']; // Convert Selenocysteine to cysteine.
135  ret['X'] = ret['S']; ret['x'] = ret['S']; // Convert unknown amino acids to serine.
136  ret['Z'] = ret['E']; ret['z'] = ret['E']; // Convert z (either E/Q) to E, since E occurs more frequently.
137  ret['*'] = ret['W']; // The most common stop codon is UGA. This is most similar to a Tryptophan.
138  return ret;
139  }()
140  };
141 };
142 
143 } // namespace seqan3
144 
145 // ------------------------------------------------------------------
146 // type traits
147 // ------------------------------------------------------------------
148 
149 namespace seqan3
150 {
151 
156 template <>
158 
159 } // namespace seqan3
160 
161 // ------------------------------------------------------------------
162 // containers
163 // ------------------------------------------------------------------
164 
165 namespace seqan3
166 {
170 
171 } // namespace seqan3
172 
173 // ------------------------------------------------------------------
174 // literals
175 // ------------------------------------------------------------------
176 
177 namespace seqan3
178 {
179 
192 constexpr aa20 operator""_aa20(char const c) noexcept
193 {
194  return aa20{}.assign_char(c);
195 }
196 
211 inline aa20_vector operator""_aa20(const char * s, std::size_t n)
212 {
213  aa20_vector r;
214  r.resize(n);
215 
216  for (size_t i = 0; i < n; ++i)
217  r[i].assign_char(s[i]);
218 
219  return r;
220 }
222 
223 } // namespace seqan3
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa20.hpp:115
The main SeqAn3 namespace.
The canonical amino acid alphabet.
Definition: aa20.hpp:61
T resize(T... args)
Provides seqan3::aminoacid_base.
~aa20() noexcept=default
Defaulted.
static detail::min_viable_uint_t< size > constexpr alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:175
constexpr aa20 & operator=(aa20 const &) noexcept=default
Defaulted.
constexpr aa20() noexcept=default
Defaulted.
Provides utilities for modifying characters.
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:29
Provides seqan3::AminoacidAlphabet.
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:141
Identifies amino acid alphabets.
Definition: concept.hpp:43
std::conditional_t< std::Same< char, void >, char, char > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition: alphabet_base.hpp:61
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa20.hpp:90
constexpr char_type to_lower(char_type const c) noexcept
Converts &#39;A&#39;-&#39;Z&#39; to &#39;a&#39;-&#39;z&#39; respectively; other characters are returned as is.
Definition: transform.hpp:82