SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
 
Loading...
Searching...
No Matches
dot_bracket3.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// dot_bracket3
23// ------------------------------------------------------------------
24
25namespace seqan3
26{
27
53class dot_bracket3 : public alphabet_base<dot_bracket3, 3>
54{
55private:
58
60 friend base_t;
61
62public:
66 constexpr dot_bracket3() noexcept = default;
67 constexpr dot_bracket3(dot_bracket3 const &) noexcept = default;
68 constexpr dot_bracket3(dot_bracket3 &&) noexcept = default;
69 constexpr dot_bracket3 & operator=(dot_bracket3 const &) noexcept = default;
70 constexpr dot_bracket3 & operator=(dot_bracket3 &&) noexcept = default;
71 ~dot_bracket3() noexcept = default;
72
74
77
83 constexpr bool is_pair_open() const noexcept
84 {
85 return to_rank() == 1u;
86 }
87
93 constexpr bool is_pair_close() const noexcept
94 {
95 return to_rank() == 2u;
96 }
97
103 constexpr bool is_unpaired() const noexcept
104 {
105 return to_rank() == 0u;
106 }
107
114 static constexpr uint8_t max_pseudoknot_depth{1u};
115
122 constexpr std::optional<uint8_t> pseudoknot_id() const noexcept
123 {
124 if (is_unpaired())
125 return std::nullopt;
126 else
127 return 0;
128 }
130
131private:
133 static constexpr char_type rank_to_char_table[alphabet_size]{'.', '(', ')'};
134
136 static constexpr char_type rank_to_char(rank_type const rank)
137 {
138 return rank_to_char_table[rank];
139 }
140
142 static constexpr rank_type char_to_rank(char_type const chr)
143 {
144 using index_t = std::make_unsigned_t<char_type>;
145 return char_to_rank_table[static_cast<index_t>(chr)];
146 }
147
148 // clang-format off
150 static constexpr std::array<rank_type, 256> char_to_rank_table
151 {
152 []() constexpr {
153 std::array<rank_type, 256> rank_table{};
154
155 // Value-initialisation of std::array does usually initialise. `fill` is explicit.
156 rank_table.fill(0u);
157
158 // canonical
159 rank_table['.'] = 0u;
160 rank_table['('] = 1u;
161 rank_table[')'] = 2u;
162
163 return rank_table;
164 }()
165 };
166};
167// clang-format on
168
169inline namespace literals
170{
171
185constexpr dot_bracket3 operator""_db3(char const ch) noexcept
186{
187 return dot_bracket3{}.assign_char(ch);
188}
189
202{
204 vec.resize(len);
205
206 for (size_t idx = 0ul; idx < len; ++idx)
207 vec[idx].assign_char(str[idx]);
208
209 return vec;
210}
212
213} // namespace literals
214
215} // namespace seqan3
Provides seqan3::rna_structure_alphabet.
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
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:137
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 three letter RNA structure alphabet of the characters ".()"..
Definition: dot_bracket3.hpp:54
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition: dot_bracket3.hpp:93
constexpr std::optional< uint8_t > pseudoknot_id() const noexcept
Get an identifier for a pseudoknotted interaction, where opening and closing brackets of the same typ...
Definition: dot_bracket3.hpp:122
static constexpr uint8_t max_pseudoknot_depth
The ability of this alphabet to represent pseudoknots, i.e. crossing interactions,...
Definition: dot_bracket3.hpp:114
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition: dot_bracket3.hpp:103
constexpr dot_bracket3() noexcept=default
Defaulted.
constexpr bool is_pair_open() const noexcept
Check whether the character represents a rightward interaction in an RNA structure.
Definition: dot_bracket3.hpp:83
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.