SeqAn3
dot_bracket3.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <vector>
43 
47 
48 // ------------------------------------------------------------------
49 // dot_bracket3
50 // ------------------------------------------------------------------
51 
52 namespace seqan3
53 {
54 
76 class dot_bracket3 : public alphabet_base<dot_bracket3, 3>
77 {
78 private:
81 
83  friend base_t;
84 
85 public:
89  constexpr dot_bracket3() : base_t{} {}
90  constexpr dot_bracket3(dot_bracket3 const &) = default;
91  constexpr dot_bracket3(dot_bracket3 &&) = default;
92  constexpr dot_bracket3 & operator=(dot_bracket3 const &) = default;
93  constexpr dot_bracket3 & operator=(dot_bracket3 &&) = default;
94  ~dot_bracket3() = default;
96 
101  static const dot_bracket3 UNPAIRED;
103  static const dot_bracket3 PAIR_OPEN;
104  static const dot_bracket3 PAIR_CLOSE;
105  static const dot_bracket3 UNKNOWN;
107 
110 
114  constexpr bool is_pair_open() const noexcept
115  {
116  return *this == PAIR_OPEN;
117  }
118 
122  constexpr bool is_pair_close() const noexcept
123  {
124  return *this == PAIR_CLOSE;
125  }
126 
130  constexpr bool is_unpaired() const noexcept
131  {
132  return *this == UNPAIRED;
133  }
134 
139  static constexpr uint8_t max_pseudoknot_depth{1};
141 
142 protected:
144 
146  static constexpr char_type rank_to_char[value_size]
147  {
148  '.',
149  '(',
150  ')'
151  };
152 
154  static constexpr std::array<rank_type, 256> char_to_rank
155  {
156  [] () constexpr
157  {
158  std::array<rank_type, 256> rank_table{};
159 
160  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
161  for (rank_type & rnk : rank_table)
162  rnk = 0;
163 
164  // canonical
165  rank_table['.'] = 0;
166  rank_table['('] = 1;
167  rank_table[')'] = 2;
168 
169  return rank_table;
170  } ()
171  };
172 };
173 
174 constexpr dot_bracket3 dot_bracket3::UNPAIRED = dot_bracket3{}.assign_char('.');
175 constexpr dot_bracket3 dot_bracket3::PAIR_OPEN = dot_bracket3{}.assign_char('(');
176 constexpr dot_bracket3 dot_bracket3::PAIR_CLOSE = dot_bracket3{}.assign_char(')');
177 constexpr dot_bracket3 dot_bracket3::UNKNOWN = dot_bracket3::UNPAIRED;
178 
179 } // namespace seqan3
180 
181 // ------------------------------------------------------------------
182 // literals
183 // ------------------------------------------------------------------
184 
185 namespace seqan3
186 {
187 
200 inline std::vector<dot_bracket3> operator""_db3(const char * str, std::size_t len)
201 {
202  std::vector<dot_bracket3> vec;
203  vec.resize(len);
204 
205  for (size_t idx = 0u; idx < len; ++idx)
206  vec[idx].assign_char(str[idx]);
207 
208  return vec;
209 }
210 
211 } // namespace seqan3
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:89
char char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
constexpr bool is_pair_open() const noexcept
Check whether the character represents a rightward interaction in an RNA structure.
Definition: dot_bracket3.hpp:114
Provides seqan3::rna_structure_concept.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
The three letter RNA structure alphabet of the characters ".()".
Definition: dot_bracket3.hpp:76
static detail::min_viable_uint_t< size > constexpr value_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:198
Provides seqan3::alphabet_base.
Metafunction that indicates to what extent an alphabet can handle pseudoknots. [value metafunction ba...
Definition: concept_pre.hpp:228
constexpr derived_type & assign_char(std::conditional_t< std::Same< char_type, void >, char, char_type > const c) noexcept
Assign from a character.
Definition: alphabet_base.hpp:165
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition: dot_bracket3.hpp:122
Provides utilities for modifying characters.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:77
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition: dot_bracket3.hpp:130