SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
dssp9.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 // ------------------------------------------------------------------
22 // dssp9
23 // ------------------------------------------------------------------
24 
25 namespace seqan3
26 {
27 
62 class dssp9 : public alphabet_base<dssp9, 9>
63 {
64 private:
67 
69  friend base_t;
70 
71 public:
75  constexpr dssp9() noexcept = default;
76  constexpr dssp9(dssp9 const &) noexcept = default;
77  constexpr dssp9(dssp9 &&) noexcept = default;
78  constexpr dssp9 & operator=(dssp9 const &) noexcept = default;
79  constexpr dssp9 & operator=(dssp9 &&) noexcept = default;
80  ~dssp9() noexcept = default;
81 
83 
84 private:
86  static constexpr char_type rank_to_char_table[alphabet_size]
87  {
88  'H', 'B', 'E', 'G', 'I', 'T', 'S', 'C', 'X'
89  };
90 
92  static constexpr std::array<rank_type, 256> char_to_rank_table
93  {
94  [] () constexpr
95  {
97 
98  // initialize with X (std::array::fill unfortunately not constexpr)
99  for (rank_type & rnk : ret)
100  rnk = 8u;
101 
102  // reverse mapping for characters
103  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
104  {
105  ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
106  }
107 
108  return ret;
109  } ()
110  };
111 
113  static constexpr char_type rank_to_char(rank_type const rank)
114  {
115  return rank_to_char_table[rank];
116  }
117 
119  static constexpr rank_type char_to_rank(char_type const chr)
120  {
121  using index_t = std::make_unsigned_t<char_type>;
122  return char_to_rank_table[static_cast<index_t>(chr)];
123  }
124 };
125 
126 inline namespace literals
127 {
128 
142 constexpr dssp9 operator""_dssp9(char const ch) noexcept
143 {
144  return dssp9{}.assign_char(ch);
145 }
146 
158 inline std::vector<dssp9> operator""_dssp9(const char * str, std::size_t len)
159 {
160  std::vector<dssp9> vec;
161  vec.resize(len);
162 
163  for (size_t idx = 0u; idx < len; ++idx)
164  vec[idx].assign_char(str[idx]);
165 
166  return vec;
167 }
169 
170 } // inline namespace literals
171 
172 } // namespace seqan3
Core alphabet concept and free function/type trait wrappers.
Provides seqan3::alphabet_base.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:81
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:104
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:211
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:276
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:96
The protein structure alphabet of the characters "HGIEBTSCX".
Definition: dssp9.hpp:63
constexpr dssp9() noexcept=default
Defaulted.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
T resize(T... args)
Provides utilities for modifying characters.