Loading...
Searching...
No Matches
nucleotide_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/detail/concept.hpp>
#include <seqan3/alphabet/detail/convert.hpp>
#include <seqan3/alphabet/nucleotide/concept.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
namespace seqan3
{
template <typename derived_type, auto size>
class nucleotide_base : public alphabet_base<derived_type, size, char>
{
private:
using base_t = alphabet_base<derived_type, size, char>;
constexpr nucleotide_base() noexcept = default;
constexpr nucleotide_base(nucleotide_base const &) noexcept = default;
constexpr nucleotide_base(nucleotide_base &&) noexcept = default;
constexpr nucleotide_base & operator=(nucleotide_base const &) noexcept = default;
constexpr nucleotide_base & operator=(nucleotide_base &&) noexcept = default;
~nucleotide_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_nucl_type>
requires (!std::same_as<nucleotide_base, other_nucl_type>) && (!std::same_as<derived_type, other_nucl_type>)
&& nucleotide_alphabet<other_nucl_type>
&& detail::convertable_to_through_char_representation<other_nucl_type, derived_type>
explicit constexpr nucleotide_base(other_nucl_type const & other) noexcept
{
static_cast<derived_type &>(*this) =
detail::convert_through_char_representation<other_nucl_type, derived_type>[seqan3::to_rank(other)];
}
constexpr derived_type complement() const noexcept
{
return derived_type{}.assign_rank(derived_type{}.rank_complement(to_rank()));
}
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{};
// Value-initialisation of std::array does usually initialise. `fill` is explicit.
ret.fill(false);
// 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;
}
// U and T shall be accepted for all
ret['U'] = true;
ret['T'] = true;
ret['u'] = true;
ret['t'] = true;
return ret;
}()};
};
} // namespace seqan3
concept.hpp
Provides alphabet helper concepts.
concept.hpp
Provides seqan3::nucleotide_alphabet.
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::alphabet_base::assign_rank
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
seqan3::nucleotide_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 nucleotide_base.hpp:138
seqan3::nucleotide_base::nucleotide_base
constexpr nucleotide_base(other_nucl_type const &other) noexcept
Allow explicit construction from any other nucleotide type and convert via the character representati...
Definition nucleotide_base.hpp:82
seqan3::nucleotide_base::complement
constexpr derived_type complement() const noexcept
Return the complement of the letter.
Definition nucleotide_base.hpp:111
seqan3::nucleotide_base::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
std::array::fill
T fill(T... args)
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
nucleotide_alphabet
A concept that indicates whether an alphabet represents nucleotides.
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
transform.hpp
Provides utilities for modifying characters.
Hide me