BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
rna5.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// rna5
23// ------------------------------------------------------------------
24
25namespace bio::alphabet
26{
27
47class rna5 : public nucleotide_base<rna5, 5>
48{
49private:
52
54 friend base_t;
56 friend base_t::base_t;
58
59public:
63 constexpr rna5() noexcept = default;
64 constexpr rna5(rna5 const &) noexcept = default;
65 constexpr rna5(rna5 &&) noexcept = default;
66 constexpr rna5 & operator=(rna5 const &) noexcept = default;
67 constexpr rna5 & operator=(rna5 &&) noexcept = default;
68 ~rna5() noexcept = default;
69
70 using base_t::base_t;
71
73 constexpr rna5(dna5 const & r) noexcept { assign_rank(r.to_rank()); }
75
76protected:
78
80 static constexpr std::array<char_type, alphabet_size> rank_to_char{'A', 'C', 'G', 'N', 'U'};
81
83 static constexpr std::array<rank_type, 256> char_to_rank = dna5::char_to_rank;
84
86 static const std::array<rna5, alphabet_size> complement_table;
87};
88
89} // namespace bio::alphabet
90
91// ------------------------------------------------------------------
92// literals
93// ------------------------------------------------------------------
94
95namespace bio::alphabet
96{
97
98inline namespace literals
99{
100
109consteval rna5 operator""_rna5(char const c)
110{
111 if (!char_is_valid_for<rna5>(c))
112 throw std::invalid_argument{"Illegal character in character literal."};
113
114 return rna5{}.assign_char(c);
115}
116
126template <meta::detail::literal_buffer_string str>
127constexpr std::vector<rna5> operator""_rna5()
128{
129 return detail::string_literal<str, rna5>();
130}
132
133} // namespace literals
134
135} // namespace bio::alphabet
136
137// ------------------------------------------------------------------
138// rna5 (deferred definition)
139// ------------------------------------------------------------------
140
141namespace bio::alphabet
142{
143
144constexpr std::array<rna5, rna5::alphabet_size> rna5::complement_table{
145 'U'_rna5, // complement of 'A'_rna5
146 'G'_rna5, // complement of 'C'_rna5
147 'C'_rna5, // complement of 'G'_rna5
148 'N'_rna5, // complement of 'N'_rna5
149 'A'_rna5 // complement of 'U'_rna5
150};
151
152} // 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 five letter DNA alphabet of A,C,G,T and the unknown character N..
Definition: dna5.hpp:50
A CRTP-base that refines bio::alphabet::base and is used by the nucleotides.
Definition: nucleotide_base.hpp:42
The five letter RNA alphabet of A,C,G,U and the unknown character N..
Definition: rna5.hpp:48
constexpr rna5() noexcept=default
Defaulted.
Provides bio::alphabet::dna5, container aliases and string literals.
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::nucleotide_base.