SeqAn3
aa27.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <vector>
43 
46 
47 namespace seqan3
48 {
67 class aa27 : public aminoacid_base<aa27, 27>
68 {
69 private:
72 
74  friend base_t;
76  friend base_t::base_t;
78 
79 public:
83  constexpr aa27() : base_t{} {}
84  constexpr aa27(aa27 const &) = default;
85  constexpr aa27(aa27 &&) = default;
86  constexpr aa27 & operator=(aa27 const &) = default;
87  constexpr aa27 & operator=(aa27 &&) = default;
88  ~aa27() = default;
89 
90  using base_t::base_t;
92 
93 protected:
95  static constexpr char_type rank_to_char[value_size]
96  {
97  'A',
98  'B',
99  'C',
100  'D',
101  'E',
102  'F',
103  'G',
104  'H',
105  'I',
106  'J',
107  'K',
108  'L',
109  'M',
110  'N',
111  'O',
112  'P',
113  'Q',
114  'R',
115  'S',
116  'T',
117  'U',
118  'V',
119  'W',
120  'X',
121  'Y',
122  'Z',
123  '*'
124  };
125 
127  static constexpr std::array<rank_type, 256> char_to_rank
128  {
129  [] () constexpr
130  {
131  std::array<rank_type, 256> ret{};
132 
133  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
134  for (auto & c : ret)
135  c = 23; // value of 'X'
136 
137  // reverse mapping for characters and their lowercase
138  for (rank_type rnk = 0u; rnk < value_size; ++rnk)
139  {
140  ret[static_cast<rank_type>( rank_to_char[rnk]) ] = rnk;
141  ret[static_cast<rank_type>(to_lower(rank_to_char[rnk]))] = rnk;
142  }
143 
144  return ret;
145  }()
146  };
147 };
148 
149 } // namespace seqan3
150 
151 // ------------------------------------------------------------------
152 // containers
153 // ------------------------------------------------------------------
154 
155 namespace seqan3
156 {
159 using aa27_vector = std::vector<aa27>;
160 
161 } // namespace seqan3
162 
163 // ------------------------------------------------------------------
164 // literals
165 // ------------------------------------------------------------------
166 
167 namespace seqan3
168 {
169 
182 inline aa27_vector operator""_aa27(const char * s, std::size_t n)
183 {
184  aa27_vector r;
185  r.resize(n);
186 
187  for (size_t i = 0; i < n; ++i)
188  r[i].assign_char(s[i]);
189 
190  return r;
191 }
192 
193 } // namespace seqan3
alphabet_concept && assign_char(alphabet_concept &&alph, char_type const chr)
Returns the alphabet letter&#39;s value in character representation.
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:89
std::vector< aa27 > aa27_vector
Alias for an std::vector of seqan3::aa27.
Definition: aa27.hpp:159
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:67
Free function/metafunction wrappers for alphabets with member functions/types.
static detail::min_viable_uint_t< size > constexpr value_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:198
char_t char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
static constexpr char_type rank_to_char[value_size]
Value to char conversion table.
Definition: aa27.hpp:96
Provides utilities for modifying characters.
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:57
static constexpr std::array< rank_type, 256 > char_to_rank
Char to value conversion table.
Definition: aa27.hpp:128
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: char_operations.hpp:107