SeqAn3
dssp9.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 
47 
48 // ------------------------------------------------------------------
49 // dssp9
50 // ------------------------------------------------------------------
51 
52 namespace seqan3
53 {
54 
85 class dssp9 : public alphabet_base<dssp9, 9>
86 {
87 private:
90 
92  friend base_t;
93 
94 public:
98  constexpr dssp9() : base_t{} {}
99  constexpr dssp9(dssp9 const &) = default;
100  constexpr dssp9(dssp9 &&) = default;
101  constexpr dssp9 & operator=(dssp9 const &) = default;
102  constexpr dssp9 & operator=(dssp9 &&) = default;
103  ~dssp9() = default;
105 
110  static const dssp9 H;
112  static const dssp9 B;
113  static const dssp9 E;
114  static const dssp9 G;
115  static const dssp9 I;
116  static const dssp9 T;
117  static const dssp9 S;
118  static const dssp9 C;
119  static const dssp9 X;
121 
122 protected:
124 
126  static constexpr char_type rank_to_char[value_size]
127  {
128  'H', 'B', 'E', 'G', 'I', 'T', 'S', 'C', 'X'
129  };
130 
132  static constexpr std::array<rank_type, 256> char_to_rank
133  {
134  [] () constexpr
135  {
136  std::array<rank_type, 256> ret{};
137 
138  // initialize with X (std::array::fill unfortunately not constexpr)
139  for (rank_type & rnk : ret)
140  rnk = 8;
141 
142  // reverse mapping for characters
143  for (rank_type rnk = 0u; rnk < value_size; ++rnk)
144  {
145  ret[static_cast<rank_type>(rank_to_char[rnk])] = rnk;
146  }
147 
148  return ret;
149  } ()
150  };
151 };
152 
153 constexpr dssp9 dssp9::H = dssp9{}.assign_char('H');
154 constexpr dssp9 dssp9::B = dssp9{}.assign_char('B');
155 constexpr dssp9 dssp9::E = dssp9{}.assign_char('E');
156 constexpr dssp9 dssp9::G = dssp9{}.assign_char('G');
157 constexpr dssp9 dssp9::I = dssp9{}.assign_char('I');
158 constexpr dssp9 dssp9::T = dssp9{}.assign_char('T');
159 constexpr dssp9 dssp9::S = dssp9{}.assign_char('S');
160 constexpr dssp9 dssp9::C = dssp9{}.assign_char('C');
161 constexpr dssp9 dssp9::X = dssp9{}.assign_char('X');
162 
163 } // namespace seqan3
164 
165 // ------------------------------------------------------------------
166 // literals
167 // ------------------------------------------------------------------
168 
169 namespace seqan3
170 {
171 
184 inline std::vector<dssp9> operator""_dssp9(const char * str, std::size_t len)
185 {
186  std::vector<dssp9> vec;
187  vec.resize(len);
188 
189  for (size_t idx = 0u; idx < len; ++idx)
190  vec[idx].assign_char(str[idx]);
191 
192  return vec;
193 }
194 
195 } // 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:89
char char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
The protein structure alphabet of the characters "HGIEBTSCX".
Definition: dssp9.hpp:85
alphabet_concept && assign_char(alphabet_concept &&alph, char_type const chr)
Returns the alphabet letter&#39;s value in character representation.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
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
Provides seqan3::alphabet_base.
Provides utilities for modifying characters.
Core alphabet concept and free function/metafunction wrappers.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:77