SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
aa10li.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <vector>
13
17
18namespace seqan3
19{
79class aa10li : public aminoacid_base<aa10li, 10>
80{
81private:
84
86 friend base_t;
89 friend base_t::base_t;
91
92public:
96 constexpr aa10li() noexcept = default;
97 constexpr aa10li(aa10li const &) noexcept = default;
98 constexpr aa10li(aa10li &&) noexcept = default;
99 constexpr aa10li & operator=(aa10li const &) noexcept = default;
100 constexpr aa10li & operator=(aa10li &&) noexcept = default;
101 ~aa10li() noexcept = default;
102
104 using base_t::base_t;
106
107private:
109 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'F', 'G', 'H', 'I', 'J', 'K', 'P'};
110
112 static constexpr rank_type char_to_rank(char_type const chr)
113 {
114 using index_t = std::make_unsigned_t<char_type>;
115 return char_to_rank_table[static_cast<index_t>(chr)];
116 }
117
119 static constexpr char_type rank_to_char(rank_type const rank)
120 {
121 return rank_to_char_table[rank];
122 }
123
124 // clang-format off
126 static constexpr std::array<rank_type, 256> char_to_rank_table
127 {
128 []() constexpr {
130
131 // initialize with 'A' because S appears most frequently and gets converted to A in this alphabet
132 ret.fill(0u); // Value-initialisation of std::array does usually initialise. `fill` is explicit.
133
134 // reverse mapping for characters and their lowercase
135 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
136 {
137 ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
138 ret[static_cast<rank_type>(to_lower(rank_to_char_table[rnk]))] = rnk;
139 }
140
141 ret['D'] = ret['B'];
142 ret['d'] = ret['B']; // Convert D to B (either D/N).
143 ret['E'] = ret['B'];
144 ret['e'] = ret['B']; // Convert E to B (either D/N).
145 ret['L'] = ret['J'];
146 ret['l'] = ret['J']; // Convert L to J (either I/L).
147 ret['M'] = ret['J'];
148 ret['m'] = ret['J']; // Convert M to J (either I/L).
149 ret['N'] = ret['H'];
150 ret['n'] = ret['H']; // Convert N to H.
151 ret['O'] = ret['K'];
152 ret['o'] = ret['K']; // Convert Pyrrolysine to K.
153 ret['Q'] = ret['B'];
154 ret['q'] = ret['B']; // Convert Q to B (either D/N).
155 ret['R'] = ret['K'];
156 ret['r'] = ret['K']; // Convert R to K.
157 ret['S'] = ret['A'];
158 ret['s'] = ret['A']; // Convert S to A.
159 ret['T'] = ret['A'];
160 ret['t'] = ret['A']; // Convert T to A.
161 ret['U'] = ret['C'];
162 ret['u'] = ret['C']; // Convert Selenocysteine to C.
163 ret['V'] = ret['I'];
164 ret['v'] = ret['I']; // Convert V to I.
165 ret['W'] = ret['F'];
166 ret['w'] = ret['F']; // Convert W to F.
167 ret['X'] = ret['A'];
168 ret['x'] = ret['A']; // Convert unknown amino acids to Alanine.
169 ret['Y'] = ret['F'];
170 ret['y'] = ret['F']; // Convert Y to F.
171 ret['Z'] = ret['B'];
172 ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
173 ret['*'] = ret['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in
174 // this alphabet gets converted to Phenylalanine.
175
176 return ret;
177 }()
178 };
179};
180// clang-format of
181
182// ------------------------------------------------------------------
183// containers
184// ------------------------------------------------------------------
185
192
193// ------------------------------------------------------------------
194// literals
195// ------------------------------------------------------------------
196inline namespace literals
197{
198
212constexpr aa10li operator""_aa10li(char const c) noexcept
213{
214 return aa10li{}.assign_char(c);
215}
216
228SEQAN3_WORKAROUND_LITERAL aa10li_vector operator""_aa10li(char const * const s, size_t const n)
229{
231 r.resize(n);
232
233 for (size_t i = 0; i < n; ++i)
234 r[i].assign_char(s[i]);
235
236 return r;
237}
239
240} // namespace literals
241
242} // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::aminoacid_base.
The reduced Li amino acid alphabet.
Definition aa10li.hpp:80
constexpr aa10li() noexcept=default
Defaulted.
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
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:77
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:196
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:69
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition aminoacid_base.hpp:29
T fill(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:80
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition platform.hpp:269
T resize(T... args)
Provides utilities for modifying characters.
Hide me