SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
dna15.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <vector>
13
16
17// ------------------------------------------------------------------
18// dna15
19// ------------------------------------------------------------------
20
21namespace seqan3
22{
23
24class rna15;
25
47class dna15 : public nucleotide_base<dna15, 15>
48{
49private:
52
54 friend base_t;
57 friend base_t::base_t;
60 friend rna15;
61
62public:
66 constexpr dna15() noexcept = default;
67 constexpr dna15(dna15 const &) noexcept = default;
68 constexpr dna15(dna15 &&) noexcept = default;
69 constexpr dna15 & operator=(dna15 const &) noexcept = default;
70 constexpr dna15 & operator=(dna15 &&) noexcept = default;
71 ~dna15() noexcept = default;
72
73 using base_t::base_t;
74
82 template <std::same_as<rna15> t> // Accept incomplete type
83 constexpr dna15(t const & r) noexcept
84 {
85 assign_rank(r.to_rank());
86 }
88
89private:
91 static constexpr char_type
92 rank_to_char_table[alphabet_size]{'A', 'B', 'C', 'D', 'G', 'H', 'K', 'M', 'N', 'R', 'S', 'T', 'V', 'W', 'Y'};
93
96 11, // T is complement of 'A'_dna15
97 12, // V is complement of 'B'_dna15
98 4, // G is complement of 'C'_dna15
99 5, // H is complement of 'D'_dna15
100 2, // C is complement of 'G'_dna15
101 3, // D is complement of 'H'_dna15
102 7, // M is complement of 'K'_dna15
103 6, // K is complement of 'M'_dna15
104 8, // N is complement of 'N'_dna15
105 14, // Y is complement of 'R'_dna15
106 10, // S is complement of 'S'_dna15
107 0, // A is complement of 'T'_dna15
108 1, // B is complement of 'V'_dna15
109 13, // W is complement of 'W'_dna15
110 9 // R is complement of 'Y'_dna15
111 };
112
114 static constexpr rank_type rank_complement(rank_type const rank)
115 {
117 }
118
120 static constexpr char_type rank_to_char(rank_type const rank)
121 {
122 return rank_to_char_table[rank];
123 }
124
126 static constexpr rank_type char_to_rank(char_type const chr)
127 {
128 using index_t = std::make_unsigned_t<char_type>;
129 return char_to_rank_table[static_cast<index_t>(chr)];
130 }
131
132 // clang-format off
135 {
136 []() constexpr {
138
139 ret.fill(8u); // initialize with UNKNOWN ('N')
140
141 // reverse mapping for characters and their lowercase
142 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
143 {
144 ret[rank_to_char_table[rnk]] = rnk;
145 ret[to_lower(rank_to_char_table[rnk])] = rnk;
146 }
147
148 // set U equal to T
149 ret['U'] = ret['T'];
150 ret['u'] = ret['t'];
151
152 return ret;
153 }()
154 };
155};
156// clang-format on
157
158// ------------------------------------------------------------------
159// containers
160// ------------------------------------------------------------------
161
168
169// ------------------------------------------------------------------
170// literals
171// ------------------------------------------------------------------
172inline namespace literals
173{
174
189constexpr dna15 operator""_dna15(char const c) noexcept
190{
191 return dna15{}.assign_char(c);
192}
193
203SEQAN3_WORKAROUND_LITERAL dna15_vector operator""_dna15(char const * s, std::size_t n)
204{
205 dna15_vector r;
206 r.resize(n);
207
208 for (size_t i = 0; i < n; ++i)
209 r[i].assign_char(s[i]);
210
211 return r;
212}
214
215} // namespace literals
216
217} // namespace seqan3
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
static constexpr detail::min_viable_uint_t< size > alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition alphabet_base.hpp:196
std::conditional_t< std::same_as< char_t, void >, char, char_t > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition alphabet_base.hpp:69
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
rank_type rank
The value of the alphabet letter is stored as the rank.
Definition alphabet_base.hpp:258
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition dna15.hpp:48
friend base_t
Befriend seqan3::nucleotide_base.
Definition dna15.hpp:54
static constexpr rank_type rank_complement(rank_type const rank)
Returns the complement by rank.
Definition dna15.hpp:114
friend rna15
Befriend seqan3::rna15 so it can copy char_to_rank.
Definition dna15.hpp:60
constexpr dna15() noexcept=default
Defaulted.
static constexpr rank_type rank_complement_table[alphabet_size]
The rank complement table.
Definition dna15.hpp:95
static constexpr rank_type char_to_rank(char_type const chr)
Returns the rank representation of character.
Definition dna15.hpp:126
static constexpr char_type rank_to_char_table[alphabet_size]
The lookup table used in rank_to_char.
Definition dna15.hpp:92
static constexpr char_type rank_to_char(rank_type const rank)
Returns the character representation of rank.
Definition dna15.hpp:120
static constexpr std::array< rank_type, 256 > char_to_rank_table
Returns the rank representation of character.
Definition dna15.hpp:135
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:40
alphabet_base< dna15, size, char > base_t
Type of the base class.
Definition nucleotide_base.hpp:43
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition rna15.hpp:48
T fill(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
constexpr char_type to_lower(char_type const c) noexcept
Converts 'A'-'Z' to 'a'-'z' respectively; other characters are returned as is.
Definition transform.hpp:80
SeqAn specific customisations in the standard namespace.
Provides seqan3::nucleotide_base.
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition platform.hpp:269
T resize(T... args)
Provides utilities for modifying characters.
Hide me