SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
dna5.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 // dna5
22 // ------------------------------------------------------------------
23 
24 namespace seqan3
25 {
26 
27 class rna5;
28 
48 class dna5 : public nucleotide_base<dna5, 5>
49 {
50 private:
53 
55  friend base_t;
57  friend base_t::base_t;
60  friend rna5;
61 
62 public:
66  constexpr dna5() noexcept = default;
67  constexpr dna5(dna5 const &) noexcept = default;
68  constexpr dna5(dna5 &&) noexcept = default;
69  constexpr dna5 & operator=(dna5 const &) noexcept = default;
70  constexpr dna5 & operator=(dna5 &&) noexcept = default;
71  ~dna5() noexcept = default;
72 
73  using base_t::base_t;
74 
76  template <std::same_as<rna5> t> // Accept incomplete type
77  constexpr dna5(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  'C',
91  'G',
92  'N',
93  'T'
94  };
95 
97  static constexpr std::array<rank_type, 256> char_to_rank
98  {
99  [] () constexpr
100  {
102 
103  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
104  for (auto & c : ret)
105  c = 3; // == 'N'
106 
107  // reverse mapping for characters and their lowercase
108  for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
109  {
110  ret[ rank_to_char[rnk] ] = rnk;
111  ret[to_lower(rank_to_char[rnk])] = rnk;
112  }
113 
114  // set U equal to T
115  ret['U'] = ret['T']; ret['u'] = ret['t'];
116 
117  // iupac characters are implicitly "UNKNOWN"
118  return ret;
119  }()
120  };
121 
123  static const std::array<dna5, alphabet_size> complement_table;
124 };
125 
126 // ------------------------------------------------------------------
127 // containers
128 // ------------------------------------------------------------------
129 
133 
134 // ------------------------------------------------------------------
135 // literals
136 // ------------------------------------------------------------------
137 
146 constexpr dna5 operator""_dna5(char const c) noexcept
147 {
148  return dna5{}.assign_char(c);
149 }
150 
160 inline dna5_vector operator""_dna5(char const * s, std::size_t n)
161 {
162  dna5_vector r;
163  r.resize(n);
164 
165  for (size_t i = 0; i < n; ++i)
166  r[i].assign_char(s[i]);
167 
168  return r;
169 }
171 
172 // ------------------------------------------------------------------
173 // dna5 (deferred definition)
174 // ------------------------------------------------------------------
175 
176 constexpr std::array<dna5, dna5::alphabet_size> dna5::complement_table
177 {
178  'T'_dna5, // complement of 'A'_dna5
179  'G'_dna5, // complement of 'C'_dna5
180  'C'_dna5, // complement of 'G'_dna5
181  'N'_dna5, // complement of 'N'_dna5
182  'A'_dna5 // complement of 'T'_dna5
183 };
184 
185 } // namespace seqan3
std::vector::resize
T resize(T... args)
seqan3::alphabet_base< dna5, 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::alphabet_base< dna5, 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
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::rna5
The five letter RNA alphabet of A,C,G,U and the unknown character N.
Definition: rna5.hpp:47
nucleotide_base.hpp
Provides seqan3::nucleotide_base.
seqan3::alphabet_base< dna5, 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< dna5, size, char >::assign_rank
constexpr dna5 & 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::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:49
seqan3::dna5::dna5
constexpr dna5() noexcept=default
Defaulted.