#include <genesis/population/window/queue_window_stream.hpp>
Inherits BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type >.
Stream for Windows contaiing a queue of entries, i.e., sliding Windows of a fixed number of selected positions in a genome.
With each step of the iteration, a window of entries of the underlying input stream is yielded. The window contains count() many selected entries (entries that we want to consider), which is based on the result of the user-provided entry_selection_function() functor. Any entries of the underlying stream for which entry_selection_function() returns false
are still included in the windows, but do not count towards the total count() of entries that we want in the window. This is meant as a way for instance to create windows of n
SNP positions, while also being able to retain all non-SNP entries, if they are needed for the downstream algorithm that is using the windows.
If no such extra positions should be included in the window (e.g., if we only want the SNPs), an approriate filter needs to be applied beforhand to the input stream, for instance by adding it to the VariantInputStream that is typically used as input stream here, so that these entries are removed already before being assembled into windows here.
The way the windowing then works is as follows: Any window contains count() many selected entries, as well as all not-selected entries that come before each of these selected entries. For instance, x
marking selected (for which entry_selection_function
returns true
), and -
marking non-selected entries, and with non-overlapping windows of size 2 (stride == count == 2
), we get the following windows:
---x--x---x-xx---x-xx-x--x----x-x-x---x-- [ ][ ][ ][ ][ ][ ][ ]
where brackets mark each window as a closed interval. This is only considering entries based on them being selected or not - their position on the chromosome is not considerered here at all, which also means that any missing data does not affect this - it will just appear as jumps in the positions when iterating the windows, but as this windowing approach here is not based on these positions, there is no other effect.
Notice the special last case here: the last window also contains the trailing non-selected positions. This is done so that these positions are part of some window. This is also the case if the last window contains fewer entries than the count(), which happens if the number of selected entries in the chromosome is not a multiple of the count() (which is very likely).
The default helper functions to make an instance of this window stream, make_default_queue_window_stream() and make_default_queue_window_view_stream() set the entry_selection_function() so that all entries are selected. On the other hand, the specialized versions of these functions for underlying data of type Variant, make_passing_variant_queue_window_stream() and make_passing_variant_queue_window_view_stream() instead set the entry_selection_function() so that only Variants are selected for which the Variant::status is passing. Thus, for instance, if the underlying data stream has filters applied to it using the VariantFilterNumericalParams, this can be used to filter for SNPs. See there for details.
During the stream iteration, when incrementing the iterator, we move forward stride() many entries, which can correspond to an arbitrary number of positions in the genome, depending on how far the entries are spread out. Hence, any filtering on positions in the genome should be done beforehand on the inputs, so that only those entries are used by this stream that are meant to be selected.
The four functors
have to be set in the class prior to starting the iteration, as well as the count() of how many entries shall be used in each iteration. All other settings are optional and/or defaulted to reasonable values.
See BaseWindowStream for more details on the four functors, the template parameters, and general usage examples of the class.
For helper functions that take care of setting up this class for the most common use cases:
Definition at line 131 of file queue_window_stream.hpp.
Public Member Functions | |
QueueWindowStream (InputStreamIterator begin, InputStreamIterator end, size_t count=0, size_t stride=0) | |
QueueWindowStream (QueueWindowStream &&)=default | |
QueueWindowStream (QueueWindowStream const &)=default | |
virtual | ~QueueWindowStream () override=default |
size_t | count () const |
self_type & | count (size_t value) |
Number of selected entries in each Window. More... | |
QueueWindowStream & | operator= (QueueWindowStream &&)=default |
QueueWindowStream & | operator= (QueueWindowStream const &)=default |
size_t | stride () const |
self_type & | stride (size_t value) |
Stride of the Window, that is, how many entries to move forward with each iteration. More... | |
Public Member Functions inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type > | |
BaseWindowStream (BaseWindowStream &&)=default | |
BaseWindowStream (BaseWindowStream const &)=default | |
BaseWindowStream (InputStreamIterator begin, InputStreamIterator end) | |
virtual | ~BaseWindowStream ()=default |
self_type & | add_begin_callback (std::function< void()> const &callback) |
Add a callback function that is executed when beginning the iteration. More... | |
self_type & | add_end_callback (std::function< void()> const &callback) |
Add a callback function that is executed when the end of the iteration is reached. More... | |
self_type & | add_on_enter_observer (std::function< void(typename ::genesis::population::Window< typename InputStreamIterator::value_type > const &)> const &observer) |
Add a observer function that is executed once for each window during the iteration, when entering the window during the iteration. More... | |
self_type & | add_on_leave_observer (std::function< void(typename ::genesis::population::Window< typename InputStreamIterator::value_type > const &)> const &observer) |
Add a observer function that is executed once for each window during the iteration, when leaving the window during the iteration. More... | |
Iterator | begin () |
self_type & | clear_callbacks () |
Clear all functions that have been added via add_begin_callback() and add_end_callback(). More... | |
self_type & | clear_observers () |
Clear all functions that are executed on incrementing to the next element. More... | |
Iterator | end () |
BaseWindowStream & | operator= (BaseWindowStream &&)=default |
BaseWindowStream & | operator= (BaseWindowStream const &)=default |
Public Types | |
using | base_type = BaseWindowStream< InputStreamIterator, DataType > |
using | const_reference = value_type const & |
using | Entry = typename Window::Entry |
using | InputType = typename InputStreamIterator::value_type |
using | iterator_category = std::input_iterator_tag |
using | pointer = value_type * |
using | reference = value_type & |
using | self_type = QueueWindowStream< InputStreamIterator, DataType > |
using | value_type = Window |
using | Window = ::genesis::population::Window< DataType > |
Public Types inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type > | |
using | const_reference = value_type const & |
using | DataType = typename InputStreamIterator::value_type |
using | InputStreamType = InputStreamIterator |
using | InputType = typename InputStreamIterator::value_type |
using | iterator_category = std::input_iterator_tag |
using | pointer = value_type * |
using | reference = value_type & |
using | self_type = BaseWindowStream< InputStreamIterator, DataType, typename ::genesis::population::Window< typename InputStreamIterator::value_type > > |
using | value_type = typename ::genesis::population::Window< typename InputStreamIterator::value_type > |
Public Attributes | |
friend | DerivedIterator |
std::function< bool(InputType const &)> | entry_selection_function |
Functor that takes an entry of the underlying input stream and returns whether that entry should be selected towards the window size count() or not. More... | |
Public Attributes inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type > | |
std::function< std::string(InputType const &)> | chromosome_function |
Functor that yields the current chromosome, given the input stream data. More... | |
std::function< DataType(InputType const &)> | entry_input_function |
Functor to convert from the underlying input stream that provides the data to fill the windows to the data that is stored per window. More... | |
friend | Iterator |
std::function< size_t(InputType const &)> | position_function |
Functor that yields the current position on the chromosome, given the input stream data. More... | |
Classes | |
class | DerivedIterator |
Internal iterator that produces Windows. More... | |
Protected Member Functions | |
std::unique_ptr< typename BaseWindowStream< InputStreamIterator, DataType >::BaseIterator > | get_begin_iterator_ () override final |
Get the begin iterator. More... | |
std::unique_ptr< typename BaseWindowStream< InputStreamIterator, DataType >::BaseIterator > | get_end_iterator_ () override final |
Get the end iterator. More... | |
Protected Member Functions inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type > | |
BaseWindowStream ()=default | |
|
inline |
Definition at line 715 of file queue_window_stream.hpp.
|
overridevirtualdefault |
|
default |
|
default |
|
inline |
Definition at line 752 of file queue_window_stream.hpp.
|
inline |
Number of selected entries in each Window.
The count has to be > 0
. This is the number of selected entries that are put into each Window. Typically, we process, e.g., variant positions only - in that case, the count() is the number of Variants in each Window. This depends on the entry_selection_function(), see there for details on how the selection of entries works.
Definition at line 746 of file queue_window_stream.hpp.
|
inlinefinaloverrideprotectedvirtual |
Get the begin iterator.
Needs to be implemented by the derived class, to give the correct derived BaseIterator instance.
Implements BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type >.
Definition at line 784 of file queue_window_stream.hpp.
|
inlinefinaloverrideprotectedvirtual |
Get the end iterator.
Needs to be implemented by the derived class, to give the correct derived BaseIterator instance.
Implements BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type >.
Definition at line 793 of file queue_window_stream.hpp.
|
default |
|
default |
|
inline |
Definition at line 772 of file queue_window_stream.hpp.
|
inline |
Stride of the Window, that is, how many entries to move forward with each iteration.
The stride his is the shift towards the next interval, determining how many entries are dropped from the beginning and added to the end of each Window when iterating. It has to be <= count
. If stride is set to 0 (default), it is set automatically to the count() when starting the iteration, meaning that each Window contains the next count() many new entries from the underlying input iterator.
Definition at line 766 of file queue_window_stream.hpp.
using base_type = BaseWindowStream<InputStreamIterator, DataType> |
Definition at line 140 of file queue_window_stream.hpp.
using const_reference = value_type const& |
Definition at line 150 of file queue_window_stream.hpp.
using Entry = typename Window::Entry |
Definition at line 143 of file queue_window_stream.hpp.
using InputType = typename InputStreamIterator::value_type |
Definition at line 144 of file queue_window_stream.hpp.
using iterator_category = std::input_iterator_tag |
Definition at line 146 of file queue_window_stream.hpp.
using pointer = value_type* |
Definition at line 148 of file queue_window_stream.hpp.
using reference = value_type& |
Definition at line 149 of file queue_window_stream.hpp.
using self_type = QueueWindowStream<InputStreamIterator, DataType> |
Definition at line 139 of file queue_window_stream.hpp.
using value_type = Window |
Definition at line 147 of file queue_window_stream.hpp.
using Window = ::genesis::population::Window<DataType> |
Definition at line 142 of file queue_window_stream.hpp.
friend DerivedIterator |
Definition at line 732 of file queue_window_stream.hpp.
std::function<bool( InputType const& )> entry_selection_function |
Functor that takes an entry of the underlying input stream and returns whether that entry should be selected towards the window size count() or not.
Any entry that is selected (the function here returning true
) will be used to fill the window and are considered for the count() of entries per window. Entries for which the function returns false
are also enqueued in the window, but do not count towards the number of entries in the window.
Definition at line 165 of file queue_window_stream.hpp.