Loading...
Searching...
No Matches
alphabet/cigar/cigar.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/std/charconv>
#include <seqan3/alphabet/adaptation/uint.hpp>
#include <seqan3/alphabet/cigar/exposition_only/cigar_operation.hpp>
#include <seqan3/alphabet/composite/alphabet_tuple_base.hpp>
#include <seqan3/core/debug_stream/debug_stream_type.hpp>
#include <seqan3/utility/container/small_string.hpp>
// ------------------------------------------------------------------
// cigar
// ------------------------------------------------------------------
namespace seqan3
{
class cigar : public alphabet_tuple_base<cigar, uint32_t, exposition_only::cigar_operation>
{
private:
using base_t = alphabet_tuple_base<cigar, uint32_t, exposition_only::cigar_operation>;
friend base_t;
public:
using operation = exposition_only::cigar_operation;
constexpr cigar() noexcept = default;
constexpr cigar(cigar const &) noexcept = default;
constexpr cigar(cigar &&) noexcept = default;
constexpr cigar & operator=(cigar const &) noexcept = default;
constexpr cigar & operator=(cigar &&) noexcept = default;
~cigar() noexcept = default;
// Inherit constructors from base
using base_t::base_t;
SEQAN3_DOXYGEN_ONLY((constexpr cigar(component_type const alph) noexcept {}))
SEQAN3_DOXYGEN_ONLY((constexpr cigar & operator=(component_type const alph) noexcept {}))
// Inherit operators from base
using base_t::operator=;
small_string<11> to_string() const noexcept
{
small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar operation
ret.resize(11);
auto [ptr, errc] = std::to_chars(ret.data(), ret.data() + 10, get<0>(*this));
*ptr = seqan3::to_char(get<1>(*this));
(void)errc;
ret.resize(ptr - ret.data() + 1);
return ret;
}
cigar & assign_string(std::string_view const input) noexcept
{
uint32_t num{};
auto [ptr, errc] = std::from_chars(input.data(), input.data() + input.size(), num);
if ((errc != std::errc{}) || (!char_is_valid_for<operation>(*ptr)))
{
get<0>(*this) = 0;
assign_char_to('P', get<1>(*this));
}
else
{
get<0>(*this) = num;
assign_char_to(*ptr, get<1>(*this));
}
return *this;
}
SEQAN3_DOXYGEN_ONLY((friend template <size_t index> constexpr auto get(cigar & l) noexcept {}))
SEQAN3_DOXYGEN_ONLY((friend template <typename type> constexpr auto get(cigar & l) noexcept {}))
};
template <>
struct cigar_printer<cigar>
{
template <typename stream_t>
constexpr void operator()(stream_t & stream, cigar const arg) const noexcept
{
stream << arg.to_string();
}
};
inline namespace literals
{
// ------------------------------------------------------------------
// literals
// ------------------------------------------------------------------
constexpr cigar::operation operator""_cigar_operation(char const c) noexcept
{
return cigar::operation{}.assign_char(c);
}
} // namespace literals
} // namespace seqan3
alphabet_tuple_base.hpp
Provides seqan3::alphabet_tuple_base.
std::string_view
charconv
The <charconv> header from C++17's standard library.
cigar_operation.hpp
Introduces the seqan3::exposition_only::cigar_operation alphabet.
seqan3::cigar::get
friend constexpr auto get(cigar &l) noexcept
Tuple-like access to the contained components.
Definition alphabet/cigar/cigar.hpp:196
seqan3::cigar::assign_string
cigar & assign_string(std::string_view const input) noexcept
Assign from a std::string_view.
Definition alphabet/cigar/cigar.hpp:167
seqan3::cigar::cigar
constexpr cigar() noexcept=default
Defaulted.
seqan3::cigar::operation
exposition_only::cigar_operation operation
The (extended) cigar operation alphabet of M,D,I,H,N,P,S,X,=.
Definition alphabet/cigar/cigar.hpp:93
seqan3::cigar::to_string
small_string< 11 > to_string() const noexcept
Return the string representation.
Definition alphabet/cigar/cigar.hpp:139
seqan3::exposition_only::cigar_operation
The actual implementation of seqan3::cigar::operation for documentation purposes only.
Definition cigar_operation.hpp:45
seqan3::small_string
Implements a small string that can be used for compile time computations.
Definition small_string.hpp:43
seqan3::small_string::resize
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition small_string.hpp:232
seqan3::small_vector::data
constexpr value_type * data() noexcept
Direct access to the underlying array.
Definition small_vector.hpp:525
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
std::errc
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::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::field::cigar
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
Definition record.hpp:87
seqan3::literals
The SeqAn namespace for literals.
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std::from_chars
from_chars_result from_chars(char const *first, char const *last, floating_point_type &value, chars_format fmt=chars_format::general) noexcept
Parse a char sequence into an floating point value.
Definition charconv:252
std::to_chars
to_chars_result to_chars(char *first, char *last, floating_point_type value) noexcept
std::to_chars overload for floating point via a std::stringstream for default base = 10.
Definition charconv:187
small_string.hpp
A constexpr string implementation to manipulate string literals at compile time.
uint.hpp
Provides alphabet adaptations for standard uint types.
Hide me