SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
|
Views are "lazy range combinators" that offer modified views onto other ranges. More...
Classes | |
class | seqan3::views::deep< underlying_adaptor_t > |
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view. More... | |
Typedefs | |
using | seqan3::views::chunk = seqan::stl::views::chunk |
A view adaptor that divides a range into chunks.
| |
using | seqan3::views::join_with = seqan::stl::views::join_with |
A view adaptor that represents view consisting of the sequence obtained from flattening a view of ranges, with every element of the delimiter inserted in between elements of the view. The delimiter can be a single element or a view of elements.
| |
using | seqan3::views::zip = seqan::stl::views::zip |
A view adaptor that takes several views and returns tuple-like values from every i-th element of each view.
| |
Variables | |
template<typename out_t > | |
constexpr auto | seqan3::views::convert |
A view that converts each element in the input range (implicitly or via static_cast ). | |
template<auto index> | |
constexpr auto | seqan3::views::elements |
A view calling get on each element in a range. | |
constexpr auto | seqan3::views::interleave |
A view that interleaves a given range into another range at regular intervals. | |
constexpr detail::repeat_fn | seqan3::views::repeat |
A view factory that repeats a given value infinitely. | |
constexpr auto | seqan3::views::repeat_n |
A view factory that repeats a given value n times. | |
constexpr auto | seqan3::views::slice |
A view adaptor that returns a half-open interval on the underlying range. | |
Views are "lazy range combinators" that offer modified views onto other ranges.
SeqAn makes heavy use of views as defined in the Ranges Technical Specification. From the original documentation: "A view is a lightweight wrapper that presents a view of an underlying sequence of elements in some custom way without mutating or copying it. Views are cheap to create and copy, and have non-owning reference semantics. [...] The big advantage of ranges over iterators is their composability. They permit a functional style of programming where data is manipulated by passing it through a series of combinators. In addition, the combinators can be lazy, only doing work when the answer is requested, and purely functional, without mutating the original data. This makes it easier to reason about your code, especially when writing concurrent programs."
See the range module for how views relate to containers and decorators.
Most views provided by SeqAn are specific to biological operations, like seqan3::views::trim_quality which trims sequences based on the quality or seqan3::views::complement which generates the complement of a nucleotide sequence. But SeqAn also provides some general purpose views.
std::ranges::views
or in the namespace alias std::views
.seqan3::views
.Functional and pipe notations:
Re-transform into a distinct container:
Composability:
When talking about views, two different entities are often conflated:
auto vec_view
above)std::views::reverse
and seqan3::views::complement
are view adaptors)The view adaptor also facilitates the piping behaviour. It is the only entity that is publicly documented and the actual view type (the range type returned by the adaptor) is considered implementation defined. The properties of the returned range are however specified and documented as part of the adaptor, see below.
An exception to this rule are views that don't work on an underlying range and can only be placed at the beginning of a pipe of operations; they do not need an adaptor, because their constructor is sufficient. This is not relevant for the documentation, though, we always document views::foo
, independent of whether views::foo
is the adaptor that returns the "foo type" or whether views::foo
is the "foo type".
There are three view properties that are documented for a view, only if that view fulfils them:
Source-only views: Most views operate on an underlying range and return a (modified) range, i.e. they can be placed at the beginning, middle or end of a "pipe" of view operations. However, some views are limited to being at the front ("source"), e.g. std::views::empty
, std::view::single
and std::views::iota
. These views are marked as "source-only" and have no urng_t
column in the second table. The C++ standard calls these Range factories, which are utilities to create a view.
Sink-only views: The opposite of a source-only view. It can only be placed at the end of a pipe, i.e. it operates on views, but does not actually return a range (has no rrng_t
column in the second table). The C++20 standard doesn't have this concept.
Deep views: Some views are declared as "deeps views". This means, that in case they are given a range-of-range as input (as opposed to just a range), they will apply their transformation on the innermost range (instead of the outermost range which would be default). Most alphabet-based transformations are defined as deep, but you can use seqan3::views::deep to make any view (adaptor) deep. See seqan3::views::deep for more details. The C++20 standard doesn't have this concept.
For all views the following are documented:
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | [required] (usually) | [preserved|lost|guaranteed] (usually preserved) |
std::ranges::forward_range | [required] (or not) | [preserved|lost|guaranteed] |
std::ranges::bidirectional_range | [required] (or not) | [preserved|lost|guaranteed] |
std::ranges::random_access_range | [required] (or not) | [preserved|lost|guaranteed] |
std::ranges::contiguous_range | [required] (or not) | [preserved|lost|guaranteed] (usually lost) |
std::ranges::viewable_range | [required] (usually) | [preserved|lost|guaranteed] (usually guaranteed) |
std::ranges::view | [required] (or not) | [preserved|lost|guaranteed] (usually guaranteed) |
std::ranges::sized_range | [required] (or not) | [preserved|lost|guaranteed] |
std::ranges::common_range | [required] (or not) | [preserved|lost|guaranteed] |
std::ranges::output_range | [required] (or not) | [preserved|lost|guaranteed] |
seqan3::const_iterable_range | [required] (or not) | [preserved|lost] |
std::ranges::range_reference_t | optionally a type or concept | optionally a type or concept |
Underlying range requirements: All view adaptors that are not source-only make certain assumptions about their underlying range. The most basic assumption is that the range satisfies std::ranges::input_range
, but many have stronger requirements, e.g. std::ranges::random_access_range
. The concepts in the first block all build up on each other, i.e. requiring one implies requiring those above; the other concepts are mostly independent of each other. Most views also require that the underlying range satisfy std::ranges::viewable_range which means they don't accept temporary range objects other than views (because they are cheap to copy). Note that these being requirements means that they are the minimal set of properties assumed. Views may very well make use of stronger properties if available.
Return range guarantees: All view adaptors that are not sink-only return a range that meets at least std::ranges::input_range
and also std::ranges::view
(and conversely also std::ranges::viewable_range
, because all views are viewable). Most views also preserve stronger properties, e.g. std::ranges::random_access_range
, but this depends on the view. Some views may add properties not present on the input range.
Underlying range's reference type: The reference type is the type the elements of the underlying range are accessed by (since dereferencing an iterator or calling operator[] returns the reference type). The reference type may or may not actually contain a &
(see below). For many SeqAn specific views additional concept requirements are defined for the input range's reference type, e.g. seqan3::views::complement can only operate on ranges whose elements are nucleotides (meet seqan3::nucleotide_alphabet). In some case the type may even be a specific type or the result of a type trait.
Returned range's reference type: Conversely certain views make guarantees on the concepts satisfied by the return range's reference type or even always have a fixed type, e.g. seqan3::views::complement operates on nucleotides and of course also returns nucleotides and "std::ranges::range_reference_t<urng_t>" would imply that the reference type is the same. However, and this is important to note, the reference type of seqan3::views::complement has any actual &
removed from the underlying ranges' reference type (if originally present), this goes hand-in-hand with std::ranges::output_range being lost → original elements cannot be written to through this view. This is because new elements are being generated. Other views like std::views::reverse
also preserve the &
(if originally present), because the elements in the return view still point to the elements in the original range (just in different order). This has the effect that through some combinations of views you can modify the elements in the original range (if all views in the pipe preserve std::ranges::output_range), but through others you can't.
using seqan3::views::chunk = typedef seqan::stl::views::chunk |
A view adaptor that divides a range into chunks.
using seqan3::views::join_with = typedef seqan::stl::views::join_with |
A view adaptor that represents view consisting of the sequence obtained from flattening a view of ranges, with every element of the delimiter inserted in between elements of the view. The delimiter can be a single element or a view of elements.
using seqan3::views::zip = typedef seqan::stl::views::zip |
A view adaptor that takes several views and returns tuple-like values from every i-th element of each view.
A view that converts each element in the input range (implicitly or via static_cast
).
urng_t | The type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation] |
[in] | urange | The range being processed. [parameter is omitted in pipe notation] |
Header File
#include <seqan3/utility/views/convert.hpp>
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | required | preserved |
std::ranges::forward_range | preserved | |
std::ranges::bidirectional_range | preserved | |
std::ranges::random_access_range | preserved | |
std::ranges::contiguous_range | lost¹ | |
std::ranges::viewable_range | required | guaranteed |
std::ranges::view | guaranteed | |
std::ranges::sized_range | preserved | |
std::ranges::common_range | preserved | |
std::ranges::output_range | lost¹ | |
seqan3::const_iterable_range | preserved | |
std::ranges::range_reference_t | seqan3::convertible_to<out_t> | out_t |
¹ These are preserved if out_t
is the same as std::ranges::range_reference_t<urng_t>
, i.e. no conversion takes place.
See the views submodule documentation for detailed descriptions of the view properties.
Convert from int
to bool
:
Convert from seqan3::dna15 to seqan3::dna5:
A view calling get
on each element in a range.
size_t | The type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation] |
index | The index to get. |
[in] | urange | The range being processed. [parameter is omitted in pipe notation] |
get<index>
on the underlying element. See below for the properties of the returned range. Header File
#include <seqan3/utility/views/elements.hpp>
This view may be used instead of std::view::elements
when the underlying range contains seqan3 types, e.g. seqan3::qualified.
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | required | preserved |
std::ranges::forward_range | preserved | |
std::ranges::bidirectional_range | preserved | |
std::ranges::random_access_range | preserved | |
std::ranges::contiguous_range | lost | |
std::ranges::viewable_range | required | preserved |
std::ranges::view | preserved | |
std::ranges::sized_range | preserved | |
std::ranges::common_range | preserved | |
std::ranges::output_range | preserved | |
seqan3::const_iterable_range | preserved | |
std::ranges::range_reference_t | seqan3::tuple_like | std::tuple_element_t<index, std::ranges::range_reference_t<urng_t>> |
See the views submodule documentation for detailed descriptions of the view properties.
A view that interleaves a given range into another range at regular intervals.
urng_t | The type of the range being processed. |
inserted_rng_t | The type of the range being inserted. |
[in] | urange | The range being processed. |
[in] | inserted_range | The range being inserted. |
[in] | step_size | A value of size_type which indicates the interval to insert the inserted_range. |
Header File
#include <seqan3/utility/views/interleave.hpp>
This view can be used to insert one range into another range at regular intervals. It behaves essentially like | std::views::chunk(step_size) | seqan3::views::join_with(inserted_range)
except that for input that models std::ranges::random_access_range and std::ranges::sized_range a more efficient data structure is returned (otherwise it returns exactly the above combination of views).
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | required | preserved |
std::ranges::forward_range | required | preserved |
std::ranges::bidirectional_range | required | preserved |
std::ranges::random_access_range | required | preserved |
std::ranges::contiguous_range | lost | |
std::ranges::viewable_range | required | guaranteed |
std::ranges::view | guaranteed | |
std::ranges::sized_range | required | preserved |
std::ranges::common_range | preserved | |
std::ranges::output_range | preserved | |
seqan3::const_iterable_range | preserved | |
std::ranges::range_reference_t | std::ranges::range_reference_t<urng_t> |
If above requirements are not met, this adaptor forwards to | seqan3::views::chunk(step_size) | seqan3::views::join_with(inserted_range)
which returns a view with the following properties:
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | required | preserved |
std::ranges::forward_range | required | lost |
std::ranges::bidirectional_range | lost | |
std::ranges::random_access_range | lost | |
std::ranges::contiguous_range | lost | |
std::ranges::viewable_range | required | guaranteed |
std::ranges::view | guaranteed | |
std::ranges::sized_range | lost | |
std::ranges::common_range | lost | |
std::ranges::output_range | lost | |
seqan3::const_iterable_range | lost | |
std::ranges::range_reference_t | std::ranges::range_value_t<urng_t> |
urng_t
is the type of the range modified by this view (input).rrng_t
is the type of the range returned by this view.See the views submodule documentation for detailed descriptions of the view properties.
|
inlineconstexpr |
A view factory that repeats a given value infinitely.
value_t | The type of value to repeat wrapped in a std::views::single; must model std::copy_constructible. |
[in] | value | The value to repeat. |
Header File
#include <seqan3/utility/views/repeat.hpp>
This view is source-only, it can only be at the beginning of a pipe of range transformations.
Concepts and traits | rrng_t (returned range type) |
---|---|
std::ranges::input_range | guaranteed |
std::ranges::forward_range | guaranteed |
std::ranges::bidirectional_range | guaranteed |
std::ranges::random_access_range | guaranteed |
std::ranges::contiguous_range | |
std::ranges::viewable_range | guaranteed |
std::ranges::view | guaranteed |
std::ranges::sized_range | |
std::ranges::common_range | |
std::ranges::output_range | guaranteed |
seqan3::const_iterable_range | guaranteed |
std::ranges::range_reference_t | std::remove_reference_t<value_t> & |
See the views submodule documentation for detailed descriptions of the view properties.
A view factory that repeats a given value n
times.
value_t | The type of value to repeat; must be std::copy_constructible. |
[in] | value | The value to repeat. |
[in] | count | The number of times to repeat value . |
count
, where each element equals value
. Header File
#include <seqan3/utility/views/repeat_n.hpp>
This view is source-only, it can only be at the beginning of a pipe of range transformations.
Concepts and traits | rrng_t (returned range type) |
---|---|
std::ranges::input_range | guaranteed |
std::ranges::forward_range | guaranteed |
std::ranges::bidirectional_range | guaranteed |
std::ranges::random_access_range | guaranteed |
std::ranges::contiguous_range | |
std::ranges::viewable_range | guaranteed |
std::ranges::view | guaranteed |
std::ranges::sized_range | guaranteed |
std::ranges::common_range | |
std::ranges::output_range | guaranteed |
seqan3::const_iterable_range | guaranteed |
std::ranges::range_reference_t | std::remove_reference_t<value_t> & |
See the views submodule documentation for detailed descriptions of the view properties.
A view adaptor that returns a half-open interval on the underlying range.
urng_t | The type of the range being processed. See below for requirements. [template parameter is omitted in pipe notation] |
[in] | urange | The range being processed. [parameter is omitted in pipe notation] |
[in] | begin_pos | The beginning of the interval (index of first element returned). |
[in] | end_pos | The end of the interval (index behind the last element returned). |
end_pos - begin_pos
elements of the underlying range. std::invalid_argument | If end_pos < begin_pos . |
Header File
#include <seqan3/utility/views/slice.hpp>
Concepts and traits | urng_t (underlying range type) | rrng_t (returned range type) |
---|---|---|
std::ranges::input_range | required | preserved |
std::ranges::forward_range | preserved | |
std::ranges::bidirectional_range | preserved | |
std::ranges::random_access_range | preserved | |
std::ranges::contiguous_range | preserved | |
std::ranges::viewable_range | required | guaranteed |
std::ranges::view | guaranteed | |
std::ranges::sized_range | preserved | |
std::ranges::common_range | preserved | |
std::ranges::output_range | preserved | |
seqan3::const_iterable_range | preserved | |
std::ranges::range_reference_t | std::ranges::range_reference_t<urng_t> |
See the views submodule documentation for detailed descriptions of the view properties.
This adaptor is a combination of std::views::drop and std::views::take.
If begin_pos
is larger than the size of the underlying range an empty range is returned. If end_pos
is larger than the size of the underlying range less elements are returned.
If end_pos < begin_pos
an exception of type std::invalid_argument is thrown.
urng_t (underlying range type) | rrng_t (returned range type) |
---|---|
std::basic_string const & or std::basic_string_view | std::basic_string_view |
std::ranges::borrowed_range && std::ranges::sized_range && std::ranges::contiguous_range | std::span |
std::ranges::borrowed_range && std::ranges::sized_range && std::ranges::random_access_range | std::ranges::subrange |
else | implementation defined type |
The adaptor returns exactly the type specified above.
Construction of the returned view is in \( O(begin\_pos) \) for some views, see std::views::drop.