SeqAn3  3.0.3
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 
17 namespace seqan3
18 {
19 
47 class dna16sam : public nucleotide_base<dna16sam, 16>
48 {
49 private:
52 
54  friend base_t;
56  friend base_t::base_t;
58 
59 public:
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 
73 private:
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 #ifdef SEQAN3_DEPRECATED_310
178 
180 using sam_dna16_vector SEQAN3_DEPRECATED_310 = dna16sam_vector;
181 #endif // SEQAN3_DEPRECATED_310
182 
183 // ------------------------------------------------------------------
184 // literals
185 // ------------------------------------------------------------------
186 inline namespace literals
187 {
188 
203 constexpr dna16sam operator""_dna16sam(char const c) noexcept
204 {
205  return dna16sam{}.assign_char(c);
206 }
207 
219 inline dna16sam_vector operator""_dna16sam(char const * s, size_t n)
220 {
221  dna16sam_vector r;
222  r.resize(n);
223 
224  for (size_t i = 0; i < n; ++i)
225  r[i].assign_char(s[i]);
226 
227  return r;
228 }
229 
230 #ifdef SEQAN3_DEPRECATED_310
232 SEQAN3_DEPRECATED_310 constexpr dna16sam operator""_sam_dna16(char const c) noexcept
233 {
234  return seqan3::operator""_dna16sam(c);
235 }
236 
238 SEQAN3_DEPRECATED_310 inline dna16sam_vector operator""_sam_dna16(char const * s, size_t n)
239 {
240  return seqan3::operator""_dna16sam(s, n);
241 }
242 #endif // SEQAN3_DEPRECATED_310
244 
245 } // inline namespace literals
246 
247 } // namespace seqan3
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:81
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:104
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:211
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:276
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:96
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:57
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
dna16sam_vector sam_dna16_vector
Definition: dna16sam.hpp:180
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.
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:203
T resize(T... args)