SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
aminoacid_base.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 #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>, public aminoacid_empty_base
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  if constexpr (is_constexpr_default_constructible_v<other_aa_type> &&
77 #else
78  detail::writable_constexpr_alphabet<other_aa_type>
79 #endif // SEQAN3_WORKAROUND_GCC7_AND_8_CONCEPT_ISSUES
80  )
81  {
82  static_cast<derived_type &>(*this) =
83  detail::convert_through_char_representation<derived_type, other_aa_type>[seqan3::to_rank(other)];
84  }
85  else
86  {
87  seqan3::assign_char_to(seqan3::to_char(other), static_cast<derived_type &>(*this));
88  }
89  }
91 
109  static constexpr bool char_is_valid(char_type const c) noexcept
110  {
111  return valid_char_table[static_cast<uint8_t>(c)];
112  }
113 
114 private:
116  static constexpr std::array<bool, 256> valid_char_table
117  {
118  [] () constexpr
119  {
120  // init with false
121  std::array<bool, 256> ret{};
122 
123  // the original valid chars and their lower cases
124  for (uint8_t c : derived_type::rank_to_char)
125  {
126  ret[ c ] = true;
127  ret[to_lower(c)] = true;
128  }
129 
130  return ret;
131  }()
132  };
133 };
134 
135 } // namespace seqan3
alphabet_base.hpp
Provides seqan3::alphabet_base.
concept.hpp
Provides seqan3::aminoacid_alphabet.
seqan3::alphabet_base< derived_type, 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
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:320
seqan3::alphabet_base
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:51
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:142
seqan3::aminoacid_empty_base
This is an empty base class that can be inherited by types that shall model seqan3::aminoacid_alphabe...
Definition: concept.hpp:32
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
aminoacid_alphabet
A concept that indicates whether an alphabet represents amino acids.
seqan3::alphabet_base< derived_type, size, char >::rank_type
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:62
std::array< bool, 256 >
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::aminoacid_base::aminoacid_base
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
seqan3::alphabet_base< derived_type, 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:60
transform.hpp
Provides utilities for modifying characters.
SEQAN3_WORKAROUND_GCC7_AND_8_CONCEPT_ISSUES
#define SEQAN3_WORKAROUND_GCC7_AND_8_CONCEPT_ISSUES
Various concept problems only present in GCC7 and GCC8.
Definition: platform.hpp:220
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:416
seqan3::aminoacid_base
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:29
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::aminoacid_base::char_is_valid
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:109
seqan3::alphabet_base< derived_type, size, char >::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:116
writable_alphabet
Refines seqan3::alphabet and adds assignability.