SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
aminoacid_base.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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
20namespace seqan3
21{
22
30template <typename derived_type, auto size>
31class aminoacid_base : public alphabet_base<derived_type, size, char>, public aminoacid_empty_base
32{
33private:
36
38 friend base_t;
39
43 constexpr aminoacid_base() noexcept = default;
44 constexpr aminoacid_base(aminoacid_base const &) noexcept = default;
45 constexpr aminoacid_base(aminoacid_base &&) noexcept = default;
46 constexpr aminoacid_base & operator=(aminoacid_base const &) noexcept = default;
47 constexpr aminoacid_base & operator=(aminoacid_base &&) noexcept = default;
48 ~aminoacid_base() noexcept = default;
49
51
53 friend derived_type;
54
55protected:
56 // Import from base:
57 using typename base_t::char_type;
58 using typename base_t::rank_type;
59
60public:
62 using base_t::to_rank;
63
67 // This constructor needs to be public, because constructor templates are not inherited otherwise
72 template <typename other_aa_type>
74 requires (!std::same_as<aminoacid_base, other_aa_type>) &&
75 (!std::same_as<derived_type, other_aa_type>) &&
78 explicit constexpr aminoacid_base(other_aa_type const other) noexcept
79 {
80 if constexpr (is_constexpr_default_constructible_v<other_aa_type> &&
81#if SEQAN3_WORKAROUND_GCC7_AND_8_CONCEPT_ISSUES
83#else
84 detail::writable_constexpr_alphabet<other_aa_type>
85#endif // SEQAN3_WORKAROUND_GCC7_AND_8_CONCEPT_ISSUES
86 )
87 {
88 static_cast<derived_type &>(*this) =
89 detail::convert_through_char_representation<derived_type, other_aa_type>[seqan3::to_rank(other)];
90 }
91 else
92 {
93 seqan3::assign_char_to(seqan3::to_char(other), static_cast<derived_type &>(*this));
94 }
95 }
97
117 static constexpr bool char_is_valid(char_type const c) noexcept
118 {
119 return valid_char_table[static_cast<uint8_t>(c)];
120 }
121
122private:
124 static constexpr std::array<bool, 256> valid_char_table
125 {
126 [] () constexpr
127 {
128 // init with false
130
131 // the original valid chars and their lower cases
132 for (size_t rank = 0u; rank < derived_type::alphabet_size; ++rank)
133 {
134 uint8_t c = derived_type::rank_to_char(rank);
135 ret[c] = true;
136 ret[to_lower(c)] = true;
137 }
138
139 return ret;
140 }()
141 };
142};
143
144} // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::alphabet_base.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:57
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: alphabet_base.hpp:139
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:80
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:203
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:72
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition: aminoacid_base.hpp:32
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:78
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:117
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:526
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:387
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:861
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:155
A concept that indicates whether an alphabet represents amino acids.
Refines seqan3::alphabet and adds assignability.
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
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
This is an empty base class that can be inherited by types that shall model seqan3::aminoacid_alphabe...
Definition: concept.hpp:35
Provides utilities for modifying characters.