SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
advanceable_alignment_coordinate.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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 
15 #include <seqan3/std/concepts>
16 #include <seqan3/std/iterator>
17 #include <type_traits>
18 
24 
25 namespace seqan3::detail
26 {
27 
39 enum struct advanceable_alignment_coordinate_state : uint8_t
40 {
42  none,
44  column,
46  row
47 };
48 
64 template <advanceable_alignment_coordinate_state state = advanceable_alignment_coordinate_state::none>
65 class advanceable_alignment_coordinate
66 {
67 public:
68 
74  using difference_type = std::make_signed_t<size_t>;
76 
80  constexpr advanceable_alignment_coordinate() noexcept = default;
82  constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate const &) noexcept = default;
83  constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate &&) noexcept = default;
85  constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate const &) noexcept = default;
87  constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate &&) noexcept = default;
88  ~advanceable_alignment_coordinate() noexcept = default;
89 
91  template <advanceable_alignment_coordinate_state other_state>
93  requires (other_state != state)
95  constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> const & other) :
96  first{other.first},
97  second{other.second}
98  {}
99 
101  template <advanceable_alignment_coordinate_state other_state>
103  requires (other_state != state)
105  constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> && other) :
106  first{std::move(other.first)},
107  second{std::move(other.second)}
108  {}
109 
114  constexpr advanceable_alignment_coordinate(column_index_type<size_t> const c_idx,
115  row_index_type<size_t> const r_idx) noexcept :
116  first{c_idx.get()},
117  second{r_idx.get()}
118  {}
120 
122  constexpr friend bool operator==(advanceable_alignment_coordinate const & lhs,
123  advanceable_alignment_coordinate const & rhs) noexcept
124  {
125  return std::tie(lhs.first, lhs.second) == std::tie(rhs.first, rhs.second);
126  }
127 
128  constexpr friend bool operator!=(advanceable_alignment_coordinate const & lhs,
129  advanceable_alignment_coordinate const & rhs) noexcept
130  {
131  return std::tie(lhs.first, lhs.second) != std::tie(rhs.first, rhs.second);
132  }
133 
134  constexpr friend bool operator<=(advanceable_alignment_coordinate const & lhs,
135  advanceable_alignment_coordinate const & rhs) noexcept
136  {
137  return std::tie(lhs.first, lhs.second) <= std::tie(rhs.first, rhs.second);
138  }
139 
140  constexpr friend bool operator< (advanceable_alignment_coordinate const & lhs,
141  advanceable_alignment_coordinate const & rhs) noexcept
142  {
143  return std::tie(lhs.first, lhs.second) < std::tie(rhs.first, rhs.second);
144  }
145 
146  constexpr friend bool operator>=(advanceable_alignment_coordinate const & lhs,
147  advanceable_alignment_coordinate const & rhs) noexcept
148  {
149  return std::tie(lhs.first, lhs.second) >= std::tie(rhs.first, rhs.second);
150  }
151 
152  constexpr friend bool operator> (advanceable_alignment_coordinate const & lhs,
153  advanceable_alignment_coordinate const & rhs) noexcept
154  {
155  return std::tie(lhs.first, lhs.second) > std::tie(rhs.first, rhs.second);
156  }
158 
169  constexpr advanceable_alignment_coordinate & operator++(/*pre-increment*/) noexcept
171  requires (state != advanceable_alignment_coordinate_state::none)
173  {
174  if constexpr (state == advanceable_alignment_coordinate_state::column)
175  ++this->first;
176  else
177  ++this->second;
178  return *this;
179  }
180 
184  constexpr advanceable_alignment_coordinate operator++(int /*post-increment*/) noexcept
186  requires (state != advanceable_alignment_coordinate_state::none)
188  {
189  advanceable_alignment_coordinate tmp{*this};
190  ++(*this);
191  return tmp;
192  }
193 
197  constexpr advanceable_alignment_coordinate & operator--(/*pre-decrement*/) noexcept
199  requires (state != advanceable_alignment_coordinate_state::none)
201  {
202  if constexpr (state == advanceable_alignment_coordinate_state::column)
203  --this->first;
204  else
205  --this->second;
206  return *this;
207  }
208 
212  constexpr advanceable_alignment_coordinate operator--(int /*post-decrement*/) noexcept
214  requires (state != advanceable_alignment_coordinate_state::none)
216  {
217  advanceable_alignment_coordinate tmp{*this};
218  --(*this);
219  return tmp;
220  }
221 
226  constexpr advanceable_alignment_coordinate & operator+=(difference_type const offset) noexcept
228  requires (state != advanceable_alignment_coordinate_state::none)
230  {
231  if constexpr (state == advanceable_alignment_coordinate_state::column)
232  this->first += offset;
233  else
234  this->second += offset;
235  return *this;
236  }
237 
242  constexpr advanceable_alignment_coordinate & operator-=(difference_type const offset) noexcept
244  requires (state != advanceable_alignment_coordinate_state::none)
246  {
247  if constexpr (state == advanceable_alignment_coordinate_state::column)
248  this->first -= offset;
249  else
250  this->second -= offset;
251  return *this;
252  }
253 
258  constexpr advanceable_alignment_coordinate operator+(difference_type const offset) const noexcept
260  requires (state != advanceable_alignment_coordinate_state::none)
262  {
263  advanceable_alignment_coordinate tmp{*this};
264  tmp += offset;
265  return tmp;
266  }
267 
272  constexpr advanceable_alignment_coordinate operator-(difference_type const offset) const noexcept
274  requires (state != advanceable_alignment_coordinate_state::none)
276  {
277  advanceable_alignment_coordinate tmp{*this};
278  tmp -= offset;
279  return tmp;
280  }
281 
286  constexpr difference_type operator-(advanceable_alignment_coordinate const & other) const noexcept
288  requires (state != advanceable_alignment_coordinate_state::none)
290  {
291  if constexpr (state == advanceable_alignment_coordinate_state::column)
292  return this->first - other.first;
293  else
294  return this->second - other.second;
295  }
297 
300 
304  constexpr friend advanceable_alignment_coordinate operator+(difference_type const offset,
305  advanceable_alignment_coordinate const & me) noexcept
307  requires (state != advanceable_alignment_coordinate_state::none)
309  {
310  return me + offset;
311  }
313 
315  size_t first{};
317  size_t second{};
318 };
319 
320 } // namespace seqan3::detail
321 
322 namespace seqan3
323 {
324 
335 template <typename char_t, typename coordinate_type>
337  requires detail::is_value_specialisation_of_v<std::remove_cvref_t<coordinate_type>,
338  detail::advanceable_alignment_coordinate>
340 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, coordinate_type && c)
341 {
342  s << std::tie(c.first, c.second);
343  return s;
344 }
345 
346 } // namespace seqan3
347 
348 #ifdef SEQAN3_DEPRECATED_310
349 namespace seqan3
350 {
368  : public detail::advanceable_alignment_coordinate<detail::advanceable_alignment_coordinate_state::none>
370 {
373  using base_t = detail::advanceable_alignment_coordinate<detail::advanceable_alignment_coordinate_state::none>;
375 
376 public:
377 
381  constexpr alignment_coordinate() = default;
382  constexpr alignment_coordinate(alignment_coordinate const &) = default;
383  constexpr alignment_coordinate(alignment_coordinate &&) = default;
384  constexpr alignment_coordinate & operator=(alignment_coordinate const &) = default;
386  ~alignment_coordinate() = default;
387 
390  using base_t::base_t;
391 
393  constexpr alignment_coordinate(base_t const & base) : base_t{base}
394  {}
395 
397  constexpr alignment_coordinate(base_t && base) : base_t{std::move(base)}
398  {}
401 
402  using base_t::first;
403  using base_t::second;
404 
406  SEQAN3_DOXYGEN_ONLY(size_t first;)
408  SEQAN3_DOXYGEN_ONLY(size_t second;)
409 
412  constexpr operator detail::matrix_coordinate() const
413  {
414  return detail::matrix_coordinate{detail::row_index_type{second}, detail::column_index_type{first}};
415  }
416 };
417 
418 #pragma GCC diagnostic push
419 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
421 template <typename char_t, typename coordinate_type>
422  requires std::same_as<std::remove_cvref_t<coordinate_type>, alignment_coordinate>
423 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, coordinate_type && c)
424 {
425  s << std::tie(c.first, c.second);
426  return s;
427 }
429 #pragma GCC diagnostic pop
430 
431 } // namespace seqan3
432 #endif // SEQAN3_DEPRECATED_310
Represents the begin/end of the pairwise alignment in the respective sequences.
Definition: advanceable_alignment_coordinate.hpp:370
constexpr alignment_coordinate(alignment_coordinate &&)=default
Defaulted.
~alignment_coordinate()=default
Defaulted.
constexpr alignment_coordinate & operator=(alignment_coordinate const &)=default
Defaulted.
constexpr alignment_coordinate(alignment_coordinate const &)=default
Defaulted.
constexpr alignment_coordinate()=default
Defaulted.
constexpr alignment_coordinate & operator=(alignment_coordinate &&)=default
Defaulted.
The Concepts library.
Provides seqan3::debug_stream and related types.
Provides seqan3::debug_stream and related types.
Provides type traits for working with templates.
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:101
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
@ none
No flag is set.
Definition: debug_stream_type.hpp:32
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:74
Provides C++20 additions to the <iterator> header.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
T operator!=(T... args)
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:203
Provides basic data structure for strong types.
T tie(T... args)