Loading...
Searching...
No Matches
qualified.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/nucleotide/concept.hpp>
#include <seqan3/alphabet/quality/concept.hpp>
namespace seqan3
{
template <writable_alphabet sequence_alphabet_t, writable_quality_alphabet quality_alphabet_t>
class qualified :
public alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
sequence_alphabet_t,
quality_alphabet_t>
{
private:
using base_type = alphabet_tuple_base<qualified<sequence_alphabet_t, quality_alphabet_t>,
sequence_alphabet_t,
quality_alphabet_t>;
public:
using sequence_alphabet_type = sequence_alphabet_t;
using quality_alphabet_type = quality_alphabet_t;
using char_type = alphabet_char_t<sequence_alphabet_type>;
using phred_type = alphabet_phred_t<quality_alphabet_type>;
constexpr qualified() noexcept = default;
constexpr qualified(qualified const &) noexcept = default;
constexpr qualified(qualified &&) noexcept = default;
constexpr qualified & operator=(qualified const &) noexcept = default;
constexpr qualified & operator=(qualified &&) noexcept = default;
~qualified() noexcept = default;
// Inherit from base:
using base_type::alphabet_size;
using base_type::base_type; // non-default constructors
using base_type::to_rank;
using base_type::operator=;
SEQAN3_DOXYGEN_ONLY((constexpr qualified(component_type const alph) noexcept {}))
SEQAN3_DOXYGEN_ONLY((constexpr qualified(indirect_component_type const alph) noexcept {}))
SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(component_type const alph) noexcept {}))
SEQAN3_DOXYGEN_ONLY((constexpr qualified & operator=(indirect_component_type const alph) noexcept {}))
constexpr qualified & assign_char(char_type const c) noexcept
{
base_type::assign_rank((seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{}))
* base_type::cummulative_alph_sizes[0])
+ (base_type::template to_component_rank<1>() * base_type::cummulative_alph_sizes[1]));
// The above is noticeably faster than (no subtraction and no division):
// base_type::template assign_component_rank<0>(
// seqan3::to_rank(seqan3::assign_char_to(c, sequence_alphabet_type{})));
return *this;
}
constexpr qualified & assign_phred(phred_type const c) noexcept
{
seqan3::assign_phred_to(c, get<1>(*this));
return *this;
}
constexpr phred_type to_phred() const noexcept
{
return rank_to_phred[to_rank()];
}
constexpr char_type to_char() const noexcept
{
return rank_to_char(to_rank());
}
constexpr qualified complement() const noexcept
requires nucleotide_alphabet<sequence_alphabet_t>
{
return qualified{seqan3::complement(get<0>(*this)), get<1>(*this)};
}
static constexpr bool char_is_valid(char_type const c) noexcept
{
return char_is_valid_for<sequence_alphabet_type>(c);
}
private:
static constexpr char_type rank_to_char(typename base_type::rank_type const rank)
{
return rank_to_char_table[rank];
}
static constexpr std::array<char_type, alphabet_size> rank_to_char_table{
[]() constexpr
{
std::array<char_type, alphabet_size> ret{};
for (size_t i = 0; i < alphabet_size; ++i)
{
size_t const seq_rank =
(i / base_type::cummulative_alph_sizes[0]) % seqan3::alphabet_size<quality_alphabet_type>;
ret[i] = seqan3::to_char(seqan3::assign_rank_to(seq_rank, sequence_alphabet_type{}));
}
return ret;
}()};
static constexpr std::array<char_type, alphabet_size> rank_to_phred{
[]() constexpr
{
std::array<char_type, alphabet_size> ret{};
for (size_t i = 0; i < alphabet_size; ++i)
{
size_t qual_rank =
(i / base_type::cummulative_alph_sizes[1]) % seqan3::alphabet_size<quality_alphabet_type>;
ret[i] = seqan3::to_phred(seqan3::assign_rank_to(qual_rank, quality_alphabet_type{}));
}
return ret;
}()};
};
template <typename sequence_alphabet_type, typename quality_alphabet_type>
qualified(sequence_alphabet_type &&, quality_alphabet_type &&)
-> qualified<std::decay_t<sequence_alphabet_type>, std::decay_t<quality_alphabet_type>>;
} // namespace seqan3
concept.hpp
Provides seqan3::nucleotide_alphabet.
concept.hpp
Quality alphabet concept.
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< qualified< sequence_alphabet_t, quality_alphabet_t >, sequence_alphabet_t, quality_alphabet_t >::get
friend constexpr auto get(alphabet_tuple_base &l) noexcept
Definition alphabet_tuple_base.hpp:345
seqan3::alphabet_tuple_base< qualified< sequence_alphabet_t, quality_alphabet_t >, sequence_alphabet_t, quality_alphabet_t >::assign_rank
constexpr qualified< sequence_alphabet_t, quality_alphabet_t > & assign_rank(rank_type const c) noexcept
seqan3::qualified::char_is_valid
static constexpr bool char_is_valid(char_type const c) noexcept
Validate whether a character is valid in the sequence alphabet.
Definition qualified.hpp:183
seqan3::qualified::to_char
constexpr char_type to_char() const noexcept
Return a character. This reads the internal sequence letter.
Definition qualified.hpp:161
seqan3::qualified::to_phred
constexpr phred_type to_phred() const noexcept
Return the Phred score value. This reads the internal quality letter.
Definition qualified.hpp:152
seqan3::qualified< dna4, phred42 >::char_type
alphabet_char_t< sequence_alphabet_type > char_type
Definition qualified.hpp:82
seqan3::qualified::qualified
constexpr qualified(indirect_component_type const alph) noexcept
Construction via a value of a subtype that is assignable to one of the components.
Definition qualified.hpp:108
seqan3::qualified::complement
constexpr qualified complement() const noexcept
Return a qualified where the quality is preserved, but the sequence letter is complemented.
Definition qualified.hpp:172
seqan3::qualified< dna4, phred42 >::to_rank
constexpr rank_type to_rank() const noexcept
seqan3::qualified::assign_phred
constexpr qualified & assign_phred(phred_type const c) noexcept
Assign from a Phred score value. This modifies the internal quality letter.
Definition qualified.hpp:138
seqan3::qualified< dna4, phred42 >::alphabet_size
static constexpr detail::min_viable_uint_t< size > alphabet_size
seqan3::qualified::qualified
constexpr qualified() noexcept=default
Defaulted.
seqan3::qualified::qualified
qualified(sequence_alphabet_type &&, quality_alphabet_type &&) -> qualified< std::decay_t< sequence_alphabet_type >, std::decay_t< quality_alphabet_type > >
Type deduction guide enables usage of qualified without specifying template args.
seqan3::qualified< dna4, phred42 >::quality_alphabet_type
quality_alphabet_t quality_alphabet_type
Definition qualified.hpp:76
seqan3::qualified::assign_char
constexpr qualified & assign_char(char_type const c) noexcept
Assign from a character. This modifies the internal sequence letter.
Definition qualified.hpp:122
seqan3::qualified< dna4, phred42 >::phred_type
alphabet_phred_t< quality_alphabet_type > phred_type
Definition qualified.hpp:87
seqan3::qualified< dna4, phred42 >::sequence_alphabet_type
sequence_alphabet_t sequence_alphabet_type
Definition qualified.hpp:71
std::decay_t
seqan3::complement
constexpr auto complement
Return the complement of a nucleotide object.
Definition alphabet/nucleotide/concept.hpp:102
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_size
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition alphabet/concept.hpp:834
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::char_is_valid_for
constexpr auto char_is_valid_for
Returns whether a character is in the valid set of a seqan3::alphabet (usually implies a bijective ma...
Definition alphabet/concept.hpp:661
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_phred
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition alphabet/quality/concept.hpp:97
seqan3::assign_phred_to
constexpr auto assign_phred_to
Assign a Phred score to a quality alphabet object.
Definition alphabet/quality/concept.hpp:225
seqan3::alphabet_phred_t
decltype(seqan3::to_phred(std::declval< alphabet_type >())) alphabet_phred_t
The phred_type of the alphabet; defined as the return type of seqan3::to_phred.
Definition alphabet/quality/concept.hpp:109
Hide me