BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t > Class Template Reference

Joins an arbitrary alphabet with a quality alphabet. More...

#include <bio/alphabet/quality/qualified.hpp>

+ Inheritance diagram for bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >:

Public Types

using char_type = char_t< sequence_alphabet_type >
 Equals the char_type of sequence_alphabet_type.
 
using phred_type = phred_t< quality_alphabet_type >
 Equals the phred_type of the quality_alphabet_type.
 
using quality_alphabet_type = quality_alphabet_t
 Second template parameter as member type.
 
using sequence_alphabet_type = sequence_alphabet_t
 First template parameter as member type.
 

Public Member Functions

Constructors, destructor and assignment
constexpr qualified () noexcept=default
 Defaulted.
 
constexpr qualified (qualified const &) noexcept=default
 Defaulted.
 
constexpr qualified (qualified &&) noexcept=default
 Defaulted.
 
constexpr qualifiedoperator= (qualified const &) noexcept=default
 Defaulted.
 
constexpr qualifiedoperator= (qualified &&) noexcept=default
 Defaulted.
 
 ~qualified () noexcept=default
 Defaulted.
 
constexpr qualified (component_type const alph) noexcept
 Construction via a value of one of the components.
 
constexpr qualified (indirect_component_type const alph) noexcept
 Construction via a value of a subtype that is assignable to one of the components.
 
constexpr qualifiedoperator= (component_type const alph) noexcept
 Assignment via a value of one of the components.
 
constexpr qualifiedoperator= (indirect_component_type const alph) noexcept
 Assignment via a value of a subtype that is assignable to one of the components.
 
Write functions
constexpr qualifiedassign_char (char_type const c) noexcept
 Assign from a character. This modifies the internal sequence letter.
 
constexpr qualifiedassign_phred (phred_type const c) noexcept
 Assign from a phred value. This modifies the internal quality letter.
 
Read functions
constexpr phred_type to_phred () const noexcept
 Return the phred value. This reads the internal quality letter.
 
constexpr char_type to_char () const noexcept
 Return a character. This reads the internal sequence letter.
 
constexpr qualified complement () const noexcept
 Return a qualified where the quality is preserved, but the sequence letter is complemented.
 
Read functions

All read operations are constant complexity.

constexpr operator type () const noexcept
 Implicit cast to a single letter. Works only if the type is unique in the type list.
 
Read functions
constexpr rank_type to_rank () const noexcept
 Return the letter's numeric value (rank in the alphabet).
 
Write functions
constexpr derived_type & assign_char (char_type const c) noexcept
 Assign from a character, implicitly converts invalid characters.
 
constexpr derived_type & assign_rank (rank_type const c) noexcept
 Assign from a numeric value.
 

Static Public Member Functions

static constexpr bool char_is_valid (char_type const c) noexcept
 Validate whether a character is valid in the sequence alphabet.
 

Static Public Attributes

static constexpr size_t alphabet_size = size
 The size of the alphabet, i.e. the number of different values it can take.
 

Protected Types

Member types
using rank_type = meta::detail::min_viable_uint_t< size - 1 >
 The type of the alphabet when represented as a number (e.g. via to_rank()).
 

Related Functions

(Note that these are not member functions.)

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 > >
 Type deduction guide enables usage of qualified without specifying template args.
 

Detailed Description

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
class bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >

Joins an arbitrary alphabet with a quality alphabet.

Template Parameters
sequence_alphabet_tType of the alphabet; must satisfy bio::alphabet::writable_alphabet.
quality_alphabet_tType of the quality; must satisfy bio::alphabet::writable_quality.

This composite pairs an arbitrary alphabet with a quality alphabet, where each alphabet character is stored together with its quality score in a single value. That way, you can can conveniently access the character and score information at each position of the qualified-sequence. The use case that this was designed for is a nucleotide sequence with corresponding quality scores, e.g. obtained when reading in a FASTQ file of Illumina reads. The composite also allows to store quality scores for different or extended alphabets like a qualified<char, phred42> or a qualified<gapped<dna4>, phred42> sequence. The rank values correspond to numeric values in the size of the composite, while the character values are taken from the sequence alphabet and the phred values are taken from the quality alphabet.

As with all bio::alphabet::tuple_base s you may access the individual alphabet letters in regular c++ tuple notation, i.e. get<0>(t) and objects can be brace-initialised with the individual members.

int main()
{
using namespace bio::alphabet::literals;
fmt::print("{} {} {}\n",
bio::alphabet::to_rank(get<0>(letter)),
bio::alphabet::to_rank(get<1>(letter)));
// 28 0 7
fmt::print("{} {} {}\n",
bio::alphabet::to_char(get<0>(letter)),
bio::alphabet::to_char(get<1>(letter)));
// A A (
fmt::print("{} {}\n", bio::alphabet::to_phred(letter), bio::alphabet::to_phred(get<1>(letter)));
// 7 7
// modify via structured bindings and references:
auto & [ seq_l, qual_l ] = letter;
seq_l = 'G'_dna4;
fmt::print("{}\n", bio::alphabet::to_char(letter));
// G
}
Quality type for traditional Sanger and modern Illumina Phred scores (typical range)....
Definition: phred42.hpp:45
Joins an arbitrary alphabet with a quality alphabet.
Definition: qualified.hpp:59
Provides bio::alphabet::dna4, container aliases and string literals.
Core alphabet concept and free function/type trait wrappers.
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:192
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:70
constexpr auto to_phred
The public getter function for the phred representation of a quality score.
Definition: concept.hpp:65
An inline namespace for alphabet literals. It exists to safely allow using namespace.
Definition: aa10li.hpp:183
Provides bio::alphabet::phred42 quality scores.
Provides quality alphabet composites.

