SeqAn3
aminoacid_base.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (chr) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (chr) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
42 #pragma once
43 
45 #include <seqan3/alphabet/detail/convert.hpp>
47 
48 namespace seqan3
49 {
50 
56 template <typename derived_type, auto size>
57 class aminoacid_base : public alphabet_base<derived_type, size, char>
58 {
59 private:
62 
64  friend base_t;
65 
69  constexpr aminoacid_base() : base_t{} {}
70  constexpr aminoacid_base(aminoacid_base const &) = default;
71  constexpr aminoacid_base(aminoacid_base &&) = default;
72  constexpr aminoacid_base & operator=(aminoacid_base const &) = default;
73  constexpr aminoacid_base & operator=(aminoacid_base &&) = default;
74  ~aminoacid_base() = default;
76 
78  friend derived_type;
79 
80 public:
81 
82  // Import from base:
83  using typename base_t::char_type;
84  using typename base_t::rank_type;
85  using base_t::value_size;
86  using base_t::to_rank;
87 
91  // This constructor needs to be public, because constructor templates are not inherited otherwise
93  template <typename other_aa_type>
99  explicit constexpr aminoacid_base(other_aa_type const & other) noexcept
100  {
101  using seqan3::to_rank;
102  static_cast<derived_type &>(*this) =
103  detail::convert_through_char_representation<derived_type, other_aa_type>[to_rank(other)];
104  }
106 
111  static derived_type constexpr A = assign_char(derived_type{}, 'A');
113  static derived_type constexpr B = assign_char(derived_type{}, 'B');
114  static derived_type constexpr C = assign_char(derived_type{}, 'C');
115  static derived_type constexpr D = assign_char(derived_type{}, 'D');
116  static derived_type constexpr E = assign_char(derived_type{}, 'E');
117  static derived_type constexpr F = assign_char(derived_type{}, 'F');
118  static derived_type constexpr G = assign_char(derived_type{}, 'G');
119  static derived_type constexpr H = assign_char(derived_type{}, 'H');
120  static derived_type constexpr I = assign_char(derived_type{}, 'I');
121  static derived_type constexpr J = assign_char(derived_type{}, 'J');
122  static derived_type constexpr K = assign_char(derived_type{}, 'K');
123  static derived_type constexpr L = assign_char(derived_type{}, 'L');
124  static derived_type constexpr M = assign_char(derived_type{}, 'M');
125  static derived_type constexpr N = assign_char(derived_type{}, 'N');
126  static derived_type constexpr O = assign_char(derived_type{}, 'O');
127  static derived_type constexpr P = assign_char(derived_type{}, 'P');
128  static derived_type constexpr Q = assign_char(derived_type{}, 'Q');
129  static derived_type constexpr R = assign_char(derived_type{}, 'R');
130  static derived_type constexpr S = assign_char(derived_type{}, 'S');
131  static derived_type constexpr T = assign_char(derived_type{}, 'T');
132  static derived_type constexpr U = assign_char(derived_type{}, 'U');
133  static derived_type constexpr V = assign_char(derived_type{}, 'V');
134  static derived_type constexpr W = assign_char(derived_type{}, 'W');
135  static derived_type constexpr X = assign_char(derived_type{}, 'X');
136  static derived_type constexpr Y = assign_char(derived_type{}, 'Y');
137  static derived_type constexpr Z = assign_char(derived_type{}, 'Z');
138  static derived_type constexpr TERMINATOR = assign_char(derived_type{}, '*');
139  static derived_type constexpr UNKNOWN = X;
141 };
142 
143 } // 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:89
char char_type
The type of the alphabet when converted to char (e.g. via to_char()).
Definition: alphabet_base.hpp:87
A concept that indicates whether an alphabet represents amino acids.In addition to the requirements f...
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
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:99
static detail::min_viable_uint_t< size > constexpr value_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: alphabet_base.hpp:198
Provides seqan3::alphabet_base.
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
constexpr derived_type & assign_char(std::conditional_t< std::Same< char_type, void >, char, char_type > const c) noexcept
Assign from a character.
Definition: alphabet_base.hpp:165
constexpr rank_type to_rank() const noexcept
Return the letter&#39;s numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:142
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:57
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:77
Provides seqan3::aminoacid_concept.
constexpr underlying_rank_t< alphabet_type > to_rank(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::to_rank() that delegates to a member function...
Definition: member_exposure.hpp:97