SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
dna16sam.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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
76 [alphabet_size]{'=', 'A', 'C', 'M', 'G', 'R', 'S', 'V', 'T', 'W', 'Y', 'H', 'K', 'D', 'B', 'N'};
77
79 static constexpr std::array<rank_type, 256> char_to_rank_table{[]() constexpr {std::array<rank_type, 256> ret{};
80
81 // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
82 for (auto & c : ret)
83 c = 15; // rank of 'N'
84
85 // reverse mapping for characters and their lowercase
86 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
87 {
88 ret[rank_to_char_table[rnk]] = rnk;
89 ret[to_lower(rank_to_char_table[rnk])] = rnk;
90 }
91
92 // set U equal to T
93 ret['U'] = ret['T'];
94 ret['u'] = ret['t'];
95
96 return ret;
97}()
98}; // namespace seqan3
99
101static constexpr rank_type rank_complement_table[alphabet_size]{
102 15, // N is complement of '='_dna16sam 0
103 8, // T is complement of 'A'_dna16sam 1
104 4, // G is complement of 'C'_dna16sam 2
105 12, // K is complement of 'M'_dna16sam 3
106 2, // C is complement of 'G'_dna16sam 4
107 10, // Y is complement of 'R'_dna16sam 5
108 6, // S is complement of 'S'_dna16sam 6
109 14, // B is complement of 'V'_dna16sam 7
110 1, // A is complement of 'T'_dna16sam 8
111 9, // W is complement of 'W'_dna16sam 9
112 5, // R is complement of 'Y'_dna16sam 10
113 13, // D is complement of 'H'_dna16sam 11
114 3, // M is complement of 'K'_dna16sam 12
115 11, // H is complement of 'D'_dna16sam 13
116 7, // V is complement of 'B'_dna16sam 14
117 15 // N is complement of 'N'_dna16sam 15
118};
119
121static constexpr rank_type rank_complement(rank_type const rank)
122{
123 return rank_complement_table[rank];
124}
125
130static constexpr char_type rank_to_char(rank_type const rank)
131{
132 return rank_to_char_table[rank];
133}
134
136static constexpr rank_type char_to_rank(char_type const chr)
137{
138 using index_t = std::make_unsigned_t<char_type>;
139 return char_to_rank_table[static_cast<index_t>(chr)];
140}
141}
142;
143
144// ------------------------------------------------------------------
145// containers
146// ------------------------------------------------------------------
147
154
155// ------------------------------------------------------------------
156// literals
157// ------------------------------------------------------------------
158inline namespace literals
159{
160
175constexpr dna16sam operator""_dna16sam(char const c) noexcept
176{
177 return dna16sam{}.assign_char(c);
178}
179
191inline dna16sam_vector operator""_dna16sam(char const * s, size_t n)
192{
194 r.resize(n);
195
196 for (size_t i = 0; i < n; ++i)
197 r[i].assign_char(s[i]);
198
199 return r;
200}
202
203} // namespace literals
204
205} // namespace seqan3
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:163
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:199
std::conditional_t< std::same_as< char, void >, char, char > 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: aligned_sequence_concept.hpp:29
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:83
Provides seqan3::nucleotide_base.
T resize(T... args)