SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
aa10li.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 
15 #include <vector>
16 
20 
21 namespace seqan3
22 {
82 class aa10li : public aminoacid_base<aa10li, 10>
83 {
84 private:
87 
89  friend base_t;
91  friend base_t::base_t;
93 
94 public:
98  constexpr aa10li() noexcept = default;
99  constexpr aa10li(aa10li const &) noexcept = default;
100  constexpr aa10li(aa10li &&) noexcept = default;
101  constexpr aa10li & operator=(aa10li const &) noexcept = default;
102  constexpr aa10li & operator=(aa10li &&) noexcept = default;
103  ~aa10li() noexcept = default;
104 
106  using base_t::base_t;
108 
109 private:
111  static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'F', 'G', 'H', 'I', 'J', 'K', 'P'};
112 
114  static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr {std::array<rank_type, 256> ret{};
115 
116  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
117  for (auto & c : ret)
118  c = 0; // value of 'A', because S appears most frequently and gets converted to A in this alphabet
119 
120  // reverse mapping for characters and their lowercase
121  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
122  {
123  ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
124  ret[static_cast<rank_type>(to_lower(rank_to_char_table[rnk]))] = rnk;
125  }
126 
127  ret['D'] = ret['B'];
128  ret['d'] = ret['B']; // Convert D to B (either D/N).
129  ret['E'] = ret['B'];
130  ret['e'] = ret['B']; // Convert E to B (either D/N).
131  ret['L'] = ret['J'];
132  ret['l'] = ret['J']; // Convert L to J (either I/L).
133  ret['M'] = ret['J'];
134  ret['m'] = ret['J']; // Convert M to J (either I/L).
135  ret['N'] = ret['H'];
136  ret['n'] = ret['H']; // Convert N to H.
137  ret['O'] = ret['K'];
138  ret['o'] = ret['K']; // Convert Pyrrolysine to K.
139  ret['Q'] = ret['B'];
140  ret['q'] = ret['B']; // Convert Q to B (either D/N).
141  ret['R'] = ret['K'];
142  ret['r'] = ret['K']; // Convert R to K.
143  ret['S'] = ret['A'];
144  ret['s'] = ret['A']; // Convert S to A.
145  ret['T'] = ret['A'];
146  ret['t'] = ret['A']; // Convert T to A.
147  ret['U'] = ret['C'];
148  ret['u'] = ret['C']; // Convert Selenocysteine to C.
149  ret['V'] = ret['I'];
150  ret['v'] = ret['I']; // Convert V to I.
151  ret['W'] = ret['F'];
152  ret['w'] = ret['F']; // Convert W to F.
153  ret['X'] = ret['A'];
154  ret['x'] = ret['A']; // Convert unknown amino acids to Alanine.
155  ret['Y'] = ret['F'];
156  ret['y'] = ret['F']; // Convert Y to F.
157  ret['Z'] = ret['B'];
158  ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
159  ret['*'] = ret
160  ['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in this alphabet gets converted to Phenylalanine.
161  return ret;
162 }()
163 }; // namespace seqan3
164 
166 static constexpr rank_type char_to_rank(char_type const chr)
167 {
168  using index_t = std::make_unsigned_t<char_type>;
169  return char_to_rank_table[static_cast<index_t>(chr)];
170 }
171 
173 static constexpr char_type rank_to_char(rank_type const rank)
174 {
175  return rank_to_char_table[rank];
176 }
177 }
178 ;
179 
180 // ------------------------------------------------------------------
181 // containers
182 // ------------------------------------------------------------------
183 
190 
191 // ------------------------------------------------------------------
192 // literals
193 // ------------------------------------------------------------------
194 inline namespace literals
195 {
196 
210 constexpr aa10li operator""_aa10li(char const c) noexcept
211 {
212  return aa10li{}.assign_char(c);
213 }
214 
226 inline aa10li_vector operator""_aa10li(char const * const s, size_t const n)
227 {
228  aa10li_vector r;
229  r.resize(n);
230 
231  for (size_t i = 0; i < n; ++i)
232  r[i].assign_char(s[i]);
233 
234  return r;
235 }
237 
238 } // namespace literals
239 
240 } // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::aminoacid_base.
The reduced Li amino acid alphabet.
Definition: aa10li.hpp:83
constexpr aa10li() noexcept=default
Defaulted.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:57
constexpr derived_type & assign_char(char_type const chr) noexcept requires(!std
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:163
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition: alphabet_base.hpp:80
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:199
std::conditional_t< std::same_as< char_t, void >, char, char_t > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition: alphabet_base.hpp:72
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:32
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
constexpr char_type to_lower(char_type const c) noexcept
Converts 'A'-'Z' to 'a'-'z' respectively; other characters are returned as is.
Definition: transform.hpp:83
T resize(T... args)
Provides utilities for modifying characters.