SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
dna4.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
15 #include <vector>
16 
18 
19 // ------------------------------------------------------------------
20 // dna4
21 // ------------------------------------------------------------------
22 
23 namespace seqan3
24 {
25 
26 class rna4;
27 
50 class dna4 : public nucleotide_base<dna4, 4>
51 {
52 private:
55 
57  friend base_t;
59  friend base_t::base_t;
62  friend rna4;
63 
64 public:
68  constexpr dna4() noexcept = default;
69  constexpr dna4(dna4 const &) noexcept = default;
70  constexpr dna4(dna4 &&) noexcept = default;
71  constexpr dna4 & operator=(dna4 const &) noexcept = default;
72  constexpr dna4 & operator=(dna4 &&) noexcept = default;
73  ~dna4() noexcept = default;
74 
75  using base_t::base_t;
76 
78  template <std::same_as<rna4> t> // Accept incomplete type
79  constexpr dna4(t const & r) noexcept
80  {
81  assign_rank(r.to_rank());
82  }
84 
85 protected:
87 
89  static constexpr char_type rank_to_char[alphabet_size]
90  {
91  'A',
92  'C',
93  'G',
94  'T'
95  };
96 
98  static constexpr std::array<rank_type, 256> char_to_rank
99  {
100  [] () constexpr
101  {
103 
104  // reverse mapping for characters and their lowercase
105  for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
106  {
107  ret[ rank_to_char[rnk] ] = rnk;
108  ret[to_lower(rank_to_char[rnk])] = rnk;
109  }
110 
111  // set U equal to T
112  ret['U'] = ret['T']; ret['u'] = ret['t'];
113 
114  // iupac characters get special treatment, because there is no N
115  ret['R'] = ret['A']; ret['r'] = ret['A']; // or G
116  ret['Y'] = ret['C']; ret['y'] = ret['C']; // or T
117  ret['S'] = ret['C']; ret['s'] = ret['C']; // or G
118  ret['W'] = ret['A']; ret['w'] = ret['A']; // or T
119  ret['K'] = ret['G']; ret['k'] = ret['G']; // or T
120  ret['M'] = ret['A']; ret['m'] = ret['A']; // or T
121  ret['B'] = ret['C']; ret['b'] = ret['C']; // or G or T
122  ret['D'] = ret['A']; ret['d'] = ret['A']; // or G or T
123  ret['H'] = ret['A']; ret['h'] = ret['A']; // or C or T
124  ret['V'] = ret['A']; ret['v'] = ret['A']; // or C or G
125 
126  return ret;
127  }()
128  };
129 
131  static const std::array<dna4, alphabet_size> complement_table;
132 };
133 
134 // ------------------------------------------------------------------
135 // containers
136 // ------------------------------------------------------------------
137 
141 
142 // ------------------------------------------------------------------
143 // literals
144 // ------------------------------------------------------------------
145 
154 constexpr dna4 operator""_dna4(char const c) noexcept
155 {
156  return dna4{}.assign_char(c);
157 }
158 
168 inline dna4_vector operator""_dna4(char const * s, std::size_t n)
169 {
170  dna4_vector r;
171  r.resize(n);
172 
173  for (size_t i = 0; i < n; ++i)
174  r[i].assign_char(s[i]);
175 
176  return r;
177 }
179 
180 // ------------------------------------------------------------------
181 // dna4 (deferred definition)
182 // ------------------------------------------------------------------
183 
184 constexpr std::array<dna4, dna4::alphabet_size> dna4::complement_table
185 {
186  'T'_dna4, // complement of 'A'_dna4
187  'G'_dna4, // complement of 'C'_dna4
188  'C'_dna4, // complement of 'G'_dna4
189  'A'_dna4 // complement of 'T'_dna4
190 };
191 
192 } // namespace seqan3
std::vector::resize
T resize(T... args)
seqan3::dna4::dna4
constexpr dna4() noexcept=default
Defaulted.
seqan3::alphabet_base< dna4, size, char >::alphabet_size
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:176
vector
seqan3::rna4
The four letter RNA alphabet of A,C,G,U.
Definition: rna4.hpp:47
seqan3::alphabet_base< dna4, size, char >
seqan3::nucleotide_base
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:41
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: alphabet_base.hpp:142
seqan3::dna4
The four letter DNA alphabet of A,C,G,T.
Definition: dna4.hpp:51
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
nucleotide_base.hpp
Provides seqan3::nucleotide_base.
seqan3::alphabet_base< dna4, size, char >::char_type
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:62
std
SeqAn specific customisations in the standard namespace.
seqan3::alphabet_base< dna4, size, char >::assign_rank
constexpr dna4 & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:167
std::size_t
seqan3::to_lower
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