SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
dna16sam.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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
16
17namespace seqan3
18{
19
47class dna16sam : public nucleotide_base<dna16sam, 16>
48{
49private:
52
54 friend base_t;
56 friend base_t::base_t;
58
59public:
63 constexpr dna16sam() noexcept = default;
64 constexpr dna16sam(dna16sam const &) noexcept = default;
65 constexpr dna16sam(dna16sam &&) noexcept = default;
66 constexpr dna16sam & operator=(dna16sam const &) noexcept = default;
67 constexpr dna16sam & operator=(dna16sam &&) noexcept = default;
68 ~dna16sam() noexcept = default;
69
70 using base_t::base_t;
72
73private:
75 static constexpr char_type rank_to_char_table[alphabet_size]
76 {
77 '=',
78 'A',
79 'C',
80 'M',
81 'G',
82 'R',
83 'S',
84 'V',
85 'T',
86 'W',
87 'Y',
88 'H',
89 'K',
90 'D',
91 'B',
92 'N'
93 };
94
96 static constexpr std::array<rank_type, 256> char_to_rank_table
97 {
98 [] () constexpr
99 {
101
102 // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
103 for (auto & c : ret)
104 c = 15; // rank of 'N'
105
106 // reverse mapping for characters and their lowercase
107 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
108 {
109 ret[rank_to_char_table[rnk]] = rnk;
110 ret[to_lower(rank_to_char_table[rnk])] = rnk;
111 }
112
113 // set U equal to T
114 ret['U'] = ret['T']; ret['u'] = ret['t'];
115
116 return ret;
117 }()
118 };
119
121 static constexpr rank_type rank_complement_table[alphabet_size]
122 {
123 15, // N is complement of '='_dna16sam 0
124 8, // T is complement of 'A'_dna16sam 1
125 4, // G is complement of 'C'_dna16sam 2
126 12, // K is complement of 'M'_dna16sam 3
127 2, // C is complement of 'G'_dna16sam 4
128 10, // Y is complement of 'R'_dna16sam 5
129 6, // S is complement of 'S'_dna16sam 6
130 14, // B is complement of 'V'_dna16sam 7
131 1, // A is complement of 'T'_dna16sam 8
132 9, // W is complement of 'W'_dna16sam 9
133 5, // R is complement of 'Y'_dna16sam 10
134 13, // D is complement of 'H'_dna16sam 11
135 3, // M is complement of 'K'_dna16sam 12
136 11, // H is complement of 'D'_dna16sam 13
137 7, // V is complement of 'B'_dna16sam 14
138 15 // N is complement of 'N'_dna16sam 15
139 };
140
142 static constexpr rank_type rank_complement(rank_type const rank)
143 {
144 return rank_complement_table[rank];
145 }
146
151 static constexpr char_type rank_to_char(rank_type const rank)
152 {
153 return rank_to_char_table[rank];
154 }
155
157 static constexpr rank_type char_to_rank(char_type const chr)
158 {
159 using index_t = std::make_unsigned_t<char_type>;
160 return char_to_rank_table[static_cast<index_t>(chr)];
161 }
162};
163
164// ------------------------------------------------------------------
165// containers
166// ------------------------------------------------------------------
167
174
175// ------------------------------------------------------------------
176// literals
177// ------------------------------------------------------------------
178inline namespace literals
179{
180
195constexpr dna16sam operator""_dna16sam(char const c) noexcept
196{
197 return dna16sam{}.assign_char(c);
198}
199
211inline dna16sam_vector operator""_dna16sam(char const * s, size_t n)
212{
214 r.resize(n);
215
216 for (size_t i = 0; i < n; ++i)
217 r[i].assign_char(s[i]);
218
219 return r;
220}
222
223} // inline namespace literals
224
225} // namespace seqan3
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:57
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:165
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:203
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
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=')....
Definition: dna16sam.hpp:48
constexpr dna16sam() 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: cigar_operation_table.hpp:2
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:81
Provides seqan3::nucleotide_base.
T resize(T... args)