SeqAn3 3.3.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
25namespace seqan3
26{
27
62class dssp9 : public alphabet_base<dssp9, 9>
63{
64private:
67
69 friend base_t;
70
71public:
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
84private:
86 static constexpr char_type rank_to_char_table[alphabet_size]{'H', 'B', 'E', 'G', 'I', 'T', 'S', 'C', 'X'};
87
89 static constexpr char_type rank_to_char(rank_type const rank)
90 {
91 return rank_to_char_table[rank];
92 }
93
95 static constexpr rank_type char_to_rank(char_type const chr)
96 {
97 using index_t = std::make_unsigned_t<char_type>;
98 return char_to_rank_table[static_cast<index_t>(chr)];
99 }
100
101 // clang-format off
103 static constexpr std::array<rank_type, 256> char_to_rank_table
104 {
105 []() constexpr {
107
108 ret.fill(8u);
109
110 // reverse mapping for characters
111 for (rank_type rnk = 0u; rnk < alphabet_size; ++rnk)
112 ret[static_cast<rank_type>(rank_to_char_table[rnk])] = rnk;
113
114 return ret;
115 }()
116 };
117};
118// clang-format on
119
120inline namespace literals
121{
122
136constexpr dssp9 operator""_dssp9(char const ch) noexcept
137{
138 return dssp9{}.assign_char(ch);
139}
140
152SEQAN3_WORKAROUND_LITERAL std::vector<dssp9> operator""_dssp9(char const * str, std::size_t len)
153{
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
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.
T fill(T... args)
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition: platform.hpp:282
T resize(T... args)
Provides utilities for modifying characters.