SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
aa20.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 
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 // containers
147 // ------------------------------------------------------------------
148 
149 namespace seqan3
150 {
154 
155 } // namespace seqan3
156 
157 // ------------------------------------------------------------------
158 // literals
159 // ------------------------------------------------------------------
160 
161 namespace seqan3
162 {
163 
176 constexpr aa20 operator""_aa20(char const c) noexcept
177 {
178  return aa20{}.assign_char(c);
179 }
180 
195 inline aa20_vector operator""_aa20(const char * s, std::size_t n)
196 {
197  aa20_vector r;
198  r.resize(n);
199 
200  for (size_t i = 0; i < n; ++i)
201  r[i].assign_char(s[i]);
202 
203  return r;
204 }
206 
207 } // namespace seqan3
std::vector::resize
T resize(T... args)
concept.hpp
Provides seqan3::aminoacid_alphabet.
seqan3::alphabet_base< aa20, 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:174
vector
seqan3::alphabet_base< aa20, size, char >
seqan3::aa20::char_to_rank
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa20.hpp:115
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:140
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::aa20::rank_to_char
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa20.hpp:90
seqan3::alphabet_base< aa20, 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:60
transform.hpp
Provides utilities for modifying characters.
seqan3::aa20::~aa20
~aa20() 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:29
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
seqan3::aa20
The canonical amino acid alphabet.
Definition: aa20.hpp:61
std::conditional_t
seqan3::aa20::operator=
constexpr aa20 & operator=(aa20 const &) noexcept=default
Defaulted.
seqan3::aa20::aa20
constexpr aa20() noexcept=default
Defaulted.