BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
bio::alphabet::cigar Class Reference

The cigar semialphabet pairs a counter with a bio::alphabet::cigar_op letter. More...

#include <bio/alphabet/cigar/cigar.hpp>

+ Inheritance diagram for bio::alphabet::cigar:

Public Member Functions

Constructors, destructor and assignment
constexpr cigar () noexcept=default
 Defaulted.
 
constexpr cigar (cigar const &) noexcept=default
 Defaulted.
 
constexpr cigar (cigar &&) noexcept=default
 Defaulted.
 
constexpr cigaroperator= (cigar const &) noexcept=default
 Defaulted.
 
constexpr cigaroperator= (cigar &&) noexcept=default
 Defaulted.
 
 ~cigar () noexcept=default
 Defaulted.
 
constexpr cigar (uint32_t const count, cigar_op op) noexcept
 Construct from component types.
 
constexpr cigar (uint32_t const count) noexcept
 Construct from one component.
 
constexpr cigar (cigar_op const op) noexcept
 Construct from one component.
 
constexpr cigaroperator= (uint32_t const count) noexcept
 Assign from one component.
 
constexpr cigaroperator= (cigar_op const op) noexcept
 Assign from one component.
 
Read functions
constexpr uint32_t to_rank () const noexcept
 Return the letter's numeric value (rank in the alphabet).
 
constexpr operator uint32_t () const
 Convert to number-component.
 
constexpr operator cigar_op () const
 Convert to bio::alphabet::cigar_op component.
 
std::string_view to_string (std::span< char > buffer) const noexcept
 Convert to string representation.
 
ranges::small_string< 10 > to_string () const noexcept
 Convert to string representation.
 
Write functions
constexpr cigarassign_rank (uint32_t const r) noexcept
 Assign from a numeric value.
 
cigarassign_string (std::string_view const s)
 Assign from the string representation.
 

Friends

Get functions
template<meta::one_of< uint32_t, cigar_op > type>
constexpr type get (cigar const &l) noexcept
 Get one of the two components from the cigar element (by type).
 
template<meta::one_of< uint32_t, cigar_op > type>
constexpr auto get (cigar &l) noexcept
 Get one of the two components from the cigar element (by type).
 
template<size_t index>
requires (index == 0 || index == 1)
constexpr auto get (cigar const &l) noexcept
 Get one of the two components from the cigar element (by index).
 
template<size_t index>
requires (index == 0 || index == 1)
constexpr auto get (cigar &l) noexcept
 Get one of the two components from the cigar element (by index).
 

Detailed Description

The cigar semialphabet pairs a counter with a bio::alphabet::cigar_op letter.

This semialphabet represents a unit in a CIGAR string, typically found in the SAM and BAM formats. It consists of two components, representing a number and symbol. These components are implemented as uint32_t and bio::alphabet::cigar_op, however, only values [0, 2^28) are valid for the number component.

It has a "visual representation", but since this is a string and not a char, the type only models bio::alphabet::writable_semialphabet and not bio::alphabet::writable_alphabet. Members for reading/writing the string are provided.

To avoid confusion between string and char literal, this alphabet has no user defined literal operators. Always assign from a pair of uint32_t and bio::alphabet::cigar_op.

ABI

Objects of this type always occupy exactly 32bits of memory.

On little-endian CPU architectures (all platforms officially supported by BioC++), objects of this type are guaranteed to have the same binary representation as CIGAR elements in BAM files.

Example

using namespace bio::alphabet::literals;
int main()
{
bio::alphabet::cigar c{13, 'M'_cigar_op};
fmt::print("{}\n", c); // "13M"
c.assign_string("14X");
fmt::print("{}\n", c); // "14X"
}
Provides the bio::alphabet::cigar alphabet.
The cigar semialphabet pairs a counter with a bio::alphabet::cigar_op letter.
Definition: cigar.hpp:70
Core alphabet concept and free function/type trait wrappers.
An inline namespace for alphabet literals. It exists to safely allow using namespace.
Definition: aa10li.hpp:183

Member Function Documentation

◆ assign_rank()

constexpr cigar & bio::alphabet::cigar::assign_rank ( uint32_t const  r)
inlineconstexprnoexcept

Assign from a numeric value.

Parameters
rThe rank to be assigned.

This overload overrides the base class's function to ensure correct binary layout.

Complexity

Constant.

Exceptions

Guaranteed not to throw.

◆ assign_string()

cigar & bio::alphabet::cigar::assign_string ( std::string_view const  s)
inline

Assign from the string representation.

