SeqAn3 3.4.0-rc.4
The Modern C++ library for sequence analysis.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
dna16sam.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 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;
67
70
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
119 static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr
120 {
122
123 ret.fill(15u); // initialize with UNKNOWN ('N')
124
125 // reverse mapping for characters and their lowercase
126 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
127 {
128 ret[rank_to_char_table[rnk]] = rnk;
129 ret[to_lower(rank_to_char_table[rnk])] = rnk;
130 }
131
132 // set U equal to T
133 ret['U'] = ret['T'];
134 ret['u'] = ret['t'];
135
136 return ret;
137 }()};
138};
139
140// ------------------------------------------------------------------
141// containers
142// ------------------------------------------------------------------
143
150
151// ------------------------------------------------------------------
152// literals
153// ------------------------------------------------------------------
154inline namespace literals
155{
156
171constexpr dna16sam operator""_dna16sam(char const c) noexcept
172{
173 return dna16sam{}.assign_char(c);
174}
175
187SEQAN3_WORKAROUND_LITERAL dna16sam_vector operator""_dna16sam(char const * s, size_t n)
188{
190 r.resize(n);
191
192 for (size_t i = 0; i < n; ++i)
193 r[i].assign_char(s[i]);
194
195 return r;
196}
198
199} // namespace literals
200
201} // 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:45
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