SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
 
Loading...
Searching...
No Matches
dna3bs.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <vector>
16
19
20// ------------------------------------------------------------------
21// dna3bs
22// ------------------------------------------------------------------
23
24namespace seqan3
25{
60class dna3bs : public nucleotide_base<dna3bs, 3>
61{
62private:
65
67 friend base_t;
70 friend base_t::base_t;
72
73public:
77 constexpr dna3bs() noexcept = default;
78 constexpr dna3bs(dna3bs const &) noexcept = default;
79 constexpr dna3bs(dna3bs &&) noexcept = default;
80 constexpr dna3bs & operator=(dna3bs const &) noexcept = default;
81 constexpr dna3bs & operator=(dna3bs &&) noexcept = default;
82 ~dna3bs() noexcept = default;
83
84 using base_t::base_t;
86
87private:
89 static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'G', 'T'};
90
92 static constexpr rank_type rank_complement_table[alphabet_size]{
93 2, // T is complement of 'A'_dna3bs
94 2, // T is complement of 'G'_dna3bs
95 0 // A is complement of 'T'_dna3bs
96 };
97
99 static constexpr rank_type rank_complement(rank_type const rank)
100 {
101 return rank_complement_table[rank];
102 }
103
105 static constexpr char_type rank_to_char(rank_type const rank)
106 {
107 return rank_to_char_table[rank];
108 }
109
111 static constexpr rank_type char_to_rank(char_type const chr)
112 {
113 using index_t = std::make_unsigned_t<char_type>;
114 return char_to_rank_table[static_cast<index_t>(chr)];
115 }
116
117 // clang-format off
119 static constexpr std::array<rank_type, 256> char_to_rank_table
120 {
121 []() constexpr {
123
124 // reverse mapping for characters and their lowercase
125 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
126 {
127 ret[rank_to_char_table[rnk]] = rnk;
128 ret[to_lower(rank_to_char_table[rnk])] = rnk;
129 }
130
131 // set C and U equal to T
132 ret['C'] = ret['T'];
133 ret['c'] = ret['t'];
134 ret['U'] = ret['T'];
135 ret['u'] = ret['t'];
136
137 // iupac characters get special treatment, because there is no N
138 ret['R'] = ret['A'];
139 ret['r'] = ret['A']; // A or G becomes A
140 ret['Y'] = ret['T'];
141 ret['y'] = ret['T']; // C or T becomes T
142 ret['S'] = ret['T'];
143 ret['s'] = ret['T']; // C or G becomes T
144 ret['W'] = ret['A'];
145 ret['w'] = ret['A']; // A or T becomes A
146 ret['K'] = ret['G'];
147 ret['k'] = ret['G']; // G or T becomes G
148 ret['M'] = ret['A'];
149 ret['m'] = ret['A']; // A or C becomes A
150 ret['B'] = ret['T'];
151 ret['b'] = ret['T']; // C or G or T becomes T
152 ret['D'] = ret['A'];
153 ret['d'] = ret['A']; // A or G or T becomes A
154 ret['H'] = ret['A'];
155 ret['h'] = ret['A']; // A or C or T becomes A
156 ret['V'] = ret['A'];
157 ret['v'] = ret['A']; // A or C or G becomes A
158
159 return ret;
160 }()
161 };
162};
163// clang-format on
164
165// ------------------------------------------------------------------
166// containers
167// ------------------------------------------------------------------
168
175
176// ------------------------------------------------------------------
177// literals
178// ------------------------------------------------------------------
179inline namespace literals
180{
181
196constexpr dna3bs operator""_dna3bs(char const c) noexcept
197{
198 return dna3bs{}.assign_char(c);
199}
200
210SEQAN3_WORKAROUND_LITERAL dna3bs_vector operator""_dna3bs(char const * s, std::size_t n)
211{
213 r.resize(n);
214
215 for (size_t i = 0; i < n; ++i)
216 r[i].assign_char(s[i]);
217
218 return r;
219}
221
222} // namespace literals
223
224} // namespace seqan3
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:163
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:80
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:199
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:72
The three letter reduced DNA alphabet for bisulfite sequencing mode (A,G,T(=C))..
Definition: dna3bs.hpp:61
constexpr dna3bs() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:43
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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:83
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:282
T resize(T... args)
Provides utilities for modifying characters.