21 #include <type_traits>
77 template <std::ranges::viewable_range inner_type>
79 requires std::ranges::random_access_range<inner_type> && std::ranges::sized_range<inner_type> &&
80 (std::is_const_v<std::remove_reference_t<inner_type>> || std::ranges::view<inner_type>)
95 using ungapped_view_type = decltype(
views::type_reduce(std::declval<inner_type &&>()));
124 using size_type = std::ranges::range_size_t<inner_type>;
139 #ifdef SEQAN3_DEPRECATED_310
165 template <
typename other_range_t>
167 requires (!std::same_as<other_range_t, gap_decorator>) &&
169 std::ranges::viewable_range<other_range_t>
191 return anchors.rbegin()->second + ungapped_view.size();
193 return ungapped_view.size();
217 assert(pos <=
size());
219 set_iterator_type it_set = anchors.upper_bound(anchor_gap_t{pos, bound_dummy});
221 if (it_set == anchors.begin())
223 anchors.emplace_hint(anchors.begin(), anchor_gap_t{pos, count});
228 auto gap_len{it_set->second};
229 if (it_set != anchors.begin())
230 gap_len -= (*(
std::prev(it_set))).second;
232 if (it_set->first + gap_len >= pos)
234 anchor_gap_t
gap{it_set->first, it_set->second +
count};
235 it_set = anchors.erase(it_set);
236 anchors.insert(it_set,
gap);
240 anchor_gap_t
gap{pos, it_set->second +
count};
242 anchors.insert(it_set,
gap);
268 throw gap_erase_failure(
"The range to be erased does not correspond to a consecutive gap.");
292 set_iterator_type it = anchors.upper_bound(anchor_gap_t{pos1, bound_dummy});
294 if (it == anchors.begin())
299 size_type const gap_len = gap_length(it);
302 if ((it->first + gap_len) < pos2)
304 throw gap_erase_failure{
"The range to be erased does not correspond to a consecutive gap."};
307 else if (gap_len == pos2 - pos1)
309 it = anchors.erase(it);
314 anchor_gap_t
gap{it->first, it->second - pos2 + pos1};
315 it = anchors.erase(it);
316 it = anchors.insert(it,
gap);
321 update(it, pos2 - pos1);
333 template <
typename unaligned_sequence_t>
335 requires std::assignable_from<gap_decorator &, unaligned_sequence_t>
419 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
427 throw std::out_of_range{
"Trying to access element behind the last in gap_decorator."};
475 lhs.anchors == rhs.anchors &&
476 std::ranges::equal(lhs.ungapped_view, rhs.ungapped_view))
490 return !(lhs == rhs);
499 auto lit = lhs.
begin();
500 auto rit = rhs.
begin();
502 while (lit != lhs.
end() && rit != rhs.
end() && *lit == *rit)
505 if (rit == rhs.
end())
507 else if (lit == lhs.
end())
519 auto lit = lhs.
begin();
520 auto rit = rhs.
begin();
522 while (lit != lhs.
end() && rit != rhs.
end() && *lit == *rit)
525 if (lit == lhs.
end())
527 else if (rit == rhs.
end())
539 return !(lhs <= rhs);
560 using set_iterator_type =
typename anchor_set_type::iterator;
577 size_type gap_length(set_iterator_type it)
const
579 return (it == anchors.begin()) ? it->second : it->second - (*
std::prev(it)).second;
594 void rupdate(size_type
const pos, size_type
const offset)
596 for (
auto it =
std::prev(anchors.end(), 1); it->first > pos;)
598 anchors.emplace_hint(it, anchor_gap_t{it->first +
offset, it->second +
offset});
599 anchors.erase(*it--);
615 void update(set_iterator_type it, size_type
const offset)
617 while (it != anchors.end())
619 anchor_gap_t gap{it->first -
offset, it->second -
offset};
620 it = anchors.erase(it);
621 it = anchors.insert(it, gap);
627 ungapped_view_type ungapped_view{};
630 anchor_set_type anchors{};
640 template <std::ranges::viewable_range urng_t>
650 template <
std::ranges::view urng_t>
670 template <
std::ranges::viewable_range inner_type>
672 requires
std::ranges::random_access_range<inner_type> &&
std::ranges::sized_range<inner_type> &&
673 (
std::is_const_v<
std::remove_reference_t<inner_type>> ||
std::ranges::view<inner_type>)
683 int64_t ungapped_view_pos{0};
689 typename gap_decorator::set_iterator_type anchor_set_it{};
691 bool is_at_gap{
true};
696 assert(new_pos <= host->
size());
699 anchor_set_it = host->anchors.upper_bound(anchor_gap_t{pos, host->bound_dummy});
700 ungapped_view_pos = pos;
702 if (anchor_set_it != host->anchors.begin())
704 typename gap_decorator::set_iterator_type prev{
std::prev(anchor_set_it)};
707 if (prev != host->anchors.begin())
710 ungapped_view_pos -= prev->second;
711 left_gap_end = prev->first + gap_len;
714 if (ungapped_view_pos !=
static_cast<int64_t
>(host->ungapped_view.size()) &&
715 pos >= left_gap_end && (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first))
749 host(&host_), anchor_set_it{host_.anchors.begin()}
751 if (host_.anchors.
size() && (*host_.anchors.
begin()).first == 0)
754 left_gap_end = anchor_set_it->second;
779 if (pos < left_gap_end)
782 if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
785 if (ungapped_view_pos !=
static_cast<int64_t
>(host->ungapped_view.size()))
790 left_gap_end = anchor_set_it->first + anchor_set_it->second -
791 ((anchor_set_it != host->anchors.begin()) ? (
std::prev(anchor_set_it))->second : 0);
795 if (left_gap_end == host->size())
813 this->jump(this->pos + skip);
835 if (pos < left_gap_end)
837 (anchor_set_it != host->anchors.begin()) ? --anchor_set_it : anchor_set_it;
839 if (anchor_set_it != host->anchors.begin())
842 left_gap_end = prev->first + prev->second -
843 ((prev != host->anchors.begin()) ?
std::prev(prev)->second : 0);
851 else if (anchor_set_it == host->anchors.end() || pos < anchor_set_it->first)
872 this->jump(this->pos - skip);
919 return lhs.pos == rhs.pos;
925 return lhs.pos != rhs.pos;
931 return lhs.pos < rhs.pos;
937 return lhs.pos > rhs.pos;
943 return lhs.pos <= rhs.pos;
949 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:131
The iterator type over a seqan3::gap_decorator.
Definition: gap_decorator.hpp:676
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:941
reference operator*() const
Dereference operator returns a copy of the element currently pointed at.
Definition: gap_decorator.hpp:899
gap_decorator_iterator & operator--()
Decrements iterator.
Definition: gap_decorator.hpp:830
gap_decorator_iterator & operator=(gap_decorator_iterator const &)=default
Defaulted.
typename gap_decorator::difference_type difference_type
The difference type.
Definition: gap_decorator.hpp:726
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:824
gap_decorator_iterator operator--(int)
Returns a decremented iterator copy.
Definition: gap_decorator.hpp:862
gap_decorator_iterator operator+(difference_type const skip) const
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:818
difference_type operator-(gap_decorator_iterator const lhs) const noexcept
Returns the distance between two iterators.
Definition: gap_decorator.hpp:889
gap_decorator_iterator operator++(int)
Returns an incremented iterator copy.
Definition: gap_decorator.hpp:803
gap_decorator_iterator & operator+=(difference_type const skip)
Advances iterator by skip many positions.
Definition: gap_decorator.hpp:811
gap_decorator_iterator & operator++()
Increments iterator.
Definition: gap_decorator.hpp:774
typename gap_decorator::const_reference reference
The reference type.
Definition: gap_decorator.hpp:730
gap_decorator_iterator operator-(difference_type const skip) const
Returns an iterator copy advanced by skip many positions.
Definition: gap_decorator.hpp:877
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:929
gap_decorator_iterator(gap_decorator const &host_)
Construct from seqan3::gap_decorator and initialising to first position.
Definition: gap_decorator.hpp:748
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:883
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:923
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:764
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:947
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:935
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:870
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:917
value_type * pointer
The pointer type.
Definition: gap_decorator.hpp:732
typename gap_decorator::value_type value_type
The value type.
Definition: gap_decorator.hpp:728
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:694
reference operator[](difference_type const n) const
Return underlying container value currently pointed at.
Definition: gap_decorator.hpp:905
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:83
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:416
friend bool operator==(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is equal to rhs.
Definition: gap_decorator.hpp:472
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:424
std::ranges::range_difference_t< inner_type > difference_type
The difference type of the underlying sequence.
Definition: gap_decorator.hpp:130
const_iterator cend() const noexcept
Returns an iterator pointing behind the last element of the decorator.
Definition: gap_decorator.hpp:393
const_iterator end() const noexcept
Returns an iterator pointing behind the last element of the decorator.
Definition: gap_decorator.hpp:387
inner_type unaligned_sequence_type
The underlying ungapped range type.
Definition: gap_decorator.hpp:137
gap_decorator(other_range_t &&range)
Construct with the ungapped range type.
Definition: gap_decorator.hpp:171
reference operator[](size_type const i) const
Return the i-th element as a reference.
Definition: gap_decorator.hpp:443
friend bool operator!=(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is not equal to rhs.
Definition: gap_decorator.hpp:488
iterator erase_gap(const_iterator const it)
Erase one gap symbol at the indicated iterator postion.
Definition: gap_decorator.hpp:264
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:361
unaligned_sequence_type unaligned_seq_type
Definition: gap_decorator.hpp:141
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:211
~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:288
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:517
size_type size() const
Returns the total length of the aligned sequence.
Definition: gap_decorator.hpp:188
reference const_reference
const_reference type equals reference type equals value type because the underlying sequence must not...
Definition: gap_decorator.hpp:118
gap_decorator & operator=(gap_decorator const &)=default
Defaulted.
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:105
friend bool operator>(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is greater than rhs.
Definition: gap_decorator.hpp:537
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:546
gap_decorator()=default
Default constructor.
friend bool operator<(gap_decorator const &lhs, gap_decorator const &rhs)
Checks whether lhs is less than rhs.
Definition: gap_decorator.hpp:497
std::ranges::range_size_t< inner_type > size_type
The size_type of the underlying sequence.
Definition: gap_decorator.hpp:124
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:337
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition: gap_decorator.hpp:367
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:169
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:151
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition: type_reduce.hpp:158
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Adaptations of concepts from the Ranges TS.
Provides seqan3::views::type_reduce.