SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
dna5.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// dna5
19// ------------------------------------------------------------------
20
21namespace seqan3
22{
23
24class rna5;
25
47class dna5 : public nucleotide_base<dna5, 5>
48{
49private:
52
54 friend base_t;
57 friend base_t::base_t;
60 friend rna5;
61
62public:
66 constexpr dna5() noexcept = default;
67 constexpr dna5(dna5 const &) noexcept = default;
68 constexpr dna5(dna5 &&) noexcept = default;
69 constexpr dna5 & operator=(dna5 const &) noexcept = default;
70 constexpr dna5 & operator=(dna5 &&) noexcept = default;
71 ~dna5() noexcept = default;
72
73 using base_t::base_t;
74
82 template <std::same_as<rna5> t> // Accept incomplete type
83 constexpr dna5(t const & r) noexcept
84 {
85 assign_rank(r.to_rank());
86 }
88
89private:
91 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'C', 'G', 'N', 'T'};
92
94 static constexpr rank_type rank_complement_table[alphabet_size]{
95 4, // T is complement of 'A'_dna5
96 2, // G is complement of 'C'_dna5
97 1, // C is complement of 'G'_dna5
98 3, // N is complement of 'N'_dna5
99 0 // A is complement of 'T'_dna5
100 };
101
103 static constexpr rank_type rank_complement(rank_type const rank)
104 {
105 return rank_complement_table[rank];
106 }
107
109 static constexpr char_type rank_to_char(rank_type const rank)
110 {
111 return rank_to_char_table[rank];
112 }
113
115 static constexpr rank_type char_to_rank(char_type const chr)
116 {
117 using index_t = std::make_unsigned_t<char_type>;
118 return char_to_rank_table[static_cast<index_t>(chr)];
119 }
120
121 // clang-format off
123 static constexpr std::array<rank_type, 256> char_to_rank_table
124 {
125 []() constexpr {
127
128 ret.fill(3u); // initialize with UNKNOWN ('N')
129
130 // reverse mapping for characters and their lowercase
131 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
132 {
133 ret[rank_to_char_table[rnk]] = rnk;
134 ret[to_lower(rank_to_char_table[rnk])] = rnk;
135 }
136
137 // set U equal to T
138 ret['U'] = ret['T'];
139 ret['u'] = ret['t'];
140
141 // iupac characters are implicitly "UNKNOWN"
142 return ret;
143 }()
144 };
145};
146// clang-format on
147
148// ------------------------------------------------------------------
149// containers
150// ------------------------------------------------------------------
151
158
159// ------------------------------------------------------------------
160// literals
161// ------------------------------------------------------------------
162inline namespace literals
163{
164
179constexpr dna5 operator""_dna5(char const c) noexcept
180{
181 return dna5{}.assign_char(c);
182}
183
193SEQAN3_WORKAROUND_LITERAL dna5_vector operator""_dna5(char const * s, std::size_t n)
194{
195 dna5_vector r;
196 r.resize(n);
197
198 for (size_t i = 0; i < n; ++i)
199 r[i].assign_char(s[i]);
200
201 return r;
202}
204
205} // namespace literals
206
207} // 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
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition alphabet_base.hpp:77
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
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
constexpr dna5() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:40
The five letter RNA alphabet of A,C,G,U and the unknown character N.
Definition rna5.hpp:46
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