SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
dna3bs.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 // dna3bs
22 // ------------------------------------------------------------------
23 
24 namespace seqan3
25 {
55 class dna3bs : public nucleotide_base<dna3bs, 3>
56 {
57 private:
60 
62  friend base_t;
64  friend base_t::base_t;
66 
67 public:
71  constexpr dna3bs() noexcept = default;
72  constexpr dna3bs(dna3bs const &) noexcept = default;
73  constexpr dna3bs(dna3bs &&) noexcept = default;
74  constexpr dna3bs & operator=(dna3bs const &) noexcept = default;
75  constexpr dna3bs & operator=(dna3bs &&) noexcept = default;
76  ~dna3bs() noexcept = default;
77 
78  using base_t::base_t;
80 
81 protected:
83 
85  static constexpr char_type rank_to_char[alphabet_size]
86  {
87  'A',
88  'G',
89  'T'
90  };
91 
93  static constexpr std::array<rank_type, 256> char_to_rank
94  {
95  [] () constexpr
96  {
98 
99  // reverse mapping for characters and their lowercase
100  for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
101  {
102  ret[ rank_to_char[rnk] ] = rnk;
103  ret[to_lower(rank_to_char[rnk])] = rnk;
104  }
105 
106  // set C and U equal to T
107  ret['C'] = ret['T']; ret['c'] = ret['t'];
108  ret['U'] = ret['T']; ret['u'] = ret['t'];
109 
110  // iupac characters get special treatment, because there is no N
111  ret['R'] = ret['A']; ret['r'] = ret['A']; // A or G becomes A
112  ret['Y'] = ret['T']; ret['y'] = ret['T']; // C or T becomes T
113  ret['S'] = ret['T']; ret['s'] = ret['T']; // C or G becomes T
114  ret['W'] = ret['A']; ret['w'] = ret['A']; // A or T becomes A
115  ret['K'] = ret['G']; ret['k'] = ret['G']; // G or T becomes G
116  ret['M'] = ret['A']; ret['m'] = ret['A']; // A or C becomes A
117  ret['B'] = ret['T']; ret['b'] = ret['T']; // C or G or T becomes T
118  ret['D'] = ret['A']; ret['d'] = ret['A']; // A or G or T becomes A
119  ret['H'] = ret['A']; ret['h'] = ret['A']; // A or C or T becomes A
120  ret['V'] = ret['A']; ret['v'] = ret['A']; // A or C or G becomes A
121 
122  return ret;
123  }()
124  };
125 
127  static const std::array<dna3bs, alphabet_size> complement_table;
128 };
129 
130 // ------------------------------------------------------------------
131 // containers
132 // ------------------------------------------------------------------
133 
137 
138 // ------------------------------------------------------------------
139 // literals
140 // ------------------------------------------------------------------
141 
150 constexpr dna3bs operator""_dna3bs(char const c) noexcept
151 {
152  return dna3bs{}.assign_char(c);
153 }
154 
164 inline dna3bs_vector operator""_dna3bs(char const * s, std::size_t n)
165 {
166  dna3bs_vector r;
167  r.resize(n);
168 
169  for (size_t i = 0; i < n; ++i)
170  r[i].assign_char(s[i]);
171 
172  return r;
173 }
175 
176 // ------------------------------------------------------------------
177 // dna3bs (deferred definition)
178 // ------------------------------------------------------------------
179 
180 constexpr std::array<dna3bs, dna3bs::alphabet_size> dna3bs::complement_table
181 {
182  'T'_dna3bs, // complement of 'A'_dna3bs
183  'T'_dna3bs, // complement of 'G'_dna3bs
184  'A'_dna3bs // complement of 'T'_dna3bs
185 };
186 
187 } // namespace seqan3
seqan3::dna3bs::dna3bs
constexpr dna3bs() noexcept=default
Defaulted.
std::vector::resize
T resize(T... args)
seqan3::alphabet_base< dna3bs, 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:174
vector
seqan3::alphabet_base< dna3bs, size, char >
seqan3::nucleotide_base
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:40
seqan3::dna3bs
The three letter reduced DNA alphabet for bisulfite sequencing mode (A,G,T(=C)).
Definition: dna3bs.hpp:55
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:140
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
nucleotide_base.hpp
Provides seqan3::nucleotide_base.
transform.hpp
Provides utilities for modifying characters.
seqan3::dna3bs::~dna3bs
~dna3bs() noexcept=default
Defaulted.
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
std::conditional_t
seqan3::dna3bs::operator=
constexpr dna3bs & operator=(dna3bs const &) noexcept=default
Defaulted.