Loading...
Searching...
No Matches
masked.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/composite/alphabet_tuple_base.hpp>
#include <seqan3/alphabet/mask/mask.hpp>
#include <seqan3/utility/char_operations/predicate.hpp>
#include <seqan3/utility/char_operations/transform.hpp>
namespace seqan3
{
template <writable_alphabet sequence_alphabet_t>
requires std::regular<sequence_alphabet_t>
class masked : public alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>
{
private:
using base_t = alphabet_tuple_base<masked<sequence_alphabet_t>, sequence_alphabet_t, mask>;
public:
using sequence_alphabet_type = sequence_alphabet_t;
using char_type = alphabet_char_t<sequence_alphabet_type>;
using base_t::alphabet_size;
using typename base_t::rank_type;
constexpr masked() = default;
constexpr masked(masked const &) = default;
constexpr masked(masked &&) = default;
constexpr masked & operator=(masked const &) = default;
constexpr masked & operator=(masked &&) = default;
~masked() = default;
using base_t::base_t; // Inherit non-default constructors
// Inherit operators from base
using base_t::operator=;
constexpr masked & assign_char(char_type const c) noexcept
{
using index_t = std::make_unsigned_t<char_type>;
base_t::assign_rank(char_to_rank[static_cast<index_t>(c)]);
return *this;
}
constexpr char_type to_char() const noexcept
{
return rank_to_char[base_t::to_rank()];
}
protected:
static constexpr std::array<char_type, alphabet_size> rank_to_char{
[]() constexpr
{
std::array<char_type, alphabet_size> ret{};
for (size_t i = 0; i < alphabet_size; ++i)
{
ret[i] = (i < alphabet_size / 2)
? seqan3::to_char(seqan3::assign_rank_to(i, sequence_alphabet_type{}))
: to_lower(seqan3::to_char(seqan3::assign_rank_to(i / 2, sequence_alphabet_type{})));
}
return ret;
}()};
static constexpr std::array<rank_type, detail::size_in_values_v<char_type>> char_to_rank{
[]() constexpr
{
std::array<rank_type, detail::size_in_values_v<char_type>> ret{};
for (size_t i = 0; i < 256; ++i)
{
char_type const c = static_cast<char_type>(i);
ret[i] = is_lower(c) ? seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})) * 2
: seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{}));
}
return ret;
}()};
};
template <typename sequence_alphabet_type>
masked(sequence_alphabet_type &&, mask const &) -> masked<std::decay_t<sequence_alphabet_type>>;
} //namespace seqan3
alphabet_tuple_base.hpp
Provides seqan3::alphabet_tuple_base.
std::array
seqan3::alphabet_base::rank_type
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
seqan3::alphabet_tuple_base< masked< sequence_alphabet_t >, sequence_alphabet_t, mask >::assign_rank
constexpr masked< sequence_alphabet_t > & assign_rank(rank_type const c) noexcept
seqan3::alphabet_tuple_base< masked< sequence_alphabet_t >, sequence_alphabet_t, mask >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
seqan3::alphabet_tuple_base< masked< sequence_alphabet_t >, sequence_alphabet_t, mask >::to_rank
constexpr rank_type to_rank() const noexcept
seqan3::mask
Implementation of a masked alphabet to be used for tuple composites.
Definition mask.hpp:35
seqan3::masked::char_to_rank
static constexpr std::array< rank_type, detail::size_in_values_v< char_type > > char_to_rank
Char to rank conversion table.
Definition masked.hpp:125
seqan3::masked::char_type
alphabet_char_t< sequence_alphabet_type > char_type
Equals the char_type of sequence_alphabet_type.
Definition masked.hpp:58
seqan3::masked::operator=
constexpr masked & operator=(masked &&)=default
Defaulted.
seqan3::masked::alphabet_size
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.
seqan3::masked::rank_to_char
static constexpr std::array< char_type, alphabet_size > rank_to_char
Rank to char conversion table.
Definition masked.hpp:109
seqan3::masked::operator=
constexpr masked & operator=(masked const &)=default
Defaulted.
seqan3::masked::~masked
~masked()=default
Defaulted.
seqan3::masked::masked
constexpr masked(masked &&)=default
Defaulted.
seqan3::masked::masked
masked(sequence_alphabet_type &&, mask const &) -> masked< std::decay_t< sequence_alphabet_type > >
Type deduction guide enables usage of masked without specifying template args.
seqan3::masked::assign_char
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition masked.hpp:86
seqan3::masked::masked
constexpr masked()=default
Defaulted.
seqan3::masked::sequence_alphabet_type
sequence_alphabet_t sequence_alphabet_type
First template parameter as member type.
Definition masked.hpp:52
seqan3::masked::masked
constexpr masked(masked const &)=default
Defaulted.
seqan3::masked::to_char
constexpr char_type to_char() const noexcept
Return a character.
Definition masked.hpp:101
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::alphabet_char_t
decltype(seqan3::to_char(std::declval< alphabet_type const >())) alphabet_char_t
The char_type of the alphabet; defined as the return type of seqan3::to_char.
Definition alphabet/concept.hpp:393
seqan3::assign_rank_to
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:288
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
seqan3::is_lower
constexpr auto is_lower
Checks whether c is a lower case character.
Definition predicate.hpp:243
std::make_unsigned_t
mask.hpp
Create a mask composite which can be applied with another alphabet.
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
predicate.hpp
Provides character predicates for tokenisation.
transform.hpp
Provides utilities for modifying characters.
Hide me