SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
dot_bracket3.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
25 namespace seqan3
26 {
27 
51 class dot_bracket3 : public alphabet_base<dot_bracket3, 3>
52 {
53 private:
56 
58  friend base_t;
59 
60 public:
64  constexpr dot_bracket3() noexcept = default;
65  constexpr dot_bracket3(dot_bracket3 const &) noexcept = default;
66  constexpr dot_bracket3(dot_bracket3 &&) noexcept = default;
67  constexpr dot_bracket3 & operator=(dot_bracket3 const &) noexcept = default;
68  constexpr dot_bracket3 & operator=(dot_bracket3 &&) noexcept = default;
69  ~dot_bracket3() noexcept = default;
70 
74 
78  constexpr bool is_pair_open() const noexcept
79  {
80  return to_rank() == 1u;
81  }
82 
86  constexpr bool is_pair_close() const noexcept
87  {
88  return to_rank() == 2u;
89  }
90 
94  constexpr bool is_unpaired() const noexcept
95  {
96  return to_rank() == 0u;
97  }
98 
103  static constexpr uint8_t max_pseudoknot_depth{1u};
104 
109  constexpr std::optional<uint8_t> pseudoknot_id() const noexcept
110  {
111  if (is_unpaired())
112  return std::nullopt;
113  else
114  return 0;
115  }
117 
118 protected:
120 
122  static constexpr char_type rank_to_char[alphabet_size]
123  {
124  '.',
125  '(',
126  ')'
127  };
128 
130  static constexpr std::array<rank_type, 256> char_to_rank
131  {
132  [] () constexpr
133  {
134  std::array<rank_type, 256> rank_table{};
135 
136  // initialize with unpaired (std::array::fill unfortunately not constexpr)
137  for (rank_type & rnk : rank_table)
138  rnk = 0u;
139 
140  // canonical
141  rank_table['.'] = 0u;
142  rank_table['('] = 1u;
143  rank_table[')'] = 2u;
144 
145  return rank_table;
146  } ()
147  };
148 };
149 
162 inline std::vector<dot_bracket3> operator""_db3(const char * str, std::size_t len)
163 {
165  vec.resize(len);
166 
167  for (size_t idx = 0ul; idx < len; ++idx)
168  vec[idx].assign_char(str[idx]);
169 
170  return vec;
171 }
172 
181 constexpr dot_bracket3 operator""_db3(char const ch) noexcept
182 {
183  return dot_bracket3{}.assign_char(ch);
184 }
185 
187 
188 } // namespace seqan3
seqan3::dot_bracket3::dot_bracket3
constexpr dot_bracket3() noexcept=default
Defaulted.
seqan3::dot_bracket3::is_pair_open
constexpr bool is_pair_open() const noexcept
Check whether the character represents a rightward interaction in an RNA structure.
Definition: dot_bracket3.hpp:78
std::vector::resize
T resize(T... args)
concept.hpp
Provides seqan3::rna_structure_alphabet.
alphabet_base.hpp
Provides seqan3::alphabet_base.
seqan3::dot_bracket3::operator=
constexpr dot_bracket3 & operator=(dot_bracket3 const &) noexcept=default
Defaulted.
seqan3::alphabet_base< dot_bracket3, 3 >::alphabet_size
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:174
vector
seqan3::alphabet_base
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:51
seqan3::dot_bracket3::max_pseudoknot_depth
static constexpr uint8_t max_pseudoknot_depth
The ability of this alphabet to represent pseudoknots, i.e. crossing interactions,...
Definition: dot_bracket3.hpp:103
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:140
seqan3::dot_bracket3::pseudoknot_id
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:109
seqan3::alphabet_base< dot_bracket3, 3 >::rank_type
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:62
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::alphabet_base< dot_bracket3, 3 >::char_type
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:60
transform.hpp
Provides utilities for modifying characters.
seqan3::dot_bracket3::~dot_bracket3
~dot_bracket3() noexcept=default
seqan3::dot_bracket3
The three letter RNA structure alphabet of the characters ".()".
Definition: dot_bracket3.hpp:51
seqan3::dot_bracket3::is_pair_close
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition: dot_bracket3.hpp:86
std::optional
seqan3::dot_bracket3::is_unpaired
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition: dot_bracket3.hpp:94
std::size_t
seqan3::alphabet_base< dot_bracket3, 3 >::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:116