SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
 
Loading...
Searching...
No Matches
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;
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
74private:
77 [alphabet_size]{'=', 'A', 'C', 'M', 'G', 'R', 'S', 'V', 'T', 'W', 'Y', 'H', 'K', 'D', 'B', 'N'};
78
81 15, // N is complement of '='_dna16sam 0
82 8, // T is complement of 'A'_dna16sam 1
83 4, // G is complement of 'C'_dna16sam 2
84 12, // K is complement of 'M'_dna16sam 3
85 2, // C is complement of 'G'_dna16sam 4
86 10, // Y is complement of 'R'_dna16sam 5
87 6, // S is complement of 'S'_dna16sam 6
88 14, // B is complement of 'V'_dna16sam 7
89 1, // A is complement of 'T'_dna16sam 8
90 9, // W is complement of 'W'_dna16sam 9
91 5, // R is complement of 'Y'_dna16sam 10
92 13, // D is complement of 'H'_dna16sam 11
93 3, // M is complement of 'K'_dna16sam 12
94 11, // H is complement of 'D'_dna16sam 13
95 7, // V is complement of 'B'_dna16sam 14
96 15 // N is complement of 'N'_dna16sam 15
97 };
98
100 static constexpr rank_type rank_complement(rank_type const rank)
101 {
103 }
104
109 static constexpr char_type rank_to_char(rank_type const rank)
110 {
111 return rank_to_char_table[rank];
112 }
113
115 static constexpr rank_type char_to_rank(char_type const chr)
116 {
117 using index_t = std::make_unsigned_t<char_type>;
118 return char_to_rank_table[static_cast<index_t>(chr)];
119 }
120
121 // clang-format off
124 []() constexpr {
126
127 ret.fill(15u); // initialize with UNKNOWN ('N')
128
129 // reverse mapping for characters and their lowercase
130 for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
131 {
132 ret[rank_to_char_table[rnk]] = rnk;
133 ret[to_lower(rank_to_char_table[rnk])] = rnk;
134 }
135
136 // set U equal to T
137 ret['U'] = ret['T'];
138 ret['u'] = ret['t'];
139
140 return ret;
141 }()
142 };
143};
144// clang-format on
145
146// ------------------------------------------------------------------
147// containers
148// ------------------------------------------------------------------
149
156
157// ------------------------------------------------------------------
158// literals
159// ------------------------------------------------------------------
160inline namespace literals
161{
162
177constexpr dna16sam operator""_dna16sam(char const c) noexcept
178{
179 return dna16sam{}.assign_char(c);
180}
181
193SEQAN3_WORKAROUND_LITERAL dna16sam_vector operator""_dna16sam(char const * s, size_t n)
194{
196 r.resize(n);
197
198 for (size_t i = 0; i < n; ++i)
199 r[i].assign_char(s[i]);
200
201 return r;
202}
204
205} // namespace literals
206
207} // 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
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
rank_type rank
The value of the alphabet letter is stored as the rank.
Definition: alphabet_base.hpp:261
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=')....
Definition: dna16sam.hpp:48
static constexpr rank_type char_to_rank(char_type const chr)
Returns the rank representation of character.
Definition: dna16sam.hpp:115
static constexpr rank_type rank_complement_table[alphabet_size]
The rank complement table.
Definition: dna16sam.hpp:80
static constexpr char_type rank_to_char(rank_type const rank)
Returns the character representation of rank.
Definition: dna16sam.hpp:109
static constexpr std::array< rank_type, 256 > char_to_rank_table
The lookup table used in char_to_rank.
Definition: dna16sam.hpp:123
static constexpr char_type rank_to_char_table[alphabet_size]
The lookup table used in rank_to_char.
Definition: dna16sam.hpp:77
friend base_t
Befriend seqan3::nucleotide_base.
Definition: dna16sam.hpp:54
constexpr dna16sam() noexcept=default
Defaulted.
static constexpr rank_type rank_complement(rank_type const rank)
Returns the complement by rank.
Definition: dna16sam.hpp:100
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:43
alphabet_base< dna16sam, size, char > base_t
Type of the base class.
Definition: nucleotide_base.hpp:46
T fill(T... args)
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.
#define SEQAN3_WORKAROUND_LITERAL
Our char literals returning std::vector should be constexpr if constexpr std::vector is supported.
Definition: platform.hpp:282
T resize(T... args)