SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
aa10murphy.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 
79 class aa10murphy : public aminoacid_base<aa10murphy, 10>
80 {
81 private:
84 
86  friend base_t;
88  friend base_t::base_t;
90 
91 public:
95  constexpr aa10murphy() noexcept = default;
96  constexpr aa10murphy(aa10murphy const &) noexcept = default;
97  constexpr aa10murphy(aa10murphy &&) noexcept = default;
98  constexpr aa10murphy & operator=(aa10murphy const &) noexcept = default;
99  constexpr aa10murphy & operator=(aa10murphy &&) noexcept = default;
100  ~aa10murphy() noexcept = default;
101 
103  using base_t::base_t;
105 
106 protected:
108  static constexpr char_type rank_to_char[alphabet_size]
109  {
110  'A',
111  'B',
112  'C',
113  'F',
114  'G',
115  'H',
116  'I',
117  'K',
118  'P',
119  'S',
120  };
121 
124  {
125  [] () constexpr
126  {
128 
129  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
130  for (auto & c : ret)
131  c = 9; // value of 'S', because that appears most frequently
132 
133  // reverse mapping for characters and their lowercase
134  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
135  {
136  ret[static_cast<rank_type>( rank_to_char[rnk]) ] = rnk;
137  ret[static_cast<rank_type>(to_lower(rank_to_char[rnk]))] = rnk;
138  }
139 
140  ret['D'] = ret['B']; ret['d'] = ret['B']; // Convert D to B (either D/N).
141  ret['E'] = ret['B']; ret['e'] = ret['B']; // Convert E to B (either D/N).
142  ret['J'] = ret['I']; ret['j'] = ret['I']; // Convert J (either I/L) to I.
143  ret['L'] = ret['I']; ret['l'] = ret['I']; // Convert L to I.
144  ret['M'] = ret['I']; ret['m'] = ret['I']; // Convert M to I.
145  ret['N'] = ret['B']; ret['n'] = ret['B']; // Convert N to B (either D/N).
146  ret['O'] = ret['K']; ret['o'] = ret['K']; // Convert Pyrrolysine to K.
147  ret['Q'] = ret['B']; ret['q'] = ret['B']; // Convert Q to B (either D/N).
148  ret['R'] = ret['K']; ret['r'] = ret['K']; // Convert R to K.
149  ret['T'] = ret['S']; ret['t'] = ret['S']; // Convert T to S.
150  ret['U'] = ret['C']; ret['u'] = ret['C']; // Convert Selenocysteine to C.
151  ret['V'] = ret['I']; ret['v'] = ret['I']; // Convert V to I.
152  ret['W'] = ret['F']; ret['w'] = ret['F']; // Convert W to F.
153  ret['X'] = ret['S']; ret['x'] = ret['S']; // Convert unknown amino acids to Serine.
154  ret['Y'] = ret['F']; ret['y'] = ret['F']; // Convert Y to F.
155  ret['Z'] = ret['B']; ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
156  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.
157  return ret;
158  }()
159  };
160 };
161 
162 // ------------------------------------------------------------------
163 // type traits
164 // ------------------------------------------------------------------
165 
170 template <>
172 
173 // ------------------------------------------------------------------
174 // containers
175 // ------------------------------------------------------------------
176 
180 
181 // ------------------------------------------------------------------
182 // literals
183 // ------------------------------------------------------------------
184 
194 constexpr aa10murphy operator""_aa10murphy(char const c) noexcept
195 {
196  return aa10murphy{}.assign_char(c);
197 }
198 
211 inline aa10murphy_vector operator""_aa10murphy(const char * s, std::size_t n)
212 {
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
constexpr aa10murphy() noexcept=default
Defaulted.
The main SeqAn3 namespace.
T resize(T... args)
Provides seqan3::aminoacid_base.
~aa10murphy() noexcept=default
Defaulted.
The reduced Murphy amino acid alphabet.
Definition: aa10murphy.hpp:79
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 aa10murphy & operator=(aa10murphy const &) 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
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa10murphy.hpp:109
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 std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa10murphy.hpp:124
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