#include <genesis/population/window/base_window_stream.hpp>
Base class for streams of Windows over the chromosomes of a genome.
This base class serves for sliding windows, windows over regions of a genome, etc.
The template parameters are:
InputStreamIterator
: The type of the underlying stream over the genome data (that is, the input stream from which the windows take their data). Needs to have a member type value_type
that specifies the actual input type that the stream produces, which we here call the InputType
(and typedef it as that).Data
: The data type of the Window::Data that is stored in Window::Entry. The functor entry_input_function needs to be provided to convert from InputType
to this Data
. By default, we take this to be the same as the InputType
, meaning that the Window contains the same data type as the underlying stream that we get our data from.WindowType
: The type of window that is emitted in each step of the iteration. This can either be Window or WindowView, depending on whether the data needs to be kept in memory, or can be produced on the fly while iterating each window.The three functors
have to be set in the class prior to starting the iteration.
The general usage of the derived classes that actually implement this stream is as follows, on the example of the SlidingIntervalWindowStream:
// Make a window stream using some underlying data stream // that yields data for one position in the genome at a time. auto win_it = SlidingIntervalWindowStream<InputStreamIterator>( data_begin, data_end ); // Set functors to access the underlying data. win_it.entry_input_function = []( Data const& variant ) { return variant; }; win_it.chromosome_function = []( Data const& variant ) { return variant.chromosome; }; win_it.position_function = []( Data const& variant ) { return variant.position; }; // Set properties specific to the derived class. win_it.width( width ); win_it.stride( stride ); // Iterate over Windows. for( auto it = win_it.begin(); it != win_it.end(); ++it ) { // Inside here, we typically then want to loop over the entries of each window } // Alternative version. for( auto const& window : win_it ) { // Same as above, nested loop here to iterate the entries of each window }
Other derived classes work accordingly.
Definition at line 119 of file base_window_stream.hpp.
Public Member Functions | |
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(WindowType 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(WindowType 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 | const_reference = value_type const & |
using | DataType = Data |
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, WindowType > |
using | value_type = WindowType |
Public Attributes | |
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 | BaseIterator |
Internal PIMPL-like implementation of the iterator that produces Windows. More... | |
class | Iterator |
Internal public iterator that produces Windows. More... | |
Protected Member Functions | |
BaseWindowStream ()=default | |
virtual std::unique_ptr< BaseIterator > | get_begin_iterator_ ()=0 |
Get the begin iterator. More... | |
virtual std::unique_ptr< BaseIterator > | get_end_iterator_ ()=0 |
Get the end iterator. More... | |
|
inline |
Definition at line 620 of file base_window_stream.hpp.
|
virtualdefault |
|
default |
|
default |
|
protecteddefault |
|
inline |
Add a callback function that is executed when beginning the iteration.
Similar to the functionality offered by the observers, this could also be achieved by executing these functions direclty where needed, but having it as a callback here helps to reduce code duplication.
See also add_end_callback().
Definition at line 698 of file base_window_stream.hpp.
|
inline |
Add a callback function that is executed when the end of the iteration is reached.
This is similar to the add_begin_callback() functionality, but instead of executing the callback when starting the iteration, it is called when ending it. Again, this is meant as a means to reduce user code duplication, for example for logging needs.
Definition at line 716 of file base_window_stream.hpp.
|
inline |
Add a observer function that is executed once for each window during the iteration, when entering the window during the iteration.
These functions are executed when starting and incrementing the iterator, once for each window, in the order in which they are added here. They take the window (typically of type Window or WindowView) that the iterator just moved to as their argument, so that user code can react to the new window properties.
They are a way of adding behaviour to the iteration loop that could also simply be placed in the beginning of the loop body of the user code. Still, offering this here can reduce redundant code, such as logging window positions during the iteration.
Definition at line 652 of file base_window_stream.hpp.
|
inline |
Add a observer function that is executed once for each window during the iteration, when leaving the window during the iteration.
These functions are executed when incrementing the iterator towards the next window or at the end of the iteration, once for each window, in the order in which they are added here. They take the window (typically of type Window or WindowView) that the iterator is about to move on from as their argument, so that user code can react to the new window properties.
They are a way of adding behaviour to the iteration loop that could also simply be placed at the end of the loop body of the user code. Still, offering this here can reduce redundant code, such as logging window positions during the iteration.
Definition at line 671 of file base_window_stream.hpp.
|
inline |
Definition at line 747 of file base_window_stream.hpp.
|
inline |
Clear all functions that have been added via add_begin_callback() and add_end_callback().
Definition at line 731 of file base_window_stream.hpp.
|
inline |
Clear all functions that are executed on incrementing to the next element.
This clears both the on enter and on leave observers.
Definition at line 682 of file base_window_stream.hpp.
|
inline |
Definition at line 759 of file base_window_stream.hpp.
|
protectedpure virtual |
Get the begin iterator.
Needs to be implemented by the derived class, to give the correct derived BaseIterator instance.
Implemented in QueueWindowStream< InputStreamIterator, DataType >, RegionWindowStream< InputStreamIterator, DataType >, IntervalWindowStream< InputStreamIterator, DataType >, ChromosomeWindowStream< InputStreamIterator, DataType >, GenomeWindowStream< InputStreamIterator, DataType >, PositionWindowStream< InputStreamIterator, DataType >, and WindowViewStream< InputStreamIterator, Data >.
|
protectedpure virtual |
Get the end iterator.
Needs to be implemented by the derived class, to give the correct derived BaseIterator instance.
Implemented in QueueWindowStream< InputStreamIterator, DataType >, RegionWindowStream< InputStreamIterator, DataType >, IntervalWindowStream< InputStreamIterator, DataType >, ChromosomeWindowStream< InputStreamIterator, DataType >, GenomeWindowStream< InputStreamIterator, DataType >, PositionWindowStream< InputStreamIterator, DataType >, and WindowViewStream< InputStreamIterator, Data >.
|
default |
|
default |
using const_reference = value_type const& |
Definition at line 137 of file base_window_stream.hpp.
using DataType = Data |
Definition at line 128 of file base_window_stream.hpp.
using InputStreamType = InputStreamIterator |
Definition at line 127 of file base_window_stream.hpp.
using InputType = typename InputStreamIterator::value_type |
Definition at line 131 of file base_window_stream.hpp.
using iterator_category = std::input_iterator_tag |
Definition at line 133 of file base_window_stream.hpp.
using pointer = value_type* |
Definition at line 135 of file base_window_stream.hpp.
using reference = value_type& |
Definition at line 136 of file base_window_stream.hpp.
using self_type = BaseWindowStream<InputStreamIterator, DataType, WindowType> |
Definition at line 130 of file base_window_stream.hpp.
using value_type = WindowType |
Definition at line 134 of file base_window_stream.hpp.
std::function<std::string( InputType const& )> chromosome_function |
Functor that yields the current chromosome, given the input stream data.
Definition at line 152 of file base_window_stream.hpp.
Functor to convert from the underlying input stream that provides the data to fill the windows to the data that is stored per window.
Definition at line 147 of file base_window_stream.hpp.
friend Iterator |
Definition at line 633 of file base_window_stream.hpp.
std::function<size_t( InputType const& )> position_function |
Functor that yields the current position on the chromosome, given the input stream data.
Definition at line 158 of file base_window_stream.hpp.