SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
aminoacid_base.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 #include <seqan3/alphabet/detail/convert.hpp>
19 
20 namespace seqan3
21 {
22 
28 template <typename derived_type, auto size>
29 class aminoacid_base : public alphabet_base<derived_type, size, char>
30 {
31 private:
34 
36  friend base_t;
37 
41  constexpr aminoacid_base() noexcept = default;
42  constexpr aminoacid_base(aminoacid_base const &) noexcept = default;
43  constexpr aminoacid_base(aminoacid_base &&) noexcept = default;
44  constexpr aminoacid_base & operator=(aminoacid_base const &) noexcept = default;
45  constexpr aminoacid_base & operator=(aminoacid_base &&) noexcept = default;
46  ~aminoacid_base() noexcept = default;
47 
50  friend derived_type;
51 
52 protected:
53  // Import from base:
54  using typename base_t::char_type;
55  using typename base_t::rank_type;
56 
57 public:
59  using base_t::to_rank;
60 
64  // This constructor needs to be public, because constructor templates are not inherited otherwise
66  template <typename other_aa_type>
72  explicit constexpr aminoacid_base(other_aa_type const & other) noexcept
73  {
74  using seqan3::to_rank;
75  static_cast<derived_type &>(*this) =
76  detail::convert_through_char_representation<derived_type, other_aa_type>[to_rank(other)];
77  }
79 
97  static constexpr bool char_is_valid(char_type const c) noexcept
98  {
99  return valid_char_table[static_cast<uint8_t>(c)];
100  }
101 
102 private:
104  static constexpr std::array<bool, 256> valid_char_table
105  {
106  [] () constexpr
107  {
108  // init with false
109  std::array<bool, 256> ret{};
110 
111  // the original valid chars and their lower cases
112  for (uint8_t c : derived_type::rank_to_char)
113  {
114  ret[ c ] = true;
115  ret[to_lower(c)] = true;
116  }
117 
118  return ret;
119  }()
120  };
121 };
122 
123 } // namespace seqan3
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition: alphabet_base.hpp:63
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:103
The main SeqAn3 namespace.
constexpr aminoacid_base(other_aa_type const &other) noexcept
Allow explicit construction from any other aminoacid type and convert via the character representatio...
Definition: aminoacid_base.hpp:72
A concept that indicates whether an alphabet represents amino acids.Since an amino acid alphabet has ...
Provides seqan3::alphabet_base.
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character value has a one-to-one mapping to an alphabet value. ...
Definition: aminoacid_base.hpp:97
static detail::min_viable_uint_t< size > constexpr alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:175
Provides utilities for modifying characters.
constexpr rank_type to_rank() const noexcept
Return the letter&#39;s numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:117
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:29
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:52
Provides seqan3::AminoacidAlphabet.
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
std::conditional_t< std::Same< char, void >, char, char > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition: alphabet_base.hpp:61
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: transform.hpp:82