BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
rna4.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <vector>
17
20
21// ------------------------------------------------------------------
22// rna4
23// ------------------------------------------------------------------
24
25namespace bio::alphabet
26{
27
47class rna4 : public nucleotide_base<rna4, 4>
48{
49private:
52
54 friend base_t;
56 friend base_t::base_t;
58
59public:
63 constexpr rna4() noexcept = default;
64 constexpr rna4(rna4 const &) noexcept = default;
65 constexpr rna4(rna4 &&) noexcept = default;
66 constexpr rna4 & operator=(rna4 const &) noexcept = default;
67 constexpr rna4 & operator=(rna4 &&) noexcept = default;
68 ~rna4() noexcept = default;
69
70 using base_t::base_t;
71
73 constexpr rna4(dna4 const & r) noexcept { assign_rank(r.to_rank()); }
75
79 constexpr rna4 complement() const noexcept { return rna4{}.assign_rank(to_rank() ^ 0b11); }
80
81protected:
83
85 static constexpr std::array<char_type, alphabet_size> rank_to_char{'A', 'C', 'G', 'U'};
86
88 static constexpr std::array<rank_type, 256> char_to_rank = dna4::char_to_rank;
89};
90
91} // namespace bio::alphabet
92
93// ------------------------------------------------------------------
94// literals
95// ------------------------------------------------------------------
96
97namespace bio::alphabet
98{
99
100inline namespace literals
101{
102
111consteval rna4 operator""_rna4(char const c)
112{
113 if (!char_is_valid_for<rna4>(c))
114 throw std::invalid_argument{"Illegal character in character literal."};
115
116 return rna4{}.assign_char(c);
117}
118
128template <meta::detail::literal_buffer_string str>
129constexpr std::vector<rna4> operator""_rna4()
130{
131 return detail::string_literal<str, rna4>();
132}
134
135} // namespace literals
136
137} // namespace bio::alphabet
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: base.hpp:168
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
The four letter DNA alphabet of A,C,G,T..
Definition: dna4.hpp:49
A CRTP-base that refines bio::alphabet::base and is used by the nucleotides.
Definition: nucleotide_base.hpp:42
The four letter RNA alphabet of A,C,G,U..
Definition: rna4.hpp:48
constexpr rna4() noexcept=default
Defaulted.
Provides bio::alphabet::dna4, container aliases and string literals.
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::nucleotide_base.