21 #include <type_traits>
80 template <std::ranges::viewable_range inner_type>
82 requires std::ranges::random_access_range<inner_type> && std::ranges::sized_range<inner_type> &&
83 (std::is_const_v<std::remove_reference_t<inner_type>> || std::ranges::view<inner_type>)
127 using size_type = std::ranges::range_size_t<inner_type>;
166 template <
typename other_range_t>
168 requires (!std::same_as<other_range_t, gap_decorator>) &&
170 std::ranges::viewable_range<other_range_t>
192 return anchors.rbegin()->second + ungapped_view.size();
194 return ungapped_view.size();
218 assert(pos <=
size());
222 if (it_set == anchors.begin())
224 anchors.emplace_hint(anchors.begin(),
anchor_gap_t{pos, count});
229 auto gap_len{it_set->second};
230 if (it_set != anchors.begin())
231 gap_len -= (*(
std::prev(it_set))).second;
233 if (it_set->first + gap_len >= pos)
236 it_set = anchors.erase(it_set);
237 anchors.insert(it_set,
gap);
243 anchors.insert(it_set,
gap);
269 throw gap_erase_failure(
"The range to be erased does not correspond to a consecutive gap.");
295 if (it == anchors.begin())
300 size_type const gap_len = gap_length(it);
303 if ((it->first + gap_len) < pos2)
305 throw gap_erase_failure{
"The range to be erased does not correspond to a consecutive gap."};
308 else if (gap_len == pos2 - pos1)
310 it = anchors.erase(it);
316 it = anchors.erase(it);
317 it = anchors.insert(it,
gap);
322 update(it, pos2 - pos1);
334 template <
typename unaligned_sequence_t>
336 requires std::assignable_from<gap_decorator &, unaligned_sequence_t>
420 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
428 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
491 return !(lhs == rhs);
500 auto lit = lhs.
begin();
501 auto rit = rhs.
begin();
503 while (lit != lhs.
end() && rit != rhs.
end() && *lit == *rit)
506 if (rit == rhs.
end())
508 else if (lit == lhs.
end())
520 auto lit = lhs.
begin();
521 auto rit = rhs.
begin();
523 while (lit != lhs.
end() && rit != rhs.
end() && *lit == *rit)
526 if (lit == lhs.
end())
528 else if (rit == rhs.
end())
540 return !(lhs <= rhs);
580 return (it == anchors.begin()) ? it->second : it->second - (*
std::prev(it)).second;
597 for (
auto it =
std::prev(anchors.end(), 1); it->first > pos;)
600 anchors.erase(*it--);
618 while (it != anchors.end())
621 it = anchors.erase(it);
622 it = anchors.insert(it,
gap);
641 template <std::ranges::viewable_range urng_t>
651 template <
std::ranges::view urng_t>
671 template <
std::ranges::viewable_range inner_type>
673 requires
std::ranges::random_access_range<inner_type> &&
std::ranges::sized_range<inner_type> &&
674 (
std::is_const_v<
std::remove_reference_t<inner_type>> ||
std::ranges::view<inner_type>)
684 int64_t ungapped_view_pos{0};
692 bool is_at_gap{
true};
697 assert(new_pos <= host->
size());
700 anchor_set_it = host->anchors.upper_bound(
anchor_gap_t{pos, host->bound_dummy});
701 ungapped_view_pos = pos;
703 if (anchor_set_it != host->anchors.begin())
708 if (prev != host->anchors.begin())
711 ungapped_view_pos -= prev->second;
712 left_gap_end = prev->first + gap_len;
715 if (ungapped_view_pos !=
static_cast<int64_t
>(host->ungapped_view.size()) &&
716 pos >= left_gap_end && (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first))
750 host(&host_), anchor_set_it{host_.anchors.begin()}
755 left_gap_end = anchor_set_it->second;
780 if (pos < left_gap_end)
783 if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
786 if (ungapped_view_pos !=
static_cast<int64_t
>(host->ungapped_view.size()))
791 left_gap_end = anchor_set_it->first + anchor_set_it->second -
792 ((anchor_set_it != host->anchors.begin()) ? (
std::prev(anchor_set_it))->second : 0);
796 if (left_gap_end == host->size())
814 this->jump(this->pos + skip);
836 if (pos < left_gap_end)
838 (anchor_set_it != host->anchors.begin()) ? --anchor_set_it : anchor_set_it;
840 if (anchor_set_it != host->anchors.begin())
843 left_gap_end = prev->first + prev->second -
844 ((prev != host->anchors.begin()) ?
std::prev(prev)->second : 0);
852 else if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
873 this->jump(this->pos - skip);
920 return lhs.pos == rhs.pos;
926 return lhs.pos != rhs.pos;
932 return lhs.pos < rhs.pos;
938 return lhs.pos > rhs.pos;
944 return lhs.pos <= rhs.pos;
950 return lhs.pos >= rhs.pos;
Adaptations of algorithms from the Ranges TS.
Includes customized exception types for the alignment module .
Core alphabet concept and free function/type trait wrappers.
A combined alphabet that can hold values of either of its alternatives.
Definition: alphabet_variant.hpp:132
The iterator type over a seqan3::gap_decorator.
Definition: gap_decorator.hpp:677
friend bool operator<=(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is less than or equal to rhs.
Definition: gap_decorator.hpp:942
reference operator*() const
Dereference operator returns a copy of the element currently pointed at.
Definition: gap_decorator.hpp:900
gap_decorator_iterator & operator--()
Decrements iterator.
Definition: gap_decorator.hpp:831
gap_decorator_iterator & operator=(gap_decorator_iterator const &)=default
Defaulted.
typename gap_decorator::difference_type difference_type
The difference type.
Definition: gap_decorator.hpp:727
gap_decorator_iterator & operator=(gap_decorator_iterator &&)=default
Defaulted.
friend gap_decorator_iterator operator+(difference_type const skip, gap_decorator_iterator const &it)
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:825
gap_decorator_iterator operator--(int)
Returns a decremented iterator copy.
Definition: gap_decorator.hpp:863
gap_decorator_iterator operator+(difference_type const skip) const
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:819
difference_type operator-(gap_decorator_iterator const lhs) const noexcept
Returns the distance between two iterators.
Definition: gap_decorator.hpp:890
gap_decorator_iterator operator++(int)
Returns an incremented iterator copy.
Definition: gap_decorator.hpp:804
gap_decorator_iterator & operator+=(difference_type const skip)
Advances iterator by skip many positions.
Definition: gap_decorator.hpp:812
gap_decorator_iterator & operator++()
Increments iterator.
Definition: gap_decorator.hpp:775
typename gap_decorator::const_reference reference
The reference type.
Definition: gap_decorator.hpp:731
gap_decorator_iterator operator-(difference_type const skip) const
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:878
friend bool operator<(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is less than rhs.
Definition: gap_decorator.hpp:930
gap_decorator_iterator(gap_decorator const &host_)
Construct from seqan3::gap_decorator and initialising to first position.
Definition: gap_decorator.hpp:749
gap_decorator_iterator(gap_decorator_iterator &&)=default
Defaulted.
friend gap_decorator_iterator operator-(difference_type const skip, gap_decorator_iterator const &it)
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:884
friend bool operator!=(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is not equal to rhs.
Definition: gap_decorator.hpp:924
gap_decorator_iterator(gap_decorator const &host_, typename gap_decorator::size_type const pos_)
Construct from seqan3::gap_decorator and explicit position.
Definition: gap_decorator.hpp:765
friend bool operator>=(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is greater than or equal to rhs.
Definition: gap_decorator.hpp:948
friend bool operator>(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is greater than rhs.
Definition: gap_decorator.hpp:936
gap_decorator_iterator(gap_decorator_iterator const &)=default
Defaulted.
~gap_decorator_iterator()=default
Defaulted.
gap_decorator_iterator & operator-=(difference_type const skip)
Advances iterator by skip many positions.
Definition: gap_decorator.hpp:871
friend bool operator==(gap_decorator_iterator const &lhs, gap_decorator_iterator const &rhs) noexcept
Checks whether *this is equal to rhs.
Definition: gap_decorator.hpp:918
value_type * pointer
The pointer type.
Definition: gap_decorator.hpp:733
typename gap_decorator::value_type value_type
The value type.
Definition: gap_decorator.hpp:729
void jump(typename gap_decorator::size_type const new_pos)
A helper function that performs the random access into the anchor set, updating all member variables.
Definition: gap_decorator.hpp:695
reference operator[](difference_type const n) const
Return underlying container value currently pointed at.
Definition: gap_decorator.hpp:906
gap_decorator_iterator()=default
Defaulted.
A gap decorator allows the annotation of sequences with gap symbols while leaving the underlying sequ...
Definition: gap_decorator.hpp:86
gap_decorator & operator=(gap_decorator &&rhs)=default
Defaulted.
reference at(size_type const i)
Return the i-th element as a reference.
Definition: gap_decorator.hpp:417
friend bool operator==(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is equal to rhs.
Definition: gap_decorator.hpp:473
typename anchor_set_type::iterator set_iterator_type
The iterator type for an anchor set.
Definition: gap_decorator.hpp:561
gap_decorator(gap_decorator &&rhs)=default
Defaulted.
const_reference at(size_type const i) const
Return the i-th element as a reference.
Definition: gap_decorator.hpp:425
std::ranges::range_difference_t< inner_type > difference_type
The difference type of the underlying sequence.
Definition: gap_decorator.hpp:133
const_iterator cend() const noexcept
Returns an iterator pointing behind the last element of the decorator.
Definition: gap_decorator.hpp:394
const_iterator end() const noexcept
Returns an iterator pointing behind the last element of the decorator.
Definition: gap_decorator.hpp:388
typename std::pair< size_t, size_t > anchor_gap_t
The gap type as a tuple storing position and accumulated gap lengths.
Definition: gap_decorator.hpp:555
void rupdate(size_type const pos, size_type const offset)
Update all anchor gaps after the indicated position by adding an offset.
Definition: gap_decorator.hpp:595
inner_type unaligned_sequence_type
The underlying ungapped range type.
Definition: gap_decorator.hpp:140
gap_decorator(other_range_t &&range)
Construct with the ungapped range type.
Definition: gap_decorator.hpp:172
reference operator[](size_type const i) const
Return the i-th element as a reference.
Definition: gap_decorator.hpp:444
friend bool operator!=(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is not equal to rhs.
Definition: gap_decorator.hpp:489
iterator erase_gap(const_iterator const it)
Erase one gap symbol at the indicated iterator postion.
Definition: gap_decorator.hpp:265
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:362
unaligned_sequence_type unaligned_seq_type
Definition: gap_decorator.hpp:143
iterator insert_gap(const_iterator const it, size_type const count=1)
Insert a gap of length count at the aligned sequence iterator position.
Definition: gap_decorator.hpp:212
~gap_decorator()=default
Defaulted.
iterator erase_gap(const_iterator const first, const_iterator const last)
Erase gap symbols at the iterator postions [first, last[.
Definition: gap_decorator.hpp:289
gap_decorator(gap_decorator const &)=default
Defaulted.
friend bool operator<=(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is less than or equal to rhs.
Definition: gap_decorator.hpp:518
size_type size() const
Returns the total length of the aligned sequence.
Definition: gap_decorator.hpp:189
size_type gap_length(set_iterator_type it) const
Helper function to compute the length of the gap indicated by the input iterator.
Definition: gap_decorator.hpp:578
reference const_reference
const_reference type equals reference type equals value type because the underlying sequence must not...
Definition: gap_decorator.hpp:121
gap_decorator & operator=(gap_decorator const &)=default
Defaulted.
void update(set_iterator_type it, size_type const offset)
Update all anchor gaps after indicated position by substracting an offset.
Definition: gap_decorator.hpp:616
gapped< std::ranges::range_value_t< inner_type > > value_type
The variant type of the alphabet type and gap symbol type (see seqan3::gapped).
Definition: gap_decorator.hpp:108
friend bool operator>(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is greater than rhs.
Definition: gap_decorator.hpp:538
friend bool operator>=(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is greater than or equal to rhs.
Definition: gap_decorator.hpp:547
gap_decorator()=default
Default constructor.
decltype(views::type_reduce(std::declval< inner_type && >())) ungapped_view_type
The type of the underlying view wrapped in seqan3::views::type_reduce.
Definition: gap_decorator.hpp:98
friend bool operator<(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is less than rhs.
Definition: gap_decorator.hpp:498
anchor_set_type anchors
Set storing the anchor gaps.
Definition: gap_decorator.hpp:631
std::ranges::range_size_t< inner_type > size_type
The size_type of the underlying sequence.
Definition: gap_decorator.hpp:127
friend void assign_unaligned(gap_decorator &dec, unaligned_sequence_t &&unaligned)
Assigns a new sequence of type seqan3::gap_decorator::unaligned_sequence_type to the decorator.
Definition: gap_decorator.hpp:338
ungapped_view_type ungapped_view
Stores a (copy of a) view to the ungapped, underlying sequence.
Definition: gap_decorator.hpp:628
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:368
Thrown in function seqan3::erase_gap, if a position does not contain a gap.
Definition: exception.hpp:24
The alphabet of a gap character '-'.
Definition: gap.hpp:39
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition: traits.hpp:168
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:150
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition: type_reduce.hpp:158
Provides the seqan3::detail::inherited_iterator_base template.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides the seqan3::detail::random_access_iterator class.
Adaptations of concepts from the standard library.
Adaptations of concepts from the Ranges TS.
Provides seqan3::views::type_reduce.