SeqAn3 3.4.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// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <vector>
13
17
18// ------------------------------------------------------------------
19// dot_bracket3
20// ------------------------------------------------------------------
21
22namespace seqan3
23{
24
50class dot_bracket3 : public alphabet_base<dot_bracket3, 3>
51{
52private:
55
57 friend base_t;
58
59public:
63 constexpr dot_bracket3() noexcept = default;
64 constexpr dot_bracket3(dot_bracket3 const &) noexcept = default;
65 constexpr dot_bracket3(dot_bracket3 &&) noexcept = default;
66 constexpr dot_bracket3 & operator=(dot_bracket3 const &) noexcept = default;
67 constexpr dot_bracket3 & operator=(dot_bracket3 &&) noexcept = default;
68 ~dot_bracket3() noexcept = default;
69
71
74
80 constexpr bool is_pair_open() const noexcept
81 {
82 return to_rank() == 1u;
83 }
84
90 constexpr bool is_pair_close() const noexcept
91 {
92 return to_rank() == 2u;
93 }
94
100 constexpr bool is_unpaired() const noexcept
101 {
102 return to_rank() == 0u;
103 }
104
111 static constexpr uint8_t max_pseudoknot_depth{1u};
112
119 constexpr std::optional<uint8_t> pseudoknot_id() const noexcept
120 {
121 if (is_unpaired())
122 return std::nullopt;
123 else
124 return 0;
125 }
127
128private:
130 static constexpr char_type rank_to_char_table[alphabet_size]{'.', '(', ')'};
131
133 static constexpr char_type rank_to_char(rank_type const rank)
134 {
135 return rank_to_char_table[rank];
136 }
137
139 static constexpr rank_type char_to_rank(char_type const chr)
140 {
141 using index_t = std::make_unsigned_t<char_type>;
142 return char_to_rank_table[static_cast<index_t>(chr)];
143 }
144
146 static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr
147 {
148 std::array<rank_type, 256> rank_table{};
149
150 // Value-initialisation of std::array does usually initialise. `fill` is explicit.
151 rank_table.fill(0u);
152
153 // canonical
154 rank_table['.'] = 0u;
155 rank_table['('] = 1u;
156 rank_table[')'] = 2u;
157
158 return rank_table;
159 }()};
160};
161
162inline namespace literals
163{
164
178constexpr dot_bracket3 operator""_db3(char const ch) noexcept
179{
180 return dot_bracket3{}.assign_char(ch);
181}
182
194SEQAN3_WORKAROUND_LITERAL std::vector<dot_bracket3> operator""_db3(char const * str, std::size_t len)
195{
197 vec.resize(len);
198
199 for (size_t idx = 0ul; idx < len; ++idx)
200 vec[idx].assign_char(str[idx]);
201
202 return vec;
203}
205
206} // namespace literals
207
208} // 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:54
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
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:77
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:196
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:69
The three letter RNA structure alphabet of the characters ".()".
Definition dot_bracket3.hpp:51
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition dot_bracket3.hpp:90
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:119
static constexpr uint8_t max_pseudoknot_depth
The ability of this alphabet to represent pseudoknots, i.e. crossing interactions,...
Definition dot_bracket3.hpp:111
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition dot_bracket3.hpp:100
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:80
T fill(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition platform.hpp:269
T resize(T... args)
Provides utilities for modifying characters.
Hide me