SeqAn3
dna15.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <vector>
43 
46 
47 // ------------------------------------------------------------------
48 // dna15
49 // ------------------------------------------------------------------
50 
51 namespace seqan3
52 {
53 
54 class rna15;
55 
73 class dna15 : public nucleotide_base<dna15, 15>
74 {
75 private:
78 
80  friend base_t;
82  friend base_t::base_t;
85  friend rna15;
86 
87 public:
91  constexpr dna15() noexcept : base_t{} {}
92  constexpr dna15(dna15 const &) = default;
93  constexpr dna15(dna15 &&) = default;
94  constexpr dna15 & operator=(dna15 const &) = default;
95  constexpr dna15 & operator=(dna15 &&) = default;
96  ~dna15() = default;
97 
98  using base_t::base_t;
99 
101  template <std::Same<rna15> t> // Accept incomplete type
102  constexpr dna15(t const & r) noexcept
103  {
104  assign_rank(r.to_rank());
105  }
107 
108 protected:
110 
112  static constexpr char_type rank_to_char[value_size]
113  {
114  'A',
115  'B',
116  'C',
117  'D',
118  'G',
119  'H',
120  'K',
121  'M',
122  'N',
123  'R',
124  'S',
125  'T',
126  'V',
127  'W',
128  'Y'
129  };
130 
132  static constexpr std::array<rank_type, 256> char_to_rank
133  {
134  [] () constexpr
135  {
136  std::array<rank_type, 256> ret{};
137 
138  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
139  for (auto & c : ret)
140  c = 8; // rank of 'N'
141 
142  // reverse mapping for characters and their lowercase
143  for (size_t rnk = 0u; rnk < value_size; ++rnk)
144  {
145  ret[ rank_to_char[rnk] ] = rnk;
146  ret[to_lower(rank_to_char[rnk])] = rnk;
147  }
148 
149  // set U equal to T
150  ret['U'] = ret['T']; ret['u'] = ret['t'];
151 
152  return ret;
153  }()
154  };
155 
157  static const std::array<dna15, value_size> complement_table;
158 };
159 
160 // ------------------------------------------------------------------
161 // containers
162 // ------------------------------------------------------------------
163 
166 using dna15_vector = std::vector<dna15>;
167 
168 // ------------------------------------------------------------------
169 // literals
170 // ------------------------------------------------------------------
171 
180 constexpr dna15 operator""_dna15(char const c) noexcept
181 {
182  return dna15{}.assign_char(c);
183 }
184 
194 inline dna15_vector operator""_dna15(char const * s, std::size_t n)
195 {
196  dna15_vector r;
197  r.resize(n);
198 
199  for (size_t i = 0; i < n; ++i)
200  r[i].assign_char(s[i]);
201 
202  return r;
203 }
205 
206 // ------------------------------------------------------------------
207 // dna15 (deferred definition)
208 // ------------------------------------------------------------------
209 
210 constexpr std::array<dna15, dna15::value_size> dna15::complement_table
211 {
212  'T'_dna15, // complement of 'A'_dna15
213  'V'_dna15, // complement of 'B'_dna15
214  'G'_dna15, // complement of 'C'_dna15
215  'H'_dna15, // complement of 'D'_dna15
216  'C'_dna15, // complement of 'G'_dna15
217  'D'_dna15, // complement of 'H'_dna15
218  'M'_dna15, // complement of 'K'_dna15
219  'K'_dna15, // complement of 'M'_dna15
220  'N'_dna15, // complement of 'N'_dna15
221  'Y'_dna15, // complement of 'R'_dna15
222  'S'_dna15, // complement of 'S'_dna15
223  'A'_dna15, // complement of 'T'_dna15
224  'B'_dna15, // complement of 'V'_dna15
225  'W'_dna15, // complement of 'W'_dna15
226  'R'_dna15 // complement of 'Y'_dna15
227 };
228 
229 } // namespace seqan3
char char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
alphabet_concept && assign_char(alphabet_concept &&alph, char_type const chr)
Returns the alphabet letter&#39;s value in character representation.
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:73
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
constexpr dna15 & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: alphabet_base.hpp:189
static detail::min_viable_uint_t< size > constexpr value_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:198
Provides seqan3::nucleotide_base.
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition: rna15.hpp:73
constexpr dna15(t const &r) noexcept
Allow implicit construction from dna/rna of the same size.
Definition: dna15.hpp:102
Provides utilities for modifying characters.
std::vector< dna15 > dna15_vector
Alias for an std::vector of seqan3::dna15.
Definition: dna15.hpp:166
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:65
constexpr char_type to_lower(char_type const c) noexcept
Converts &#39;A&#39;-&#39;Z&#39; to &#39;a&#39;-&#39;z&#39; respectively; other characters are returned as is.
Definition: char_operations.hpp:107