SeqAn3 3.4.0
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alphabet/cigar/cigar.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
9
10#pragma once
11
12#include <seqan3/std/charconv>
13
19
20// ------------------------------------------------------------------
21// cigar
22// ------------------------------------------------------------------
23
24namespace seqan3
25{
26
56class cigar : public alphabet_tuple_base<cigar, uint32_t, exposition_only::cigar_operation>
57{
58private:
60 using base_t = alphabet_tuple_base<cigar, uint32_t, exposition_only::cigar_operation>;
61
63 friend base_t;
65
66public:
94
98 constexpr cigar() noexcept = default;
99 constexpr cigar(cigar const &) noexcept = default;
100 constexpr cigar(cigar &&) noexcept = default;
101 constexpr cigar & operator=(cigar const &) noexcept = default;
102 constexpr cigar & operator=(cigar &&) noexcept = default;
103 ~cigar() noexcept = default;
104
105 // Inherit constructors from base
106 using base_t::base_t;
107
116 SEQAN3_DOXYGEN_ONLY((constexpr cigar(component_type const alph) noexcept {}))
117
126 SEQAN3_DOXYGEN_ONLY((constexpr cigar & operator=(component_type const alph) noexcept {}))
127
128 // Inherit operators from base
129 using base_t::operator=;
131
140 {
141 small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar operation
142 ret.resize(11);
143
144 auto [ptr, errc] = std::to_chars(ret.data(), ret.data() + 10, get<0>(*this));
145
146 *ptr = seqan3::to_char(get<1>(*this));
147 (void)errc;
148
149 ret.resize(ptr - ret.data() + 1);
150 return ret;
151 }
152
153
167 cigar & assign_string(std::string_view const input) noexcept
168 {
169 uint32_t num{};
170 auto [ptr, errc] = std::from_chars(input.data(), input.data() + input.size(), num);
171
172 if ((errc != std::errc{}) || (!char_is_valid_for<operation>(*ptr)))
173 {
174 get<0>(*this) = 0;
175 assign_char_to('P', get<1>(*this));
176 }
177 else
178 {
179 get<0>(*this) = num;
180 assign_char_to(*ptr, get<1>(*this));
181 }
182
183 return *this;
184 }
185
186
196 SEQAN3_DOXYGEN_ONLY((friend template <size_t index> constexpr auto get(cigar & l) noexcept {}))
197
206 SEQAN3_DOXYGEN_ONLY((friend template <typename type> constexpr auto get(cigar & l) noexcept {}))
208};
209
216template <>
217struct cigar_printer<cigar>
218{
224 template <typename stream_t>
225 constexpr void operator()(stream_t & stream, cigar const arg) const noexcept
226 {
227 stream << arg.to_string();
228 }
229};
230
231inline namespace literals
232{
234// ------------------------------------------------------------------
235// literals
236// ------------------------------------------------------------------
237
245
246
251constexpr cigar::operation operator""_cigar_operation(char const c) noexcept
252{
253 return cigar::operation{}.assign_char(c);
254}
256
257} // namespace literals
258
259} // namespace seqan3
Provides seqan3::alphabet_tuple_base.
The <charconv> header from C++17's standard library.
Introduces the seqan3::exposition_only::cigar_operation alphabet.
friend constexpr auto get(cigar &l) noexcept
Tuple-like access to the contained components.
Definition alphabet/cigar/cigar.hpp:196
cigar & assign_string(std::string_view const input) noexcept
Assign from a std::string_view.
Definition alphabet/cigar/cigar.hpp:167
constexpr cigar() noexcept=default
Defaulted.
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
small_string< 11 > to_string() const noexcept
Return the string representation.
Definition alphabet/cigar/cigar.hpp:139
The actual implementation of seqan3::cigar::operation for documentation purposes only.
Definition cigar_operation.hpp:45
Implements a small string that can be used for compile time computations.
Definition small_string.hpp:43
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition small_string.hpp:232
constexpr value_type * data() noexcept
Direct access to the underlying array.
Definition small_vector.hpp:525
Provides seqan3::debug_stream and related types.
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:381
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
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
Definition record.hpp:87
The SeqAn namespace for literals.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
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
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
A constexpr string implementation to manipulate string literals at compile time.
Provides alphabet adaptations for standard uint types.
Hide me