SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
aa27.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
21 namespace seqan3
22 {
43 class aa27 : public aminoacid_base<aa27, 27>
44 {
45 private:
48 
50  friend base_t;
52  friend base_t::base_t;
54 
55 public:
59  constexpr aa27() noexcept = default;
60  constexpr aa27(aa27 const &) noexcept = default;
61  constexpr aa27(aa27 &&) noexcept = default;
62  constexpr aa27 & operator=(aa27 const &) noexcept = default;
63  constexpr aa27 & operator=(aa27 &&) noexcept = default;
64  ~aa27() noexcept = default;
65 
66  using base_t::base_t;
68 
69 protected:
72  {
73  'A',
74  'B',
75  'C',
76  'D',
77  'E',
78  'F',
79  'G',
80  'H',
81  'I',
82  'J',
83  'K',
84  'L',
85  'M',
86  'N',
87  'O',
88  'P',
89  'Q',
90  'R',
91  'S',
92  'T',
93  'U',
94  'V',
95  'W',
96  'X',
97  'Y',
98  'Z',
99  '*'
100  };
101 
104  {
105  [] () constexpr
106  {
108 
109  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
110  for (auto & c : ret)
111  c = 23; // value of 'X'
112 
113  // reverse mapping for characters and their lowercase
114  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
115  {
116  ret[static_cast<rank_type>( rank_to_char[rnk]) ] = rnk;
117  ret[static_cast<rank_type>(to_lower(rank_to_char[rnk]))] = rnk;
118  }
119 
120  return ret;
121  }()
122  };
123 };
124 
125 } // namespace seqan3
126 
127 // ------------------------------------------------------------------
128 // containers
129 // ------------------------------------------------------------------
130 
131 namespace seqan3
132 {
136 
137 } // namespace seqan3
138 
139 // ------------------------------------------------------------------
140 // literals
141 // ------------------------------------------------------------------
142 
143 namespace seqan3
144 {
145 
158 constexpr aa27 operator""_aa27(char const c) noexcept
159 {
160  return aa27{}.assign_char(c);
161 }
162 
177 inline aa27_vector operator""_aa27(const char * s, std::size_t n)
178 {
179  aa27_vector r;
180  r.resize(n);
181 
182  for (size_t i = 0; i < n; ++i)
183  r[i].assign_char(s[i]);
184 
185  return r;
186 }
188 
189 } // namespace seqan3
std::vector::resize
T resize(T... args)
concept.hpp
Provides seqan3::aminoacid_alphabet.
seqan3::alphabet_base< aa27, size, char >::alphabet_size
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:176
vector
seqan3::alphabet_base< aa27, size, char >
aminoacid_base.hpp
Provides seqan3::aminoacid_base.
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:142
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::aa27::rank_to_char
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa27.hpp:72
seqan3::aa27::aa27
constexpr aa27() noexcept=default
Defaulted.
seqan3::alphabet_base< aa27, size, char >::char_type
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:62
transform.hpp
Provides utilities for modifying characters.
seqan3::aa27::char_to_rank
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa27.hpp:104
seqan3::aminoacid_base
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:30
std::size_t
seqan3::to_lower
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:81
std::conditional_t
seqan3::aa27
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:44