Parameters
sThe string to assign from.
Exceptions
std::invalid_argumentIf the string does not begin with an integer.
bio::alphabet::invalid_char_assignmentIf the string does not end on a valid character for bio::alphabet::cigar_op.

◆ to_rank()

constexpr uint32_t bio::alphabet::cigar::to_rank ( ) const
inlineconstexprnoexcept

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

This overload overrides the base class's function to ensure correct binary layout.

Complexity

Constant.

In contrast to most alphabets, this function has more overhead than just returning the stored value.

Exceptions

Guaranteed not to throw.

◆ to_string()

std::string_view bio::alphabet::cigar::to_string ( std::span< char >  buffer) const
inlinenoexcept

Convert to string representation.

Parameters
[in,out]bufferThe place the string will be created in.
Returns
A string_view into the buffer with the string-representation.

This overload takes a character buffer that the string will be created in. The buffer is required to be large enough to hold the string representation; it is recommended to always pass a buffer of at least 10 characters! This is the maximum width of the string.

A string_view into the buffer is returned. This is the only way to know the size of the "string", so you should not discard the return-result. No 0-terminator is written into the buffer.

Friends And Related Function Documentation

◆ get [1/4]

template<meta::one_of< uint32_t, cigar_op > type>
constexpr auto get ( cigar l)
friend

Get one of the two components from the cigar element (by type).

Template Parameters
typeReturn the element of specified type; eith uint32_t or bio::alphabet::cigar_op.
Returns
A proxy to the contained element that models the same alphabet concepts and supports assignment.

Example

int main()
{
using namespace bio::alphabet::literals;
bio::alphabet::cigar letter{10, 'M'_cigar_op};
uint32_t size{get<uint32_t>(letter)}; // Note this is equivalent to get<0>(letter)
bio::alphabet::cigar_op cigar_char{get<bio::alphabet::cigar_op>(letter)}; // Note this is equivalent to get<1>(letter)
fmt::print("Size is {}\n", size);
fmt::print("Cigar char is {}\n", cigar_char);
}
Introduces the cigar_op alphabet.
The cigar operation alphabet..
Definition: cigar_op.hpp:59
constexpr auto size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:517

◆ get [2/4]

template<size_t index>
requires (index == 0 || index == 1)
constexpr auto get ( cigar l)
friend

Get one of the two components from the cigar element (by index).

Template Parameters
indexReturn the element of specified index; either 0 or 1.
Returns
A proxy to the contained element that models the same alphabet concepts and supports assignment.

Example

int main()
{
using namespace bio::alphabet::literals;
bio::alphabet::cigar letter{10, 'M'_cigar_op};
uint32_t size{get<0>(letter)}; // Note this is equivalent to get<uint32_t>(letter)
bio::alphabet::cigar_op cigar_char{get<1>(letter)}; // Note this is equivalent to get<bio::alphabet::cigar_op>(letter)
fmt::print("Size is {}\n", size);
fmt::print("Cigar char is {}\n", cigar_char);
}

◆ get [3/4]

template<meta::one_of< uint32_t, cigar_op > type>
constexpr type get ( cigar const &  l)
friend

Get one of the two components from the cigar element (by type).

Template Parameters
typeReturn the element of specified type; eith uint32_t or bio::alphabet::cigar_op.
Returns
A object of the requested type.

Example

int main()
{
using namespace bio::alphabet::literals;
bio::alphabet::cigar letter{10, 'M'_cigar_op};
uint32_t size{get<uint32_t>(letter)}; // Note this is equivalent to get<0>(letter)
bio::alphabet::cigar_op cigar_char{get<bio::alphabet::cigar_op>(letter)}; // Note this is equivalent to get<1>(letter)
fmt::print("Size is {}\n", size);
fmt::print("Cigar char is {}\n", cigar_char);
}

◆ get [4/4]

template<size_t index>
requires (index == 0 || index == 1)
constexpr auto get ( cigar const &  l)
friend

Get one of the two components from the cigar element (by index).

Template Parameters
indexReturn the element of specified index; either 0 or 1.
Returns
A object of the requested type.

Example

int main()
{
using namespace bio::alphabet::literals;
bio::alphabet::cigar letter{10, 'M'_cigar_op};
uint32_t size{get<0>(letter)}; // Note this is equivalent to get<uint32_t>(letter)
bio::alphabet::cigar_op cigar_char{get<1>(letter)}; // Note this is equivalent to get<bio::alphabet::cigar_op>(letter)
fmt::print("Size is {}\n", size);
fmt::print("Cigar char is {}\n", cigar_char);
}

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