SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
aminoacid_base.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
14#include <seqan3/alphabet/detail/convert.hpp>
16
17namespace seqan3
18{
19
27template <typename derived_type, auto size>
28class aminoacid_base : public aminoacid_empty_base, public alphabet_base<derived_type, size, char>
29{
30private:
33
35 friend base_t;
36
40 constexpr aminoacid_base() noexcept = default;
41 constexpr aminoacid_base(aminoacid_base const &) noexcept = default;
42 constexpr aminoacid_base(aminoacid_base &&) noexcept = default;
43 constexpr aminoacid_base & operator=(aminoacid_base const &) noexcept = default;
44 constexpr aminoacid_base & operator=(aminoacid_base &&) noexcept = default;
45 ~aminoacid_base() noexcept = default;
46
48
50 friend derived_type;
51
52protected:
53 // Import from base:
54 using typename base_t::char_type;
55 using typename base_t::rank_type;
56
57public:
59 using base_t::to_rank;
60
64 // This constructor needs to be public, because constructor templates are not inherited otherwise
69 template <typename other_aa_type>
70 requires (!std::same_as<aminoacid_base, other_aa_type>)
71 && (!std::same_as<derived_type, other_aa_type>) && aminoacid_alphabet<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>
75 && detail::writable_constexpr_alphabet<other_aa_type>)
76 {
77 static_cast<derived_type &>(*this) =
78 detail::convert_through_char_representation<other_aa_type, derived_type>[seqan3::to_rank(other)];
79 }
80 else
81 {
82 seqan3::assign_char_to(seqan3::to_char(other), static_cast<derived_type &>(*this));
83 }
84 }
86
106 static constexpr bool char_is_valid(char_type const c) noexcept
107 {
108 return valid_char_table[static_cast<uint8_t>(c)];
109 }
110
111private:
112 // clang-format off
114 static constexpr std::array<bool, 256> valid_char_table
115 {
116 []() constexpr {
118
119 ret.fill(false); // Default constructor does not initialise!
120
121 // the original valid chars and their lower cases
122 for (size_t rank = 0u; rank < derived_type::alphabet_size; ++rank)
123 {
124 uint8_t c = derived_type::rank_to_char(rank);
125 ret[c] = true;
126 ret[to_lower(c)] = true;
127 }
128
129 return ret;
130 }()
131 };
132};
133// clang-format on
134
135} // namespace seqan3
Provides seqan3::aminoacid_alphabet.
Provides seqan3::alphabet_base.
A CRTP-base that makes defining a custom alphabet easier.
Definition alphabet_base.hpp:54
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
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:77
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:196
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:69
A CRTP-base that refines seqan3::alphabet_base and is used by the amino acids.
Definition aminoacid_base.hpp:29
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
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:106
T fill(T... args)
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:521
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:383
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
A concept that indicates whether an alphabet represents amino acids.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:80
This is an empty base class that can be inherited by types that shall model seqan3::aminoacid_alphabe...
Definition alphabet/aminoacid/concept.hpp:32
Provides utilities for modifying characters.
Hide me