SeqAn3 3.4.3-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
dna16sam.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2026 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2026 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <vector>
13
15
16namespace seqan3
17{
18
46class dna16sam : public nucleotide_base<dna16sam, 16>
47{
48private:
51
53 friend base_t;
56 friend base_t::base_t;
58
59public:
63 constexpr dna16sam() noexcept = default;
69
72
75 static constexpr char_type rank_to_char_table
76 [alphabet_size]{'=', 'A', 'C', 'M', 'G', 'R', 'S', 'V', 'T', 'W', 'Y', 'H', 'K', 'D', 'B', 'N'};
77
79 static constexpr rank_type rank_complement_table[alphabet_size]{
80 15, // N is complement of '='_dna16sam 0
81 8, // T is complement of 'A'_dna16sam 1
82 4, // G is complement of 'C'_dna16sam 2
83 12, // K is complement of 'M'_dna16sam 3
84 2, // C is complement of 'G'_dna16sam 4
85 10, // Y is complement of 'R'_dna16sam 5
86 6, // S is complement of 'S'_dna16sam 6
87 14, // B is complement of 'V'_dna16sam 7
88 1, // A is complement of 'T'_dna16sam 8
89 9, // W is complement of 'W'_dna16sam 9
90 5, // R is complement of 'Y'_dna16sam 10
91 13, // D is complement of 'H'_dna16sam 11
92 3, // M is complement of 'K'_dna16sam 12
93 11, // H is complement of 'D'_dna16sam 13
94 7, // V is complement of 'B'_dna16sam 14
95 15 // N is complement of 'N'_dna16sam 15
96 };
97
99 static constexpr rank_type rank_complement(rank_type const rank)
100 {
101 return rank_complement_table[rank];
102 }
103
108 static constexpr char_type rank_to_char(rank_type const rank)
109 {
110 return rank_to_char_table[rank];
111 }
112
114 static constexpr rank_type char_to_rank(char_type const chr)
115 {
116 using index_t = std::make_unsigned_t<char_type>;
117 return char_to_rank_table[static_cast<index_t>(chr)];
118 }
119
121 static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr
122 {
124
125 ret.fill(15u); // initialize with UNKNOWN ('N')
126
127 // reverse mapping for characters and their lowercase
128 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
129 {
130 ret[rank_to_char_table[rnk]] = rnk;
131 ret[to_lower(rank_to_char_table[rnk])] = rnk;
132 }
133
134 // set U equal to T
135 ret['U'] = ret['T'];
136 ret['u'] = ret['t'];
137
138 return ret;
139 }()};
140};
141
142// ------------------------------------------------------------------
143// containers
144// ------------------------------------------------------------------
145
152
153// ------------------------------------------------------------------
154// literals
155// ------------------------------------------------------------------
156inline namespace literals
157{
158
173constexpr dna16sam operator""_dna16sam(char const c) noexcept
174{
175 return dna16sam{}.assign_char(c);
176}
177
189SEQAN3_WORKAROUND_LITERAL dna16sam_vector operator""_dna16sam(char const * s, size_t n)
190{
192 r.resize(n);
193
194 for (size_t i = 0; i < n; ++i)
195 r[i].assign_char(s[i]);
196
197 return r;
198}
200
201} // namespace literals
202
203} // 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
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=').
Definition dna16sam.hpp:47
constexpr dna16sam() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:41
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: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:310
Hide me