BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
aa10li.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <vector>
17
20#include <bio/alphabet/detail/to_lower.hpp>
21
23{
81class aa10li : public aminoacid_base<aa10li, 10>
82{
83private:
86
88 friend base_t;
90 friend base_t::base_t;
92
93public:
97 constexpr aa10li() noexcept = default;
98 constexpr aa10li(aa10li const &) noexcept = default;
99 constexpr aa10li(aa10li &&) noexcept = default;
100 constexpr aa10li & operator=(aa10li const &) noexcept = default;
101 constexpr aa10li & operator=(aa10li &&) noexcept = default;
102 ~aa10li() noexcept = default;
103
105 using base_t::base_t;
107
108protected:
110 static constexpr std::array<char_type, alphabet_size> rank_to_char{
111 'A',
112 'B',
113 'C',
114 'F',
115 'G',
116 'H',
117 'I',
118 'J',
119 'K',
120 'P',
121 };
122
124 static constexpr std::array<rank_type, 256> char_to_rank = []() constexpr
125 {
127
128 // reverse mapping for characters and their lowercase
129 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
130 {
131 ret[static_cast<rank_type>(rank_to_char[rnk])] = rnk;
132 ret[static_cast<rank_type>(detail::to_lower(rank_to_char[rnk]))] = rnk;
133 }
134
135 ret['D'] = ret['B'];
136 ret['d'] = ret['B']; // Convert D to B (either D/N).
137 ret['E'] = ret['B'];
138 ret['e'] = ret['B']; // Convert E to B (either D/N).
139 ret['L'] = ret['J'];
140 ret['l'] = ret['J']; // Convert L to J (either I/L).
141 ret['M'] = ret['J'];
142 ret['m'] = ret['J']; // Convert M to J (either I/L).
143 ret['N'] = ret['H'];
144 ret['n'] = ret['H']; // Convert N to H.
145 ret['O'] = ret['K'];
146 ret['o'] = ret['K']; // Convert Pyrrolysine to K.
147 ret['Q'] = ret['B'];
148 ret['q'] = ret['B']; // Convert Q to B (either D/N).
149 ret['R'] = ret['K'];
150 ret['r'] = ret['K']; // Convert R to K.
151 ret['S'] = ret['A'];
152 ret['s'] = ret['A']; // Convert S to A.
153 ret['T'] = ret['A'];
154 ret['t'] = ret['A']; // Convert T to A.
155 ret['U'] = ret['C'];
156 ret['u'] = ret['C']; // Convert Selenocysteine to C.
157 ret['V'] = ret['I'];
158 ret['v'] = ret['I']; // Convert V to I.
159 ret['W'] = ret['F'];
160 ret['w'] = ret['F']; // Convert W to F.
161 ret['X'] = ret['A'];
162 ret['x'] = ret['A']; // Convert unknown amino acids to Alanine.
163 ret['Y'] = ret['F'];
164 ret['y'] = ret['F']; // Convert Y to F.
165 ret['Z'] = ret['B'];
166 ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
167 ret['*'] = ret
168 ['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in this alphabet gets converted to Phenylalanine.
169 return ret;
170 }();
171};
172
173} // namespace bio::alphabet
174
175// ------------------------------------------------------------------
176// literals
177// ------------------------------------------------------------------
178
179namespace bio::alphabet
180{
181
182inline namespace literals
183{
184
193consteval aa10li operator""_aa10li(char const c)
194{
195 if (!char_is_valid_for<aa10li>(c))
196 throw std::invalid_argument{"Illegal character in character literal."};
197
198 return aa10li{}.assign_char(c);
199}
200
210template <meta::detail::literal_buffer_string str>
211constexpr std::vector<aa10li> operator""_aa10li()
212{
213 return detail::string_literal<str, aa10li>();
214}
216
217} // namespace literals
218
219} // namespace bio::alphabet
Provides bio::alphabet::aminoacid.
Provides bio::alphabet::aminoacid_base.
The reduced Li amino acid alphabet..
Definition: aa10li.hpp:82
static constexpr std::array< char_type, alphabet_size > rank_to_char
Value to char conversion table.
Definition: aa10li.hpp:110
constexpr aa10li() noexcept=default
Defaulted.
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa10li.hpp:124
A CRTP-base that refines bio::alphabet::base and is used by the amino acids.
Definition: aminoacid_base.hpp:31
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
The alphabet module's namespace.
Definition: aa10li.hpp:23