This bio::alphabet::tuple_base itself fulfils both bio::alphabet::writable_alphabet and bio::alphabet::writable_quality.

Constructor & Destructor Documentation

◆ qualified() [1/2]

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
constexpr bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >::qualified ( component_type const  alph)
inlineconstexprnoexcept

Construction via a value of one of the components.

Template Parameters
component_typeMust be one uniquely contained in the type list of the composite.
Parameters
alphThe value of a component that should be assigned.

Note: Since the tuple_base is a CRTP base class, we show the working examples with one of its derived classes (bio::alphabet::qualified).

int main()
{
using namespace bio::alphabet::literals;
// creates {'C'_dna4, bio::alphabet::phred42{0}}
// creates {'A'_dna4, bio::alphabet::phred42{1}}
if (letter1 == letter2)
fmt::print("{}", "yeah\n"); // yeah
}

◆ qualified() [2/2]

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
constexpr bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >::qualified ( indirect_component_type const  alph)
inlineconstexprnoexcept

Construction via a value of a subtype that is assignable to one of the components.

Template Parameters
indirect_component_typeType that models bio::alphabet::weakly_assignable_from for one of the component types.
Parameters
alphThe value that should be assigned.

Note that the value will be assigned to the FIRST type T that fulfils assignable_from<T, indirect_component_type>, regardless if other types are also fit for assignment.

Note: Since the tuple_base is a CRTP base class, we show the working examples with one of its derived classes (bio::alphabet::qualified).

int main()
{
using namespace bio::alphabet::literals;
using namespace bio::alphabet::literals;
// The following creates {'C'_dna4, phred42{0}}
// The following also creates {'C'_dna4, bio::alphabet::phred42{0}}, since rna4 assignable to dna4
if (letter1 == letter2)
fmt::print("{}", "yeah\n"); // yeah
}
Meta-header for the nucleotide submodule; includes all headers from alphabet/nucleotide/.

Member Function Documentation

◆ assign_char()

template<typename derived_type , size_t size, typename char_t = char>
constexpr derived_type & bio::alphabet::base< derived_type, size, char_t >::assign_char ( char_type const  c)
inlineconstexprnoexceptinherited

Assign from a character, implicitly converts invalid characters.

Parameters
cThe character to be assigned.

Provides an implementation for bio::alphabet::assign_char_to, required to model bio::alphabet::alphabet.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ assign_rank()

template<typename derived_type , size_t size, typename char_t = char>
constexpr derived_type & bio::alphabet::base< derived_type, size, char_t >::assign_rank ( rank_type const  c)
inlineconstexprnoexceptinherited

Assign from a numeric value.

Parameters
cThe rank to be assigned.

Provides an implementation for bio::alphabet::assign_rank_to, required to model bio::alphabet::semialphabet.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ complement()

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
constexpr qualified bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >::complement ( ) const
inlineconstexprnoexcept

Return a qualified where the quality is preserved, but the sequence letter is complemented.

See also
bio::alphabet::complement
bio::alphabet::nucleotide::complement

◆ operator type()

constexpr bio::alphabet::tuple_base< qualified< sequence_alphabet_t, quality_alphabet_t > , component_types >::operator type ( ) const
inlineconstexprnoexceptinherited

Implicit cast to a single letter. Works only if the type is unique in the type list.

◆ operator=() [1/2]

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
constexpr qualified & bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >::operator= ( component_type const  alph)
inlineconstexprnoexcept

Assignment via a value of one of the components.

Template Parameters
component_typeOne of the component types. Must be uniquely contained in the type list of the composite.
Parameters
alphThe value of a component that should be assigned.

Note: Since the tuple_base is a CRTP base class, we show the working examples with one of its derived classes (bio::alphabet::qualified).

int main()
{
using namespace bio::alphabet::literals;
letter1 = 'C'_dna4; // yields {'C'_dna4, bio::alphabet::phred42{1}}
letter1 = bio::alphabet::phred42{2}; // yields {'C'_dna4, bio::alphabet::phred42{2}}
}

◆ operator=() [2/2]

template<writable_alphabet sequence_alphabet_t, writable_quality quality_alphabet_t>
constexpr qualified & bio::alphabet::qualified< sequence_alphabet_t, quality_alphabet_t >::operator= ( indirect_component_type const  alph)
inlineconstexprnoexcept

Assignment via a value of a subtype that is assignable to one of the components.

Template Parameters
indirect_component_typeType that models bio::alphabet::weakly_assignable_from for one of the component types.
Parameters
alphThe value of a component that should be assigned.

Note: Since the tuple_base is a CRTP base class, we show the working examples with one of its derived classes (bio::alphabet::qualified).

int main()
{
using namespace bio::alphabet::literals;
using namespace bio::alphabet::literals;
letter1 = 'C'_rna4; // yields {'C'_dna4, bio::alphabet::phred42{1}}
}

◆ to_rank()

template<typename derived_type , size_t size, typename char_t = char>
constexpr rank_type bio::alphabet::base< derived_type, size, char_t >::to_rank ( ) const
inlineconstexprnoexceptinherited

Return the letter's numeric value (rank in the alphabet).

Provides an implementation for bio::alphabet::to_rank, required to model bio::alphabet::semialphabet.

Complexity

Constant.

Exceptions

Guaranteed not to throw.


The documentation for this class was generated from the following file: