SeqAn3 3.4.0-rc.3
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
dna3bs.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// dna3bs
19// ------------------------------------------------------------------
20
21namespace seqan3
22{
57class dna3bs : public nucleotide_base<dna3bs, 3>
58{
59private:
62
64 friend base_t;
67 friend base_t::base_t;
69
70public:
74 constexpr dna3bs() noexcept = default;
80
83
86 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'G', 'T'};
87
89 static constexpr rank_type rank_complement_table[alphabet_size]{
90 2, // T is complement of 'A'_dna3bs
91 2, // T is complement of 'G'_dna3bs
92 0 // A is complement of 'T'_dna3bs
93 };
94
96 static constexpr rank_type rank_complement(rank_type const rank)
97 {
98 return rank_complement_table[rank];
99 }
100
102 static constexpr char_type rank_to_char(rank_type const rank)
103 {
104 return rank_to_char_table[rank];
105 }
106
108 static constexpr rank_type char_to_rank(char_type const chr)
109 {
110 using index_t = std::make_unsigned_t<char_type>;
111 return char_to_rank_table[static_cast<index_t>(chr)];
112 }
113
115 static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr
116 {
118
119 // reverse mapping for characters and their lowercase
120 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
121 {
122 ret[rank_to_char_table[rnk]] = rnk;
123 ret[to_lower(rank_to_char_table[rnk])] = rnk;
124 }
125
126 // set C and U equal to T
127 ret['C'] = ret['T'];
128 ret['c'] = ret['t'];
129 ret['U'] = ret['T'];
130 ret['u'] = ret['t'];
131
132 // iupac characters get special treatment, because there is no N
133 ret['R'] = ret['A'];
134 ret['r'] = ret['A']; // A or G becomes A
135 ret['Y'] = ret['T'];
136 ret['y'] = ret['T']; // C or T becomes T
137 ret['S'] = ret['T'];
138 ret['s'] = ret['T']; // C or G becomes T
139 ret['W'] = ret['A'];
140 ret['w'] = ret['A']; // A or T becomes A
141 ret['K'] = ret['G'];
142 ret['k'] = ret['G']; // G or T becomes G
143 ret['M'] = ret['A'];
144 ret['m'] = ret['A']; // A or C becomes A
145 ret['B'] = ret['T'];
146 ret['b'] = ret['T']; // C or G or T becomes T
147 ret['D'] = ret['A'];
148 ret['d'] = ret['A']; // A or G or T becomes A
149 ret['H'] = ret['A'];
150 ret['h'] = ret['A']; // A or C or T becomes A
151 ret['V'] = ret['A'];
152 ret['v'] = ret['A']; // A or C or G becomes A
153
154 return ret;
155 }()};
156};
157
158// ------------------------------------------------------------------
159// containers
160// ------------------------------------------------------------------
161
168
169// ------------------------------------------------------------------
170// literals
171// ------------------------------------------------------------------
172inline namespace literals
173{
174
189constexpr dna3bs operator""_dna3bs(char const c) noexcept
190{
191 return dna3bs{}.assign_char(c);
192}
193
204{
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
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
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
The three letter reduced DNA alphabet for bisulfite sequencing mode (A,G,T(=C)).
Definition dna3bs.hpp:58
constexpr dna3bs() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:41
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:74
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:294
Provides utilities for modifying characters.
Hide me