SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
aa10murphy.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 
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:
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 // containers
164 // ------------------------------------------------------------------
165 
169 
170 // ------------------------------------------------------------------
171 // literals
172 // ------------------------------------------------------------------
173 
183 constexpr aa10murphy operator""_aa10murphy(char const c) noexcept
184 {
185  return aa10murphy{}.assign_char(c);
186 }
187 
200 inline aa10murphy_vector operator""_aa10murphy(const char * s, std::size_t n)
201 {
203  r.resize(n);
204 
205  for (size_t i = 0; i < n; ++i)
206  r[i].assign_char(s[i]);
207 
208  return r;
209 }
211 
212 } // namespace seqan3
std::vector::resize
T resize(T... args)
concept.hpp
Provides seqan3::aminoacid_alphabet.
seqan3::aa10murphy
The reduced Murphy amino acid alphabet.
Definition: aa10murphy.hpp:80
seqan3::alphabet_base< aa10murphy, size, char >::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:176
vector
seqan3::aa10murphy::char_to_rank
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa10murphy.hpp:124
seqan3::alphabet_base< aa10murphy, size, char >
aminoacid_base.hpp
Provides seqan3::aminoacid_base.
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:142
seqan3::aa10murphy::rank_to_char
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa10murphy.hpp:109
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::alphabet_base< aa10murphy, size, char >::char_type
std::conditional_t< std::same_as< char, void >, char, char > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition: alphabet_base.hpp:62
transform.hpp
Provides utilities for modifying characters.
seqan3::aa10murphy::aa10murphy
constexpr aa10murphy() noexcept=default
Defaulted.
seqan3::aminoacid_base
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:30
std::size_t
seqan3::to_lower
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
std::conditional_t