SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
aa10murphy.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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
21namespace seqan3
22{
23
81class aa10murphy : public aminoacid_base<aa10murphy, 10>
82{
83private:
86
88 friend base_t;
91 friend base_t::base_t;
93
94public:
98 constexpr aa10murphy() noexcept = default;
99 constexpr aa10murphy(aa10murphy const &) noexcept = default;
100 constexpr aa10murphy(aa10murphy &&) noexcept = default;
101 constexpr aa10murphy & operator=(aa10murphy const &) noexcept = default;
102 constexpr aa10murphy & operator=(aa10murphy &&) noexcept = default;
103 ~aa10murphy() noexcept = default;
104
106 using base_t::base_t;
108
109private:
111 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'F', 'G', 'H', 'I', 'K', 'P', 'S'};
112
114 static constexpr char_type rank_to_char(rank_type const rank)
115 {
116 return rank_to_char_table[rank];
117 }
118
120 static constexpr rank_type char_to_rank(char_type const chr)
121 {
122 using index_t = std::make_unsigned_t<char_type>;
123 return char_to_rank_table[static_cast<index_t>(chr)];
124 }
125
126 // clang-format off
128 static constexpr std::array<rank_type, 256> char_to_rank_table{
129 []() constexpr {
131
132 // initialize with 'S' because that appears most frequently
133 ret.fill(9u);
134
135 // reverse mapping for characters and their lowercase
136 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
137 {
138 ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
139 ret[static_cast<rank_type>(to_lower(rank_to_char_table[rnk]))] = rnk;
140 }
141
142 ret['D'] = ret['B'];
143 ret['d'] = ret['B']; // Convert D to B (either D/N).
144 ret['E'] = ret['B'];
145 ret['e'] = ret['B']; // Convert E to B (either D/N).
146 ret['J'] = ret['I'];
147 ret['j'] = ret['I']; // Convert J (either I/L) to I.
148 ret['L'] = ret['I'];
149 ret['l'] = ret['I']; // Convert L to I.
150 ret['M'] = ret['I'];
151 ret['m'] = ret['I']; // Convert M to I.
152 ret['N'] = ret['B'];
153 ret['n'] = ret['B']; // Convert N to B (either D/N).
154 ret['O'] = ret['K'];
155 ret['o'] = ret['K']; // Convert Pyrrolysine to K.
156 ret['Q'] = ret['B'];
157 ret['q'] = ret['B']; // Convert Q to B (either D/N).
158 ret['R'] = ret['K'];
159 ret['r'] = ret['K']; // Convert R to K.
160 ret['T'] = ret['S'];
161 ret['t'] = ret['S']; // Convert T to S.
162 ret['U'] = ret['C'];
163 ret['u'] = ret['C']; // Convert Selenocysteine to C.
164 ret['V'] = ret['I'];
165 ret['v'] = ret['I']; // Convert V to I.
166 ret['W'] = ret['F'];
167 ret['w'] = ret['F']; // Convert W to F.
168 ret['X'] = ret['S'];
169 ret['x'] = ret['S']; // Convert unknown amino acids to Serine.
170 ret['Y'] = ret['F'];
171 ret['y'] = ret['F']; // Convert Y to F.
172 ret['Z'] = ret['B'];
173 ret['z'] = ret['B']; // Convert Z (either E/Q) to B (either D/N).
174 ret['*'] = ret['F']; // The most common stop codon is UGA. This is most similar to a Tryptophan which in
175 // this alphabet gets converted to Phenylalanine.
176
177 return ret;
178 }()
179 };
180};
181// clang-format on
182
183// ------------------------------------------------------------------
184// containers
185// ------------------------------------------------------------------
186
193
194// ------------------------------------------------------------------
195// literals
196// ------------------------------------------------------------------
197inline namespace literals
198{
199
213constexpr aa10murphy operator""_aa10murphy(char const c) noexcept
214{
215 return aa10murphy{}.assign_char(c);
216}
217
229SEQAN3_WORKAROUND_LITERAL aa10murphy_vector operator""_aa10murphy(char const * const s, size_t const n)
230{
232 r.resize(n);
233
234 for (size_t i = 0; i < n; ++i)
235 r[i].assign_char(s[i]);
236
237 return r;
238}
240
241} // namespace literals
242
243} // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::aminoacid_base.
The reduced Murphy amino acid alphabet..
Definition: aa10murphy.hpp:82
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:163
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:80
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:199
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:72
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:32
T fill(T... args)
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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:83
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition: platform.hpp:282
T resize(T... args)
Provides utilities for modifying characters.