SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
aa10murphy.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
81 class aa10murphy : public aminoacid_base<aa10murphy, 10>
82 {
83 private:
86 
88  friend base_t;
90  friend base_t::base_t;
92 
93 public:
97  constexpr aa10murphy() noexcept = default;
98  constexpr aa10murphy(aa10murphy const &) noexcept = default;
99  constexpr aa10murphy(aa10murphy &&) noexcept = default;
100  constexpr aa10murphy & operator=(aa10murphy const &) noexcept = default;
101  constexpr aa10murphy & operator=(aa10murphy &&) noexcept = default;
102  ~aa10murphy() noexcept = default;
103 
105  using base_t::base_t;
107 
108 private:
110  static constexpr char_type rank_to_char_table[alphabet_size]
111  {
112  'A',
113  'B',
114  'C',
115  'F',
116  'G',
117  'H',
118  'I',
119  'K',
120  'P',
121  'S'
122  };
123 
125  static constexpr std::array<rank_type, 256> char_to_rank_table
126  {
127  [] () constexpr
128  {
130 
131  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
132  for (auto & c : ret)
133  c = 9; // value of 'S', because that appears most frequently
134 
135  // reverse mapping for characters and their lowercase
136  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
137  {
138  ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
139  ret[static_cast<rank_type>(to_lower(rank_to_char_table[rnk]))] = rnk;
140  }
141 
142  ret['D'] = ret['B']; ret['d'] = ret['B']; // Convert D to B (either D/N).
143  ret['E'] = ret['B']; ret['e'] = ret['B']; // Convert E to B (either D/N).
144  ret['J'] = ret['I']; ret['j'] = ret['I']; // Convert J (either I/L) to I.
145  ret['L'] = ret['I']; ret['l'] = ret['I']; // Convert L to I.
146  ret['M'] = ret['I']; ret['m'] = ret['I']; // Convert M to I.
147  ret['N'] = ret['B']; ret['n'] = ret['B']; // Convert N to B (either D/N).
148  ret['O'] = ret['K']; ret['o'] = ret['K']; // Convert Pyrrolysine to K.
149  ret['Q'] = ret['B']; ret['q'] = ret['B']; // Convert Q to B (either D/N).
150  ret['R'] = ret['K']; ret['r'] = ret['K']; // Convert R to K.
151  ret['T'] = ret['S']; ret['t'] = ret['S']; // Convert T to S.
152  ret['U'] = ret['C']; ret['u'] = ret['C']; // Convert Selenocysteine to C.
153  ret['V'] = ret['I']; ret['v'] = ret['I']; // Convert V to I.
154  ret['W'] = ret['F']; ret['w'] = ret['F']; // Convert W to F.
155  ret['X'] = ret['S']; ret['x'] = ret['S']; // Convert unknown amino acids to Serine.
156  ret['Y'] = ret['F']; ret['y'] = ret['F']; // Convert Y to F.
157  ret['Z'] = ret['B']; ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
158  ret['*'] = ret['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in this alphabet gets converted to Phenylalanine.
159  return ret;
160  }()
161  };
162 
164  static constexpr char_type rank_to_char(rank_type const rank)
165  {
166  return rank_to_char_table[rank];
167  }
168 
170  static constexpr rank_type char_to_rank(char_type const chr)
171  {
172  using index_t = std::make_unsigned_t<char_type>;
173  return char_to_rank_table[static_cast<index_t>(chr)];
174  }
175 };
176 
177 // ------------------------------------------------------------------
178 // containers
179 // ------------------------------------------------------------------
180 
187 
188 // ------------------------------------------------------------------
189 // literals
190 // ------------------------------------------------------------------
191 inline namespace literals
192 {
193 
207 constexpr aa10murphy operator""_aa10murphy(char const c) noexcept
208 {
209  return aa10murphy{}.assign_char(c);
210 }
211 
223 inline aa10murphy_vector operator""_aa10murphy(char const * const s, size_t const n)
224 {
226  r.resize(n);
227 
228  for (size_t i = 0; i < n; ++i)
229  r[i].assign_char(s[i]);
230 
231  return r;
232 }
234 
235 } // inline namespace literals
236 
237 } // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::aminoacid_base.
The reduced Murphy amino acid alphabet.
Definition: aa10murphy.hpp:82
constexpr aa10murphy() noexcept=default
Defaulted.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:81
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:104
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:211
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:276
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:96
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:81
T resize(T... args)
Provides utilities for modifying characters.