SeqAn3
structured_rna.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 <iostream>
43 #include <optional>
44 #include <string>
45 #include <utility>
46 
50 
51 namespace seqan3
52 {
53 
76 template <typename sequence_alphabet_t, typename structure_alphabet_t>
78  requires nucleotide_concept<sequence_alphabet_t> && rna_structure_concept<structure_alphabet_t>
81  public cartesian_composition<structured_rna<sequence_alphabet_t, structure_alphabet_t>,
82  sequence_alphabet_t, structure_alphabet_t>
83 {
84 private:
87  sequence_alphabet_t, structure_alphabet_t>;
88 public:
90  using sequence_alphabet_type = sequence_alphabet_t;
92  using structure_alphabet_type = structure_alphabet_t;
93 
96 
100  constexpr structured_rna() : base_type{} {}
101  constexpr structured_rna(structured_rna const &) = default;
102  constexpr structured_rna(structured_rna &&) = default;
103  constexpr structured_rna & operator =(structured_rna const &) = default;
104  constexpr structured_rna & operator =(structured_rna &&) = default;
105  ~structured_rna() = default;
106 
107  using base_type::base_type; // Inherit non-default constructors
108 
110  SEQAN3_DOXYGEN_ONLY(( constexpr structured_rna(component_type const alph) {} ))
112  SEQAN3_DOXYGEN_ONLY(( constexpr structured_rna(indirect_component_type const alph) {} ))
114  SEQAN3_DOXYGEN_ONLY(( constexpr structured_rna & operator=(component_type const alph) {} ))
116  SEQAN3_DOXYGEN_ONLY(( constexpr structured_rna & operator=(indirect_component_type const alph) {} ))
118 
119  // Inherit operators from base
120  using base_type::operator=;
121  using base_type::operator==;
122  using base_type::operator!=;
123  using base_type::operator>=;
124  using base_type::operator<=;
125  using base_type::operator<;
126  using base_type::operator>;
127 
131  constexpr structured_rna & assign_char(char_type const c)
132  {
133  seqan3::assign_char(get<0>(*this), c);
134  return *this;
135  }
137 
140 
142  constexpr char_type to_char() const noexcept
143  {
144  return seqan3::to_char(get<0>(*this));
145  }
146 
157  constexpr structured_rna complement() const noexcept
158  {
159  return structured_rna{get<0>(*this).complement(), get<1>(*this)};
160  }
162 
165 
169  constexpr bool is_pair_open() const noexcept
170  {
171  return get<1>(*this).is_pair_open();
172  };
173 
177  constexpr bool is_pair_close() const noexcept
178  {
179  return get<1>(*this).is_pair_close();
180  };
181 
185  constexpr bool is_unpaired() const noexcept
186  {
187  return get<1>(*this).is_unpaired();
188  };
189 
191  static constexpr uint8_t max_pseudoknot_depth{structure_alphabet_t::max_pseudoknot_depth};
192 
197  constexpr std::optional<uint8_t> pseudoknot_id() const noexcept
198  {
199  if constexpr (structure_alphabet_type::max_pseudoknot_depth > 1)
200  {
201  return get<1>(*this).pseudoknot_id();
202  }
203  else
204  {
205  return (is_pair_open() || is_pair_close()) ? std::optional<uint8_t>(0) : std::nullopt;
206  }
207  };
209 };
210 
213 template <typename sequence_alphabet_type, typename structure_alphabet_type>
215  -> structured_rna<std::decay_t<sequence_alphabet_type>, std::decay_t<structure_alphabet_type>>;
216 
217 } // namespace seqan3
char_t char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: cartesian_composition.hpp:209
Provides seqan3::rna_structure_concept.
constexpr bool is_pair_close() const noexcept
Check whether the character represents a leftward interaction in an RNA structure.
Definition: structured_rna.hpp:177
constexpr structured_rna(component_type const alph)
Construction via a value of one of the components.
Definition: structured_rna.hpp:110
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition: structured_rna.hpp:90
constexpr bool is_unpaired() const noexcept
Check whether the character represents an unpaired position in an RNA structure.
Definition: structured_rna.hpp:185
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition: structured_rna.hpp:142
constexpr structured_rna complement() const noexcept
Return a structured_rna where the sequence letter is converted to its complement. ...
Definition: structured_rna.hpp:157
Provides seqan3::nucleotide_concept.
Provides seqan3::cartesian_composition.
constexpr bool is_pair_open() const noexcept
Check whether the character represents a rightward interaction in an RNA structure.
Definition: structured_rna.hpp:169
Metafunction that indicates to what extent an alphabet can handle pseudoknots. [value metafunction ba...
Definition: concept_pre.hpp:228
A seqan3::cartesian_composition that joins a nucleotide alphabet with an RNA structure alphabet...
Definition: structured_rna.hpp:80
constexpr std::optional< uint8_t > pseudoknot_id() const noexcept
Get an identifier for a pseudoknotted interaction.
Definition: structured_rna.hpp:197
constexpr alphabet_type & assign_char(alphabet_type &alph, underlying_char_t< alphabet_type > const chr) requires requires(alphabet_type alph)
Implementation of seqan3::alphabet_concept::assign_char() that delegates to a member function...
Definition: member_exposure.hpp:178
typename underlying_char< alphabet_type >::type underlying_char_t
The char_type of the alphabet. [type metafunction shortcut].
Definition: concept_pre.hpp:172
constexpr underlying_char_t< alphabet_type > to_char(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::alphabet_concept::to_char() that delegates to a member function.
Definition: member_exposure.hpp:165
structure_alphabet_t structure_alphabet_type
Second template parameter as member type.
Definition: structured_rna.hpp:92