SeqAn3 3.4.0-rc.1
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;
75 constexpr dna3bs(dna3bs const &) noexcept = default;
76 constexpr dna3bs(dna3bs &&) noexcept = default;
77 constexpr dna3bs & operator=(dna3bs const &) noexcept = default;
78 constexpr dna3bs & operator=(dna3bs &&) noexcept = default;
79 ~dna3bs() noexcept = default;
80
81 using base_t::base_t;
83
84private:
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
114 // clang-format off
116 static constexpr std::array<rank_type, 256> char_to_rank_table
117 {
118 []() constexpr {
120
121 // reverse mapping for characters and their lowercase
122 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
123 {
124 ret[rank_to_char_table[rnk]] = rnk;
125 ret[to_lower(rank_to_char_table[rnk])] = rnk;
126 }
127
128 // set C and U equal to T
129 ret['C'] = ret['T'];
130 ret['c'] = ret['t'];
131 ret['U'] = ret['T'];
132 ret['u'] = ret['t'];
133
134 // iupac characters get special treatment, because there is no N
135 ret['R'] = ret['A'];
136 ret['r'] = ret['A']; // A or G becomes A
137 ret['Y'] = ret['T'];
138 ret['y'] = ret['T']; // C or T becomes T
139 ret['S'] = ret['T'];
140 ret['s'] = ret['T']; // C or G becomes T
141 ret['W'] = ret['A'];
142 ret['w'] = ret['A']; // A or T becomes A
143 ret['K'] = ret['G'];
144 ret['k'] = ret['G']; // G or T becomes G
145 ret['M'] = ret['A'];
146 ret['m'] = ret['A']; // A or C becomes A
147 ret['B'] = ret['T'];
148 ret['b'] = ret['T']; // C or G or T becomes T
149 ret['D'] = ret['A'];
150 ret['d'] = ret['A']; // A or G or T becomes A
151 ret['H'] = ret['A'];
152 ret['h'] = ret['A']; // A or C or T becomes A
153 ret['V'] = ret['A'];
154 ret['v'] = ret['A']; // A or C or G becomes A
155
156 return ret;
157 }()
158 };
159};
160// clang-format on
161
162// ------------------------------------------------------------------
163// containers
164// ------------------------------------------------------------------
165
172
173// ------------------------------------------------------------------
174// literals
175// ------------------------------------------------------------------
176inline namespace literals
177{
178
193constexpr dna3bs operator""_dna3bs(char const c) noexcept
194{
195 return dna3bs{}.assign_char(c);
196}
197
207SEQAN3_WORKAROUND_LITERAL dna3bs_vector operator""_dna3bs(char const * s, std::size_t n)
208{
210 r.resize(n);
211
212 for (size_t i = 0; i < n; ++i)
213 r[i].assign_char(s[i]);
214
215 return r;
216}
218
219} // namespace literals
220
221} // 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
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:40
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
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