BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
dna16sam.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
17
18namespace bio::alphabet
19{
20
48class dna16sam : public nucleotide_base<dna16sam, 16>
49{
50private:
53
55 friend base_t;
57 friend base_t::base_t;
59
60public:
64 constexpr dna16sam() noexcept = default;
65 constexpr dna16sam(dna16sam const &) noexcept = default;
66 constexpr dna16sam(dna16sam &&) noexcept = default;
67 constexpr dna16sam & operator=(dna16sam const &) noexcept = default;
68 constexpr dna16sam & operator=(dna16sam &&) noexcept = default;
69 ~dna16sam() noexcept = default;
70
71 using base_t::base_t;
73
74protected:
76
78 static constexpr std::array<char_type, alphabet_size>
79 rank_to_char{'=', 'A', 'C', 'M', 'G', 'R', 'S', 'V', 'T', 'W', 'Y', 'H', 'K', 'D', 'B', 'N'};
80
82 static constexpr std::array<rank_type, 256> char_to_rank = []() constexpr
83 {
85
86 // initialize with UNKNOWN
87 ret.fill(15); // rank of 'N'
88
89 // reverse mapping for characters and their lowercase
90 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
91 {
92 ret[rank_to_char[rnk]] = rnk;
93 ret[detail::to_lower(rank_to_char[rnk])] = rnk;
94 }
95
96 // set U equal to T
97 ret['U'] = ret['T'];
98 ret['u'] = ret['t'];
99
100 return ret;
101 }();
102
104 static const std::array<dna16sam, alphabet_size> complement_table;
105};
106
107} // namespace bio::alphabet
108
109// ------------------------------------------------------------------
110// literals
111// ------------------------------------------------------------------
112
113namespace bio::alphabet
114{
115
116inline namespace literals
117{
118
127consteval dna16sam operator""_dna16sam(char const c)
128{
129 if (!char_is_valid_for<dna16sam>(c))
130 throw std::invalid_argument{"Illegal character in character literal."};
131
132 return dna16sam{}.assign_char(c);
133}
134
144template <meta::detail::literal_buffer_string str>
145constexpr std::vector<dna16sam> operator""_dna16sam()
146{
147 return detail::string_literal<str, dna16sam>();
148}
150
151} // namespace literals
152
153} // namespace bio::alphabet
154
155// ------------------------------------------------------------------
156// complement deferred definition
157// ------------------------------------------------------------------
158
159namespace bio::alphabet
160{
161
162constexpr std::array<dna16sam, dna16sam::alphabet_size> dna16sam::complement_table{
163 'N'_dna16sam, // complement of '='_dna16sam
164 'T'_dna16sam, // complement of 'A'_dna16sam
165 'G'_dna16sam, // complement of 'C'_dna16sam
166 'K'_dna16sam, // complement of 'M'_dna16sam
167 'C'_dna16sam, // complement of 'G'_dna16sam
168 'Y'_dna16sam, // complement of 'R'_dna16sam
169 'S'_dna16sam, // complement of 'S'_dna16sam
170 'B'_dna16sam, // complement of 'V'_dna16sam
171 'A'_dna16sam, // complement of 'T'_dna16sam
172 'W'_dna16sam, // complement of 'W'_dna16sam
173 'R'_dna16sam, // complement of 'Y'_dna16sam
174 'D'_dna16sam, // complement of 'H'_dna16sam
175 'M'_dna16sam, // complement of 'K'_dna16sam
176 'H'_dna16sam, // complement of 'D'_dna16sam
177 'V'_dna16sam, // complement of 'B'_dna16sam
178 'N'_dna16sam // complement of 'N'_dna16sam
179};
180
181}
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=')....
Definition: dna16sam.hpp:49
constexpr dna16sam() noexcept=default
Defaulted.
A CRTP-base that refines bio::alphabet::base and is used by the nucleotides.
Definition: nucleotide_base.hpp:42
T fill(T... args)
The alphabet module's namespace.
Definition: aa10li.hpp:23
Provides bio::alphabet::nucleotide_base.