Loading...
Searching...
No Matches
aminoacid_base.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <seqan3/alphabet/alphabet_base.hpp>
#include <seqan3/alphabet/aminoacid/concept.hpp>
#include <seqan3/alphabet/detail/concept.hpp>
#include <seqan3/alphabet/detail/convert.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
namespace seqan3
{
template <typename derived_type, auto size>
class aminoacid_base : public aminoacid_empty_base, public alphabet_base<derived_type, size, char>
{
private:
using base_t = alphabet_base<derived_type, size, char>;
friend base_t;
constexpr aminoacid_base() noexcept = default;
constexpr aminoacid_base(aminoacid_base const &) noexcept = default;
constexpr aminoacid_base(aminoacid_base &&) noexcept = default;
constexpr aminoacid_base & operator=(aminoacid_base const &) noexcept = default;
constexpr aminoacid_base & operator=(aminoacid_base &&) noexcept = default;
~aminoacid_base() noexcept = default;
friend derived_type;
protected:
// Import from base:
using typename base_t::char_type;
using typename base_t::rank_type;
public:
using base_t::alphabet_size;
using base_t::to_rank;
// This constructor needs to be public, because constructor templates are not inherited otherwise
template <typename other_aa_type>
requires (!std::same_as<aminoacid_base, other_aa_type>) && (!std::same_as<derived_type, other_aa_type>)
&& aminoacid_alphabet<other_aa_type>
&& detail::convertable_to_through_char_representation<other_aa_type, derived_type>
explicit constexpr aminoacid_base(other_aa_type const other) noexcept
{
if constexpr (is_constexpr_default_constructible_v<other_aa_type>
&& detail::writable_constexpr_alphabet<other_aa_type>)
{
static_cast<derived_type &>(*this) =
detail::convert_through_char_representation<other_aa_type, derived_type>[seqan3::to_rank(other)];
}
else
{
seqan3::assign_char_to(seqan3::to_char(other), static_cast<derived_type &>(*this));
}
}
static constexpr bool char_is_valid(char_type const c) noexcept
{
return valid_char_table[static_cast<uint8_t>(c)];
}
private:
static constexpr std::array<bool, 256> valid_char_table{
[]() constexpr
{
std::array<bool, 256> ret{};
ret.fill(false); // Default constructor does not initialise!
// the original valid chars and their lower cases
for (size_t rank = 0u; rank < derived_type::alphabet_size; ++rank)
{
uint8_t c = derived_type::rank_to_char(rank);
ret[c] = true;
ret[to_lower(c)] = true;
}
return ret;
}()};
};
} // namespace seqan3
concept.hpp
Provides seqan3::aminoacid_alphabet.
concept.hpp
Provides alphabet helper concepts.
alphabet_base.hpp
Provides seqan3::alphabet_base.
std::array
seqan3::alphabet_base< derived_type, size, char >::alphabet_base
constexpr alphabet_base() noexcept=default
seqan3::alphabet_base< derived_type, size, char >::to_rank
constexpr rank_type to_rank() const noexcept
Definition alphabet_base.hpp:134
seqan3::alphabet_base< derived_type, size, char >::rank_type
detail::min_viable_uint_t< size - 1 > rank_type
Definition alphabet_base.hpp:77
seqan3::alphabet_base< derived_type, size, char >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
Definition alphabet_base.hpp:196
seqan3::alphabet_base< derived_type, size, char >::char_type
std::conditional_t< std::same_as< char, void >, char, char > char_type
Definition alphabet_base.hpp:69
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:108
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:74
std::array::fill
T fill(T... args)
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:381
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
aminoacid_alphabet
A concept that indicates whether an alphabet represents amino acids.
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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:74
seqan3::aminoacid_empty_base
This is an empty base class that can be inherited by types that shall model seqan3::aminoacid_alphabe...
Definition alphabet/aminoacid/concept.hpp:32
transform.hpp
Provides utilities for modifying characters.
Hide me