SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
cigar.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
18 #include <seqan3/std/charconv>
19 
20 // ------------------------------------------------------------------
21 // cigar
22 // ------------------------------------------------------------------
23 
24 namespace seqan3
25 {
26 
51 class cigar : public alphabet_tuple_base<cigar, uint32_t, cigar_op>
52 {
53 private:
56 
58  friend base_t;
60 
61 public:
65  constexpr cigar() noexcept = default;
66  constexpr cigar(cigar const &) noexcept = default;
67  constexpr cigar(cigar &&) noexcept = default;
68  constexpr cigar & operator=(cigar const &) noexcept = default;
69  constexpr cigar & operator=(cigar &&) noexcept = default;
70  ~cigar() noexcept = default;
71 
72  // Inherit constructors from base
73  using base_t::base_t;
74 
76  SEQAN3_DOXYGEN_ONLY(( constexpr cigar(component_type const alph) noexcept {} ))
78  SEQAN3_DOXYGEN_ONLY(( constexpr cigar(indirect_component_type const alph) noexcept {} ))
80  SEQAN3_DOXYGEN_ONLY(( constexpr cigar & operator=(component_type const alph) noexcept {} ))
82  SEQAN3_DOXYGEN_ONLY(( constexpr cigar & operator=(indirect_component_type const alph) noexcept {} ))
84 
85  // Inherit operators from base
86  using base_t::operator=;
87  using base_t::operator==;
88  using base_t::operator!=;
89  using base_t::operator>=;
90  using base_t::operator<=;
91  using base_t::operator<;
92  using base_t::operator>;
93 
97  small_string<11> to_char() const noexcept
99  {
100  small_string<11> ret{}; // maximum number of digits for uint32_t + 1 char for the cigar_op
101  ret.resize(11);
102 
103  auto [ ptr, errc ] = std::to_chars(ret.data(), ret.data() + 10, get<0>(*this));
104 
105  *ptr = seqan3::to_char(get<1>(*this));
106  (void)errc;
107 
108  ret.resize(ptr - ret.data() + 1);
109  return ret;
110  }
112 
116  cigar & assign_char(small_string<11> const s) noexcept
118  {
119  uint32_t num{};
120  auto [ ptr, errc ] = std::from_chars(s.data(), s.data() + 10, num);
121 
122  if ((errc != std::errc{}) || (!char_is_valid_for<cigar_op>(*ptr)) || (*(ptr + 1) != 0))
123  {
124  get<0>(*this) = 0;
125  assign_char_to('P', get<1>(*this));
126  }
127  else
128  {
129  get<0>(*this) = num;
130  assign_char_to(*ptr, get<1>(*this));
131  }
132 
133  return *this;
134  }
136 };
137 
140 {
141  s << to_char(c);
142  return s;
143 }
144 
145 } // namespace seqan3
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_string.hpp:216
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:285
The main SeqAn3 namespace.
Provides std::from_chars and std::to_chars if not defined in the stl <charconv> header.
Implements a small string that can be used for compile time computations.
Definition: small_string.hpp:43
cigar & assign_char(small_string< 11 > const s) noexcept
Assign from the character representation.
Definition: cigar.hpp:117
debug_stream_type & operator<<(debug_stream_type &stream, tuple_t const &alignment)
Streaming operator for alignments, which are represented as tuples of aligned sequences.
Definition: aligned_sequence_concept.hpp:518
The CRTP base for a combined alphabet that contains multiple values of different alphabets at the sam...
Definition: alphabet_tuple_base.hpp:188
constexpr cigar() noexcept=default
Defaulted.
~cigar() noexcept=default
Defaulted.
constexpr cigar(component_type const alph) noexcept
Construction via a value of one of the components.
Definition: cigar.hpp:76
Introduces the cigar_op alphabet.
The cigar alphabet pairs a counter with a seqan3::cigar_op letter.
Definition: cigar.hpp:51
T to_chars(T... args)
constexpr cigar & operator=(cigar const &) noexcept=default
Defaulted.
A CRTP-base that makes defining a custom alphabet easier.
Definition: alphabet_base.hpp:52
Provides seqan3::alphabet_tuple_base.
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition: concept.hpp:395
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream.hpp:78
T from_chars(T... args)
small_string< 11 > to_char() const noexcept
Return the character representation.
Definition: cigar.hpp:98
Provides seqan3::debug_stream and related types.