SeqAn3 3.4.0-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-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
13
14namespace seqan3
15{
16
44class dna16sam : public nucleotide_base<dna16sam, 16>
45{
46private:
49
51 friend base_t;
54 friend base_t::base_t;
56
57public:
61 constexpr dna16sam() noexcept = default;
62 constexpr dna16sam(dna16sam const &) noexcept = default;
63 constexpr dna16sam(dna16sam &&) noexcept = default;
64 constexpr dna16sam & operator=(dna16sam const &) noexcept = default;
65 constexpr dna16sam & operator=(dna16sam &&) noexcept = default;
66 ~dna16sam() noexcept = default;
67
68 using base_t::base_t;
70
71private:
73 static constexpr char_type rank_to_char_table
74 [alphabet_size]{'=', 'A', 'C', 'M', 'G', 'R', 'S', 'V', 'T', 'W', 'Y', 'H', 'K', 'D', 'B', 'N'};
75
77 static constexpr rank_type rank_complement_table[alphabet_size]{
78 15, // N is complement of '='_dna16sam 0
79 8, // T is complement of 'A'_dna16sam 1
80 4, // G is complement of 'C'_dna16sam 2
81 12, // K is complement of 'M'_dna16sam 3
82 2, // C is complement of 'G'_dna16sam 4
83 10, // Y is complement of 'R'_dna16sam 5
84 6, // S is complement of 'S'_dna16sam 6
85 14, // B is complement of 'V'_dna16sam 7
86 1, // A is complement of 'T'_dna16sam 8
87 9, // W is complement of 'W'_dna16sam 9
88 5, // R is complement of 'Y'_dna16sam 10
89 13, // D is complement of 'H'_dna16sam 11
90 3, // M is complement of 'K'_dna16sam 12
91 11, // H is complement of 'D'_dna16sam 13
92 7, // V is complement of 'B'_dna16sam 14
93 15 // N is complement of 'N'_dna16sam 15
94 };
95
97 static constexpr rank_type rank_complement(rank_type const rank)
98 {
99 return rank_complement_table[rank];
100 }
101
106 static constexpr char_type rank_to_char(rank_type const rank)
107 {
108 return rank_to_char_table[rank];
109 }
110
112 static constexpr rank_type char_to_rank(char_type const chr)
113 {
114 using index_t = std::make_unsigned_t<char_type>;
115 return char_to_rank_table[static_cast<index_t>(chr)];
116 }
117
118 // clang-format off
120 static constexpr std::array<rank_type, 256> char_to_rank_table{
121 []() constexpr {
123
124 ret.fill(15u); // initialize with UNKNOWN ('N')
125
126 // reverse mapping for characters and their lowercase
127 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
128 {
129 ret[rank_to_char_table[rnk]] = rnk;
130 ret[to_lower(rank_to_char_table[rnk])] = rnk;
131 }
132
133 // set U equal to T
134 ret['U'] = ret['T'];
135 ret['u'] = ret['t'];
136
137 return ret;
138 }()
139 };
140};
141// clang-format on
142
143// ------------------------------------------------------------------
144// containers
145// ------------------------------------------------------------------
146
153
154// ------------------------------------------------------------------
155// literals
156// ------------------------------------------------------------------
157inline namespace literals
158{
159
174constexpr dna16sam operator""_dna16sam(char const c) noexcept
175{
176 return dna16sam{}.assign_char(c);
177}
178
190SEQAN3_WORKAROUND_LITERAL dna16sam_vector operator""_dna16sam(char const * s, size_t n)
191{
193 r.resize(n);
194
195 for (size_t i = 0; i < n; ++i)
196 r[i].assign_char(s[i]);
197
198 return r;
199}
201
202} // namespace literals
203
204} // 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 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=').
Definition dna16sam.hpp:45
constexpr dna16sam() noexcept=default
Defaulted.
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:40
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
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)
Hide me