SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
dssp9.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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]{'H', 'B', 'E', 'G', 'I', 'T', 'S', 'C', 'X'};
87 
89  static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr {std::array<rank_type, 256> ret{};
90 
91  // initialize with X (std::array::fill unfortunately not constexpr)
92  for (rank_type & rnk : ret)
93  rnk = 8u;
94 
95  // reverse mapping for characters
96  for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
97  {
98  ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
99  }
100 
101  return ret;
102 }()
103 }; // namespace seqan3
104 
106 static constexpr char_type rank_to_char(rank_type const rank)
107 {
108  return rank_to_char_table[rank];
109 }
110 
112 static constexpr rank_type char_to_rank(char_type const chr)
113 {
114  using index_t = std::make_unsigned_t<char_type>;
115  return char_to_rank_table[static_cast<index_t>(chr)];
116 }
117 }
118 ;
119 
120 inline namespace literals
121 {
122 
136 constexpr dssp9 operator""_dssp9(char const ch) noexcept
137 {
138  return dssp9{}.assign_char(ch);
139 }
140 
152 inline std::vector<dssp9> operator""_dssp9(char const * str, std::size_t len)
153 {
154  std::vector<dssp9> vec;
155  vec.resize(len);
156 
157  for (size_t idx = 0u; idx < len; ++idx)
158  vec[idx].assign_char(str[idx]);
159 
160  return vec;
161 }
163 
164 } // namespace literals
165 
166 } // 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:57
constexpr derived_type & assign_char(char_type const chr) noexcept requires(!std
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:163
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:80
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:199
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:72
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.