SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
dna15.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 
19 
20 // ------------------------------------------------------------------
21 // dna15
22 // ------------------------------------------------------------------
23 
24 namespace seqan3
25 {
26 
27 class rna15;
28 
48 class dna15 : public nucleotide_base<dna15, 15>
49 {
50 private:
53 
55  friend base_t;
57  friend base_t::base_t;
60  friend rna15;
61 
62 public:
66  constexpr dna15() noexcept = default;
67  constexpr dna15(dna15 const &) noexcept = default;
68  constexpr dna15(dna15 &&) noexcept = default;
69  constexpr dna15 & operator=(dna15 const &) noexcept = default;
70  constexpr dna15 & operator=(dna15 &&) noexcept = default;
71  ~dna15() noexcept = default;
72 
73  using base_t::base_t;
74 
76  template <std::same_as<rna15> t> // Accept incomplete type
77  constexpr dna15(t const & r) noexcept
78  {
79  assign_rank(r.to_rank());
80  }
82 
83 protected:
85 
87  static constexpr char_type rank_to_char[alphabet_size]
88  {
89  'A',
90  'B',
91  'C',
92  'D',
93  'G',
94  'H',
95  'K',
96  'M',
97  'N',
98  'R',
99  'S',
100  'T',
101  'V',
102  'W',
103  'Y'
104  };
105 
107  static constexpr std::array<rank_type, 256> char_to_rank
108  {
109  [] () constexpr
110  {
112 
113  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
114  for (auto & c : ret)
115  c = 8; // rank of 'N'
116 
117  // reverse mapping for characters and their lowercase
118  for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
119  {
120  ret[ rank_to_char[rnk] ] = rnk;
121  ret[to_lower(rank_to_char[rnk])] = rnk;
122  }
123 
124  // set U equal to T
125  ret['U'] = ret['T']; ret['u'] = ret['t'];
126 
127  return ret;
128  }()
129  };
130 
132  static const std::array<dna15, alphabet_size> complement_table;
133 };
134 
135 // ------------------------------------------------------------------
136 // containers
137 // ------------------------------------------------------------------
138 
142 
143 // ------------------------------------------------------------------
144 // literals
145 // ------------------------------------------------------------------
146 
155 constexpr dna15 operator""_dna15(char const c) noexcept
156 {
157  return dna15{}.assign_char(c);
158 }
159 
169 inline dna15_vector operator""_dna15(char const * s, std::size_t n)
170 {
171  dna15_vector r;
172  r.resize(n);
173 
174  for (size_t i = 0; i < n; ++i)
175  r[i].assign_char(s[i]);
176 
177  return r;
178 }
180 
181 // ------------------------------------------------------------------
182 // dna15 (deferred definition)
183 // ------------------------------------------------------------------
184 
185 constexpr std::array<dna15, dna15::alphabet_size> dna15::complement_table
186 {
187  'T'_dna15, // complement of 'A'_dna15
188  'V'_dna15, // complement of 'B'_dna15
189  'G'_dna15, // complement of 'C'_dna15
190  'H'_dna15, // complement of 'D'_dna15
191  'C'_dna15, // complement of 'G'_dna15
192  'D'_dna15, // complement of 'H'_dna15
193  'M'_dna15, // complement of 'K'_dna15
194  'K'_dna15, // complement of 'M'_dna15
195  'N'_dna15, // complement of 'N'_dna15
196  'Y'_dna15, // complement of 'R'_dna15
197  'S'_dna15, // complement of 'S'_dna15
198  'A'_dna15, // complement of 'T'_dna15
199  'B'_dna15, // complement of 'V'_dna15
200  'W'_dna15, // complement of 'W'_dna15
201  'R'_dna15 // complement of 'Y'_dna15
202 };
203 
204 } // namespace seqan3
std::vector::resize
T resize(T... args)
seqan3::alphabet_base< dna15, 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::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:49
seqan3::alphabet_base< dna15, 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::rna15
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition: rna15.hpp:49
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< dna15, 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
transform.hpp
Provides utilities for modifying characters.
std
SeqAn specific customisations in the standard namespace.
seqan3::alphabet_base< dna15, size, char >::assign_rank
constexpr dna15 & 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
seqan3::dna15::dna15
constexpr dna15() noexcept=default
Defaulted.