SeqAn3
member_exposure.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (chr) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (chr) 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 
42 #pragma once
43 
44 #include <iostream>
45 #include <optional>
46 
48 
49 namespace seqan3
50 {
51 
52 // ------------------------------------------------------------------
53 // seqan3::semi_alphabet_concept
54 // ------------------------------------------------------------------
55 
66 template <typename alphabet_type_with_members>
68  requires requires (alphabet_type_with_members alph) { typename alphabet_type_with_members::rank_type; }
70 struct underlying_rank<alphabet_type_with_members>
71 {
73  using type = typename alphabet_type_with_members::rank_type;
74 };
75 
81 template <typename alphabet_type_with_members>
83  requires requires (alphabet_type_with_members alph) { alphabet_type_with_members::value_size; }
85 struct alphabet_size<alphabet_type_with_members>
86 {
88  static auto constexpr value = alphabet_type_with_members::value_size;
89 };
90 
96 template <typename alphabet_type>
97 constexpr underlying_rank_t<alphabet_type> to_rank(alphabet_type const alph)
98  requires requires (alphabet_type alph) { { alph.to_rank() } -> underlying_rank_t<alphabet_type>; }
99 {
100  return alph.to_rank();
101 }
102 
109 template <typename alphabet_type>
110 constexpr alphabet_type & assign_rank(alphabet_type & alph, underlying_rank_t<alphabet_type> const rank)
111  requires requires (alphabet_type alph) { { alph.assign_rank(uint8_t{0}) } -> alphabet_type &; }
112 {
113  return alph.assign_rank(rank);
114 }
115 
127 template <typename alphabet_type>
128 constexpr alphabet_type && assign_rank(alphabet_type && alph, underlying_rank_t<alphabet_type> const rank)
129  requires requires (alphabet_type alph) { { alph.assign_rank(uint8_t{0}) } -> alphabet_type &; }
130 {
131  return std::move(alph.assign_rank(rank));
132 }
134 
135 // ------------------------------------------------------------------
136 // seqan3::alphabet_concept
137 // ------------------------------------------------------------------
138 
149 template <typename alphabet_type_with_members>
151  requires requires (alphabet_type_with_members alph) { typename alphabet_type_with_members::char_type; }
153 struct underlying_char<alphabet_type_with_members>
154 {
156  using type = typename alphabet_type_with_members::char_type;
157 };
158 
164 template <typename alphabet_type>
165 constexpr underlying_char_t<alphabet_type> to_char(alphabet_type const alph)
166  requires requires (alphabet_type alph) { { alph.to_char() } -> underlying_char_t<alphabet_type>; }
167 {
168  return alph.to_char();
169 }
170 
177 template <typename alphabet_type>
178 constexpr alphabet_type & assign_char(alphabet_type & alph, underlying_char_t<alphabet_type> const chr)
179  requires requires (alphabet_type alph) { { alph.assign_char(char{0}) } -> alphabet_type &; }
180 {
181  return alph.assign_char(chr);
182 }
183 
195 template <typename alphabet_type>
196 constexpr alphabet_type && assign_char(alphabet_type && alph, underlying_char_t<alphabet_type> const chr)
197  requires requires (alphabet_type alph) { { alph.assign_char(char{0}) } -> alphabet_type &; }
198 {
199  return std::move(alph.assign_char(chr));
200 }
202 
203 // ------------------------------------------------------------------
204 // seqan3::nucleotide_concept
205 // ------------------------------------------------------------------
206 
219 template <typename nucleotide_type>
220 constexpr nucleotide_type complement(nucleotide_type const alph)
221  requires requires (nucleotide_type alph) { { alph.complement() } -> nucleotide_type; }
222 {
223  return alph.complement();
224 }
226 
227 // ------------------------------------------------------------------
228 // seqan3::rna_structure_concept
229 // ------------------------------------------------------------------
230 
237 
245 template <typename structure_type>
246 constexpr bool is_pair_open(structure_type const alph)
247  requires requires (structure_type alph) { { alph.is_pair_open() } -> bool; }
248 {
249  return alph.is_pair_open();
250 }
251 
258 template <typename structure_type>
259 constexpr bool is_pair_close(structure_type const alph)
260  requires requires (structure_type alph) { { alph.is_pair_close() } -> bool; }
261 {
262  return alph.is_pair_close();
263 }
264 
271 template <typename structure_type>
272 constexpr bool is_unpaired(structure_type const alph)
273  requires requires (structure_type alph) { { alph.is_unpaired() } -> bool; }
274 {
275  return alph.is_unpaired();
276 }
277 
282 template <typename alphabet_type_with_pseudoknot_attribute>
284  requires requires (alphabet_type_with_pseudoknot_attribute)
285  { { alphabet_type_with_pseudoknot_attribute::max_pseudoknot_depth } -> uint8_t; }
287 struct max_pseudoknot_depth<alphabet_type_with_pseudoknot_attribute>
288 {
290  static constexpr uint8_t value = alphabet_type_with_pseudoknot_attribute::max_pseudoknot_depth;
291 };
292 
301 template<typename alphabet_type_with_pseudoknot_attribute>
302 constexpr std::optional<uint8_t> pseudoknot_id(alphabet_type_with_pseudoknot_attribute const alph)
304  requires requires(alphabet_type_with_pseudoknot_attribute)
305  { { alphabet_type_with_pseudoknot_attribute::max_pseudoknot_depth } -> uint8_t; }
307 {
308  if constexpr (alphabet_type_with_pseudoknot_attribute::max_pseudoknot_depth > 1)
309  return alph.pseudoknot_id();
310  else if (is_pair_open(alph) || is_pair_close(alph))
311  return 0;
312  else
313  return std::nullopt;
314 }
316 
317 } // namespace seqan3
The rank_type of the semi_alphabet. [type metafunction base template].
Definition: concept_pre.hpp:80
constexpr nucleotide_type complement(nucleotide_type const alph) requires requires(nucleotide_type alph)
Implementation of seqan3::nucleotide_concept::complement() that delegates to a member function...
Definition: member_exposure.hpp:220
typename alphabet_type_with_members::char_type type
The forwarded char_type.
Definition: member_exposure.hpp:156
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
seqan3::alphabet_concept metafunction base classes.
constexpr alphabet_type & assign_rank(alphabet_type &alph, underlying_rank_t< alphabet_type > const rank) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::assign_rank() that delegates to a member function...
Definition: member_exposure.hpp:110
constexpr bool is_unpaired(structure_type const alph) requires requires(structure_type alph)
Implementation of seqan3::rna_structure_concept::is_unpaired() that delegates to a member function...
Definition: member_exposure.hpp:272
typename alphabet_type_with_members::rank_type type
The forwarded rank_type.
Definition: member_exposure.hpp:73
The size of the alphabet. [value metafunction base template].
Definition: concept_pre.hpp:104
Metafunction that indicates to what extent an alphabet can handle pseudoknots. [value metafunction ba...
Definition: concept_pre.hpp:228
constexpr bool is_pair_close(structure_type const alph) requires requires(structure_type alph)
Implementation of seqan3::rna_structure_concept::is_pair_close() that delegates to a member function...
Definition: member_exposure.hpp:259
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
The char_type of the alphabet. [type metafunction base template].
Definition: concept_pre.hpp:164
constexpr underlying_rank_t< alphabet_type > to_rank(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::to_rank() that delegates to a member function...
Definition: member_exposure.hpp:97
constexpr std::optional< uint8_t > pseudoknot_id(alphabet_type_with_pseudoknot_attribute const alph)
Implementation of seqan3::rna_structure_concept::pseudoknot_id() that delegates to a member function...
Definition: member_exposure.hpp:302
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
constexpr bool is_pair_open(structure_type const alph) requires requires(structure_type alph)
Implementation of seqan3::rna_structure_concept::is_pair_open() that delegates to a member function...
Definition: member_exposure.hpp:246