SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
aa10murphy.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{
20
78class aa10murphy : public aminoacid_base<aa10murphy, 10>
79{
80private:
83
85 friend base_t;
88 friend base_t::base_t;
90
91public:
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
106private:
108 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'F', 'G', 'H', 'I', 'K', 'P', 'S'};
109
111 static constexpr char_type rank_to_char(rank_type const rank)
112 {
113 return rank_to_char_table[rank];
114 }
115
117 static constexpr rank_type char_to_rank(char_type const chr)
118 {
119 using index_t = std::make_unsigned_t<char_type>;
120 return char_to_rank_table[static_cast<index_t>(chr)];
121 }
122
123 // clang-format off
125 static constexpr std::array<rank_type, 256> char_to_rank_table{
126 []() constexpr {
128
129 // initialize with 'S' because that appears most frequently
130 ret.fill(9u);
131
132 // reverse mapping for characters and their lowercase
133 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
134 {
135 ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
136 ret[static_cast<rank_type>(to_lower(rank_to_char_table[rnk]))] = rnk;
137 }
138
139 ret['D'] = ret['B'];
140 ret['d'] = ret['B']; // Convert D to B (either D/N).
141 ret['E'] = ret['B'];
142 ret['e'] = ret['B']; // Convert E to B (either D/N).
143 ret['J'] = ret['I'];
144 ret['j'] = ret['I']; // Convert J (either I/L) to I.
145 ret['L'] = ret['I'];
146 ret['l'] = ret['I']; // Convert L to I.
147 ret['M'] = ret['I'];
148 ret['m'] = ret['I']; // Convert M to I.
149 ret['N'] = ret['B'];
150 ret['n'] = ret['B']; // Convert N to B (either D/N).
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['T'] = ret['S'];
158 ret['t'] = ret['S']; // Convert T to S.
159 ret['U'] = ret['C'];
160 ret['u'] = ret['C']; // Convert Selenocysteine to C.
161 ret['V'] = ret['I'];
162 ret['v'] = ret['I']; // Convert V to I.
163 ret['W'] = ret['F'];
164 ret['w'] = ret['F']; // Convert W to F.
165 ret['X'] = ret['S'];
166 ret['x'] = ret['S']; // Convert unknown amino acids to Serine.
167 ret['Y'] = ret['F'];
168 ret['y'] = ret['F']; // Convert Y to F.
169 ret['Z'] = ret['B'];
170 ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
171 ret['*'] = ret['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in
172 // this alphabet gets converted to Phenylalanine.
173
174 return ret;
175 }()
176 };
177};
178// clang-format on
179
180// ------------------------------------------------------------------
181// containers
182// ------------------------------------------------------------------
183
190
191// ------------------------------------------------------------------
192// literals
193// ------------------------------------------------------------------
194inline namespace literals
195{
196
210constexpr aa10murphy operator""_aa10murphy(char const c) noexcept
211{
212 return aa10murphy{}.assign_char(c);
213}
214
226SEQAN3_WORKAROUND_LITERAL aa10murphy_vector operator""_aa10murphy(char const * const s, size_t const n)
227{
229 r.resize(n);
230
231 for (size_t i = 0; i < n; ++i)
232 r[i].assign_char(s[i]);
233
234 return r;
235}
237
238} // namespace literals
239
240} // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::aminoacid_base.
The reduced Murphy amino acid alphabet.
Definition aa10murphy.hpp:79
constexpr aa10murphy() 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