19 #include <type_traits> 78 template <std::ranges::ViewableRange inner_type>
94 class gap_decorator_iterator
102 int64_t ungapped_view_pos{0};
108 typename gap_decorator::set_iterator_type anchor_set_it{};
110 bool is_at_gap{
true};
115 assert(new_pos <= host->
size());
118 anchor_set_it = host->anchors.upper_bound(anchor_gap_t{pos, host->bound_dummy});
119 ungapped_view_pos = pos;
121 if (anchor_set_it != host->anchors.begin())
123 typename gap_decorator::set_iterator_type
prev{
std::prev(anchor_set_it)};
126 if (
prev != host->anchors.begin())
129 ungapped_view_pos -=
prev->second;
130 left_gap_end =
prev->first + gap_len;
133 if (ungapped_view_pos != static_cast<int64_t>(host->ungapped_view.size()) &&
134 pos >= left_gap_end && (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first))
162 constexpr gap_decorator_iterator() =
default;
165 constexpr gap_decorator_iterator(gap_decorator_iterator
const &) =
default;
167 constexpr gap_decorator_iterator & operator=(gap_decorator_iterator
const &) =
default;
169 constexpr gap_decorator_iterator (gap_decorator_iterator &&) =
default;
171 constexpr gap_decorator_iterator & operator=(gap_decorator_iterator &&) =
default;
173 ~gap_decorator_iterator() =
default;
176 explicit constexpr gap_decorator_iterator(
gap_decorator const & host_) noexcept :
177 host(&host_), anchor_set_it{host_.anchors.
begin()}
179 if (host_.anchors.
size() && (*host_.anchors.
begin()).first == 0)
182 left_gap_end = anchor_set_it->second;
192 constexpr gap_decorator_iterator(
gap_decorator const & host_,
203 constexpr gap_decorator_iterator & operator++() noexcept
209 if (pos < left_gap_end)
213 else if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
216 if (ungapped_view_pos != static_cast<int64_t>(host->ungapped_view.size()))
221 left_gap_end = anchor_set_it->first + anchor_set_it->second -
222 ((anchor_set_it != host->anchors.begin()) ? (
std::prev(anchor_set_it))->second : 0);
231 constexpr gap_decorator_iterator & operator--() noexcept
236 if (pos < left_gap_end)
238 (anchor_set_it != host->anchors.begin()) ? --anchor_set_it : anchor_set_it;
240 if (anchor_set_it != host->anchors.begin())
243 left_gap_end =
prev->first +
prev->second -
252 else if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
263 constexpr gap_decorator_iterator operator++(
int) noexcept
265 gap_decorator_iterator cpy{*
this};
271 constexpr gap_decorator_iterator operator--(
int) noexcept
273 gap_decorator_iterator cpy{*
this};
282 constexpr
reference operator*()
const noexcept
286 : static_cast<reference>(host->ungapped_view[ungapped_view_pos]);
295 constexpr
friend bool operator==(gap_decorator_iterator
const & lhs,
297 gap_decorator_iterator
const & rhs)
299 return lhs.pos == rhs.pos;
303 constexpr
friend bool operator!=(gap_decorator_iterator
const & lhs,
304 gap_decorator_iterator
const & rhs)
306 return lhs.pos != rhs.pos;
310 constexpr
friend bool operator<(gap_decorator_iterator
const & lhs,
311 gap_decorator_iterator
const & rhs)
313 return lhs.pos < rhs.pos;
317 constexpr
friend bool operator>(gap_decorator_iterator
const & lhs,
318 gap_decorator_iterator
const & rhs)
320 return lhs.pos > rhs.pos;
324 constexpr
friend bool operator<=(gap_decorator_iterator
const & lhs,
325 gap_decorator_iterator
const & rhs)
327 return lhs.pos <= rhs.pos;
331 constexpr
friend bool operator>=(gap_decorator_iterator
const & lhs,
332 gap_decorator_iterator
const & rhs)
334 return lhs.pos >= rhs.pos;
382 template <
typename other_range_t>
406 return anchors.rbegin()->second + ungapped_view.size();
408 return ungapped_view.size();
426 assert(ungapped_view.size());
432 assert(pos <=
size());
434 set_iterator_type it_set = anchors.upper_bound(anchor_gap_t{pos, bound_dummy});
436 if (it_set == anchors.begin())
438 anchors.emplace_hint(anchors.begin(), anchor_gap_t{pos, count});
443 auto gap_len{it_set->second};
444 if (it_set != anchors.begin())
445 gap_len -= (*(
std::prev(it_set))).second;
447 if (it_set->first + gap_len >= pos)
449 anchor_gap_t
gap{it_set->first, it_set->second + count};
450 it_set = anchors.erase(it_set);
451 anchors.insert(it_set,
gap);
455 anchor_gap_t
gap{pos, it_set->second + count};
457 anchors.insert(it_set,
gap);
479 assert(ungapped_view.size());
483 throw gap_erase_failure(
"The range to be erased does not correspond to a consecutive gap.");
504 assert(ungapped_view.size());
508 set_iterator_type it = anchors.upper_bound(anchor_gap_t{pos1, bound_dummy});
510 if (it == anchors.begin())
515 size_type const gap_len = gap_length(it);
518 if ((it->first + gap_len) < pos2)
520 throw gap_erase_failure{
"The range to be erased does not correspond to a consecutive gap."};
523 else if (gap_len == pos2 - pos1)
525 it = anchors.erase(it);
530 anchor_gap_t
gap{it->first, it->second - pos2 + pos1};
531 it = anchors.erase(it);
532 it = anchors.insert(it,
gap);
537 update(it, pos2 - pos1);
546 template <
typename unaligned_seq_t>
626 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
634 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
677 if (lhs.size() == rhs.size() &&
678 lhs.anchors == rhs.anchors &&
690 return !(lhs == rhs);
696 auto lit = lhs.begin();
697 auto rit = rhs.begin();
699 while (lit != lhs.end() && rit != rhs.end() && *lit == *rit)
702 if (rit == rhs.end())
704 else if (lit == lhs.end())
713 auto lit = lhs.begin();
714 auto rit = rhs.begin();
716 while (lit != lhs.end() && rit != rhs.end() && *lit == *rit)
719 if (lit == lhs.end())
721 else if (rit == rhs.end())
730 return !(lhs <= rhs);
748 using set_iterator_type =
typename anchor_set_type::iterator;
765 constexpr size_type gap_length(set_iterator_type it)
const noexcept
767 return (it == anchors.begin()) ? it->second : it->second - (*
std::prev(it)).second;
782 void rupdate(size_type
const pos, size_type
const offset)
784 for (
auto it =
std::prev(anchors.end(), 1); it->first > pos;)
786 anchors.emplace_hint(it, anchor_gap_t{it->first + offset, it->second + offset});
787 anchors.erase(*it--);
803 void update(set_iterator_type it, size_type
const offset)
805 while (it != anchors.end())
807 anchor_gap_t gap{it->first - offset, it->second - offset};
808 it = anchors.erase(it);
809 it = anchors.insert(it, gap);
815 decltype(
view::all(std::declval<inner_type &&>())) ungapped_view{};
818 anchor_set_type anchors{};
824 template <std::ranges::ViewableRange urng_t>
829 gap_decorator(urng_t && range) -> gap_decorator<std::remove_reference_t<urng_t>
const &>;
832 template <std::ranges::View urng_t>
842 template <
typename type>
843 constexpr
int enable_view<seqan3::gap_decorator<type>> = 0;
845 template <
typename type>
846 constexpr
int enable_view<seqan3::gap_decorator<type>
const> = 0;
::ranges::equal equal
Alias for ranges::equal. Determines if two sets of elements are the same.
Definition: algorithm:54
A combined alphabet that can hold values of either of its alternatives.
Definition: alphabet_variant.hpp:205
Specifies the requirements of a Range type that is either a std::ranges::View or an lvalue-reference...
::ranges::prev prev
Alias for ranges::prev. Returns the nth predecessor of the given iterator.
Definition: iterator:326
The alphabet of a gap character '-'.
Definition: gap.hpp:36
Specifies requirements of a Range type for which begin returns a type that models std::RandomAccessIt...
difference_type_t< inner_type > difference_type
The difference type of the underlying sequence.
Definition: gap_decorator.hpp:353
size_type size() const noexcept
Returns the total length of the aligned sequence.
Definition: gap_decorator.hpp:403
friend bool operator!=(gap_decorator const &lhs, gap_decorator const &rhs) noexcept
Checks whether lhs is not equal to rhs.
Definition: gap_decorator.hpp:688
constexpr auto all
A view adaptor that behaves like std::view:all, but type erases contiguous ranges.
Definition: view_all.hpp:160
Provides the seqan3::detail::random_access_iterator class.
reference at(size_type const i)
Return the i-th element as a reference.
Definition: gap_decorator.hpp:623
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
typename difference_type< t >::type difference_type_t
Shortcut for seqan3::difference_type (TransformationTrait shortcut).
Definition: pre.hpp:166
friend void assign_unaligned(gap_decorator &dec, unaligned_seq_t &&unaligned)
Assigns a new sequence of type seqan3::gap_decorator::unaligned_seq_type to the decorator.
Definition: gap_decorator.hpp:550
const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the decorator.
Definition: gap_decorator.hpp:602
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:578
iterator insert_gap(iterator const it, size_type const count=1)
Insert a gap of length count at the aligned sequence iterator position.
Definition: gap_decorator.hpp:424
friend bool operator<(gap_decorator const &lhs, gap_decorator const &rhs) noexcept
Checks whether lhs is less than rhs.
Definition: gap_decorator.hpp:694
size_type_t< inner_type > size_type
The size_type of the underlying sequence.
Definition: gap_decorator.hpp:351
reference const_reference
const_reference type equals reference type equals value type because the underlying sequence must not...
Definition: gap_decorator.hpp:349
Adaptations of concepts from the Ranges TS.
iterator end() const noexcept
Returns an iterator to the element following the last element of the decorator.
Definition: gap_decorator.hpp:596
friend bool operator>(gap_decorator const &lhs, gap_decorator const &rhs) noexcept
Checks whether lhs is greater than rhs.
Definition: gap_decorator.hpp:728
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
Provides seqan3::view::all.
iterator erase_gap(iterator const it)
Erase one gap symbol at the indicated iterator postion.
Definition: gap_decorator.hpp:477
Specifies the requirements of a Range type that has constant time copy, move and assignment operators...
friend bool operator<=(gap_decorator const &lhs, gap_decorator const &rhs) noexcept
Checks whether lhs is less than or equal to rhs.
Definition: gap_decorator.hpp:711
inner_type unaligned_seq_type
The underlying ungapped range type.
Definition: gap_decorator.hpp:362
Thrown in function seqan3::erase_gap, if a position does not contain a gap.
Definition: exception.hpp:23
typename size_type< t >::type size_type_t
Shortcut for seqan3::size_type (TransformationTrait shortcut).
Definition: pre.hpp:195
friend bool operator>=(gap_decorator const &lhs, gap_decorator const &rhs) noexcept
Checks whether lhs is greater than or equal to rhs.
Definition: gap_decorator.hpp:734
constexpr reference operator[](size_type const i) const noexcept
Return the i-th element as a reference.
Definition: gap_decorator.hpp:649
Definition: aligned_sequence_concept.hpp:35
iterator erase_gap(iterator const first, iterator const last)
Erase gap symbols at the iterator postions [first, last[.
Definition: gap_decorator.hpp:502
The std::Constructible concept specifies that a variable of type T can be initialized with the given ...
aligned_seq_t::iterator erase_gap(aligned_seq_t &aligned_seq, typename aligned_seq_t::const_iterator pos_it)
An implementation of seqan3::AlignedSequence::erase_gap for sequence containers.
Definition: aligned_sequence_concept.hpp:278
Adaptations of algorithms from the Ranges TS.
Core alphabet concept and free function/type trait wrappers.
Includes customized exception types for the alignment module .
gap_decorator_iterator iterator
The iterator type of this container (a bidirectional iterator).
Definition: gap_decorator.hpp:355
const_reference at(size_type const i) const
Return the i-th element as a reference.
Definition: gap_decorator.hpp:631
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
Adaptations of concepts from the standard library.
iterator const_iterator
The const_iterator equals the iterator type. Since no references are ever returned and thus the under...
Definition: gap_decorator.hpp:358
gapped< value_type_t< inner_type > > value_type
The variant type of the alphabet type and gap symbol type (see seqan3::gapped).
Definition: gap_decorator.hpp:344
iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:572
gap_decorator(urng_t &&range) -> gap_decorator< std::remove_reference_t< urng_t > const &>
Ranges (not views!) always deduce to const & range_type since they are access-only anyway...
A gap decorator allows the annotation of sequences with gap symbols while leaving the underlying sequ...
Definition: gap_decorator.hpp:83
gap_decorator(other_range_t &&range)
Construct with the ungapped range type.
Definition: gap_decorator.hpp:388