SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
sam_dna16.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 
16 
17 namespace seqan3
18 {
19 
45 class sam_dna16 : public nucleotide_base<sam_dna16, 16>
46 {
47 private:
50 
52  friend base_t;
54  friend base_t::base_t;
56 
57 public:
61  constexpr sam_dna16() noexcept = default;
62  constexpr sam_dna16(sam_dna16 const &) noexcept = default;
63  constexpr sam_dna16(sam_dna16 &&) noexcept = default;
64  constexpr sam_dna16 & operator=(sam_dna16 const &) noexcept = default;
65  constexpr sam_dna16 & operator=(sam_dna16 &&) noexcept = default;
66  ~sam_dna16() noexcept = default;
67 
68  using base_t::base_t;
70 
71 protected:
73 
75  static constexpr char_type rank_to_char[alphabet_size]
76  {
77  '=',
78  'A',
79  'C',
80  'M',
81  'G',
82  'R',
83  'S',
84  'V',
85  'T',
86  'W',
87  'Y',
88  'H',
89  'K',
90  'D',
91  'B',
92  'N'
93  };
94 
96  static constexpr std::array<rank_type, 256> char_to_rank
97  {
98  [] () constexpr
99  {
101 
102  // initialize with UNKNOWN (std::array::fill unfortunately not constexpr)
103  for (auto & c : ret)
104  c = 15; // rank of 'N'
105 
106  // reverse mapping for characters and their lowercase
107  for (size_t rnk = 0u; rnk < alphabet_size; ++rnk)
108  {
109  ret[ rank_to_char[rnk] ] = rnk;
110  ret[to_lower(rank_to_char[rnk])] = rnk;
111  }
112 
113  // set U equal to T
114  ret['U'] = ret['T']; ret['u'] = ret['t'];
115 
116  return ret;
117  }()
118  };
119 
121  static const std::array<sam_dna16, alphabet_size> complement_table;
122 };
123 
124 // ------------------------------------------------------------------
125 // containers
126 // ------------------------------------------------------------------
127 
131 
132 // ------------------------------------------------------------------
133 // literals
134 // ------------------------------------------------------------------
135 
145 constexpr sam_dna16 operator""_sam_dna16(char const c) noexcept
146 {
147  return sam_dna16{}.assign_char(c);
148 }
149 
160 inline sam_dna16_vector operator""_sam_dna16(char const * s, size_t n)
161 {
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 // complement deferred definition
174 // ------------------------------------------------------------------
175 
176 constexpr std::array<sam_dna16, sam_dna16::alphabet_size> sam_dna16::complement_table
177 {
178  'N'_sam_dna16, // complement of '='_sam_dna16
179  'T'_sam_dna16, // complement of 'A'_sam_dna16
180  'G'_sam_dna16, // complement of 'C'_sam_dna16
181  'K'_sam_dna16, // complement of 'M'_sam_dna16
182  'C'_sam_dna16, // complement of 'G'_sam_dna16
183  'Y'_sam_dna16, // complement of 'R'_sam_dna16
184  'S'_sam_dna16, // complement of 'S'_sam_dna16
185  'B'_sam_dna16, // complement of 'V'_sam_dna16
186  'A'_sam_dna16, // complement of 'T'_sam_dna16
187  'W'_sam_dna16, // complement of 'W'_sam_dna16
188  'R'_sam_dna16, // complement of 'Y'_sam_dna16
189  'D'_sam_dna16, // complement of 'H'_sam_dna16
190  'M'_sam_dna16, // complement of 'K'_sam_dna16
191  'H'_sam_dna16, // complement of 'D'_sam_dna16
192  'V'_sam_dna16, // complement of 'B'_sam_dna16
193  'N'_sam_dna16 // complement of 'N'_sam_dna16
194 };
195 
196 } // namespace seqan3
std::vector::resize
T resize(T... args)
seqan3::sam_dna16::~sam_dna16
~sam_dna16() noexcept=default
Defaulted.
seqan3::alphabet_base< sam_dna16, 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
std::vector
seqan3::sam_dna16::sam_dna16
constexpr sam_dna16() noexcept=default
Defaulted.
seqan3::alphabet_base< sam_dna16, size, char >
seqan3::sam_dna16::operator=
constexpr sam_dna16 & operator=(sam_dna16 const &) noexcept=default
Defaulted.
seqan3::nucleotide_base
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition: nucleotide_base.hpp:40
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
seqan3::sam_dna16
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=').
Definition: sam_dna16.hpp:45
std::array< rank_type, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
nucleotide_base.hpp
Provides seqan3::nucleotide_base.
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