BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
dna15.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
18#include <bio/alphabet/detail/to_lower.hpp>
20
21// ------------------------------------------------------------------
22// dna15
23// ------------------------------------------------------------------
24
25namespace bio::alphabet
26{
27
28class rna15;
29
49class dna15 : public nucleotide_base<dna15, 15>
50{
51private:
54
56 friend base_t;
58 friend base_t::base_t;
61 friend rna15;
62
63public:
67 constexpr dna15() noexcept = default;
68 constexpr dna15(dna15 const &) noexcept = default;
69 constexpr dna15(dna15 &&) noexcept = default;
70 constexpr dna15 & operator=(dna15 const &) noexcept = default;
71 constexpr dna15 & operator=(dna15 &&) noexcept = default;
72 ~dna15() noexcept = default;
73
74 using base_t::base_t;
75
77 template <std::same_as<rna15> t> // Accept incomplete type
78 constexpr dna15(t const & r) noexcept
79 {
80 assign_rank(r.to_rank());
81 }
83
84protected:
86
89 rank_to_char{'A', 'B', 'C', 'D', 'G', 'H', 'K', 'M', 'N', 'R', 'S', 'T', 'V', 'W', 'Y'};
90
92 static constexpr std::array<rank_type, 256> char_to_rank = []() constexpr
93 {
95
96 // initialize with UNKNOWN
97 ret.fill(8); // rank of 'N'
98
99 // reverse mapping for characters and their lowercase
100 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
101 {
102 ret[rank_to_char[rnk]] = rnk;
103 ret[detail::to_lower(rank_to_char[rnk])] = rnk;
104 }
105
106 // set U equal to T
107 ret['U'] = ret['T'];
108 ret['u'] = ret['t'];
109
110 return ret;
111 }();
112
114 static const std::array<dna15, alphabet_size> complement_table;
115};
116
117} // namespace bio::alphabet
118
119// ------------------------------------------------------------------
120// literals
121// ------------------------------------------------------------------
122
123namespace bio::alphabet
124{
125
126inline namespace literals
127{
128
137consteval dna15 operator""_dna15(char const c)
138{
139 if (!char_is_valid_for<dna15>(c))
140 throw std::invalid_argument{"Illegal character in character literal."};
141
142 return dna15{}.assign_char(c);
143}
144
154template <meta::detail::literal_buffer_string str>
155constexpr std::vector<dna15> operator""_dna15()
156{
157 return detail::string_literal<str, dna15>();
158}
160
161} // namespace literals
162
163} // namespace bio::alphabet
164
165// ------------------------------------------------------------------
166// dna15 (deferred definition)
167// ------------------------------------------------------------------
168
169namespace bio::alphabet
170{
171
172constexpr std::array<dna15, dna15::alphabet_size> dna15::complement_table{
173 'T'_dna15, // complement of 'A'_dna15
174 'V'_dna15, // complement of 'B'_dna15
175 'G'_dna15, // complement of 'C'_dna15
176 'H'_dna15, // complement of 'D'_dna15
177 'C'_dna15, // complement of 'G'_dna15
178 'D'_dna15, // complement of 'H'_dna15
179 'M'_dna15, // complement of 'K'_dna15
180 'K'_dna15, // complement of 'M'_dna15
181 'N'_dna15, // complement of 'N'_dna15
182 'Y'_dna15, // complement of 'R'_dna15
183 'S'_dna15, // complement of 'S'_dna15
184 'A'_dna15, // complement of 'T'_dna15
185 'B'_dna15, // complement of 'V'_dna15
186 'W'_dna15, // complement of 'W'_dna15
187 'R'_dna15 // complement of 'Y'_dna15
188};
189
190} // namespace bio::alphabet
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: base.hpp:168
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap..
Definition: dna15.hpp:50
constexpr dna15() noexcept=default
Defaulted.
A CRTP-base that refines bio::alphabet::base and is used by the nucleotides.
Definition: nucleotide_base.hpp:42
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap..
Definition: rna15.hpp:50
T fill(T... args)
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::nucleotide_base.