SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
aa27.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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:
71  static constexpr char_type rank_to_char[alphabet_size]
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 // type traits
129 // ------------------------------------------------------------------
130 
131 namespace seqan3
132 {
133 
138 template <>
140 
141 } // namespace seqan3
142 
143 // ------------------------------------------------------------------
144 // containers
145 // ------------------------------------------------------------------
146 
147 namespace seqan3
148 {
152 
153 } // namespace seqan3
154 
155 // ------------------------------------------------------------------
156 // literals
157 // ------------------------------------------------------------------
158 
159 namespace seqan3
160 {
161 
174 constexpr aa27 operator""_aa27(char const c) noexcept
175 {
176  return aa27{}.assign_char(c);
177 }
178 
193 inline aa27_vector operator""_aa27(const char * s, std::size_t n)
194 {
195  aa27_vector r;
196  r.resize(n);
197 
198  for (size_t i = 0; i < n; ++i)
199  r[i].assign_char(s[i]);
200 
201  return r;
202 }
204 
205 } // namespace seqan3
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:63
The main SeqAn3 namespace.
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:43
T resize(T... args)
Provides seqan3::aminoacid_base.
static constexpr char_type rank_to_char[alphabet_size]
Value to char conversion table.
Definition: aa27.hpp:72
static detail::min_viable_uint_t< size > constexpr alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:175
constexpr aa27 & operator=(aa27 const &) noexcept=default
Defaulted.
Provides utilities for modifying characters.
~aa27() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:29
constexpr aa27() noexcept=default
Defaulted.
Provides seqan3::AminoacidAlphabet.
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa27.hpp:104
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:141
Identifies amino acid alphabets.
Definition: concept.hpp:43
constexpr char_type to_lower(char_type const c) noexcept
Converts &#39;A&#39;-&#39;Z&#39; to &#39;a&#39;-&#39;z&#39; respectively; other characters are returned as is.
Definition: transform.hpp:82