BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
aa27.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
22namespace bio::alphabet
23{
44class aa27 : public aminoacid_base<aa27, 27>
45{
46private:
49
51 friend base_t;
53 friend base_t::base_t;
55
56public:
60 constexpr aa27() noexcept = default;
61 constexpr aa27(aa27 const &) noexcept = default;
62 constexpr aa27(aa27 &&) noexcept = default;
63 constexpr aa27 & operator=(aa27 const &) noexcept = default;
64 constexpr aa27 & operator=(aa27 &&) noexcept = default;
65 ~aa27() noexcept = default;
66
67 using base_t::base_t;
69
70protected:
72 static constexpr std::array<char_type, alphabet_size> rank_to_char{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
73 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
74 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '*'};
75
77 static constexpr std::array<rank_type, 256> char_to_rank = []() constexpr
78 {
80
81 // initialize with UNKNOWN
82 ret.fill(23); // value of 'X'
83
84 // reverse mapping for characters and their lowercase
85 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
86 {
87 ret[static_cast<rank_type>(rank_to_char[rnk])] = rnk;
88 ret[static_cast<rank_type>(detail::to_lower(rank_to_char[rnk]))] = rnk;
89 }
90
91 return ret;
92 }();
93};
94
95} // namespace bio::alphabet
96
97// ------------------------------------------------------------------
98// literals
99// ------------------------------------------------------------------
100
101namespace bio::alphabet
102{
103
104inline namespace literals
105{
106
115consteval aa27 operator""_aa27(char const c)
116{
117 if (!char_is_valid_for<aa27>(c))
118 throw std::invalid_argument{"Illegal character in character literal."};
119
120 return aa27{}.assign_char(c);
121}
122
132template <meta::detail::literal_buffer_string str>
133constexpr std::vector<aa27> operator""_aa27()
134{
135 return detail::string_literal<str, aa27>();
136}
138
139} // namespace literals
140
141} // namespace bio::alphabet
Provides bio::alphabet::aminoacid.
Provides bio::alphabet::aminoacid_base.
The twenty-seven letter amino acid alphabet..
Definition: aa27.hpp:45
static constexpr std::array< char_type, alphabet_size > rank_to_char
Value to char conversion table.
Definition: aa27.hpp:72
constexpr aa27() noexcept=default
Defaulted.
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa27.hpp:77
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
T fill(T... args)
The alphabet module's namespace.
Definition: aa10li.hpp:23