A library for working with phylogenetic and population genetic data.
v0.32.0
BaseWindowStream< InputStreamIterator, Data, WindowType > Class Template Referenceabstract

#include <genesis/population/window/base_window_stream.hpp>

Detailed Description

template<class InputStreamIterator, class Data = typename InputStreamIterator::value_type, class WindowType = typename ::genesis::population::Window<Data>>
class genesis::population::BaseWindowStream< InputStreamIterator, Data, WindowType >

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_typeadd_begin_callback (std::function< void()> const &callback)
 Add a callback function that is executed when beginning the iteration. More...
 
self_typeadd_end_callback (std::function< void()> const &callback)
 Add a callback function that is executed when the end of the iteration is reached. More...
 
self_typeadd_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_typeadd_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_typeclear_callbacks ()
 Clear all functions that have been added via add_begin_callback() and add_end_callback(). More...
 
self_typeclear_observers ()
 Clear all functions that are executed on incrementing to the next element. More...
 
Iterator end ()
 
BaseWindowStreamoperator= (BaseWindowStream &&)=default
 
BaseWindowStreamoperator= (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< BaseIteratorget_begin_iterator_ ()=0
 Get the begin iterator. More...
 
virtual std::unique_ptr< BaseIteratorget_end_iterator_ ()=0
 Get the end iterator. More...
 

Constructor & Destructor Documentation

◆ BaseWindowStream() [1/4]

BaseWindowStream ( InputStreamIterator  begin,
InputStreamIterator  end 
)
inline

Definition at line 620 of file base_window_stream.hpp.

◆ ~BaseWindowStream()

virtual ~BaseWindowStream ( )
virtualdefault

◆ BaseWindowStream() [2/4]

BaseWindowStream ( BaseWindowStream< InputStreamIterator, Data, WindowType > const &  )
default

◆ BaseWindowStream() [3/4]

BaseWindowStream ( BaseWindowStream< InputStreamIterator, Data, WindowType > &&  )
default

◆ BaseWindowStream() [4/4]

BaseWindowStream ( )
protecteddefault

Member Function Documentation

◆ add_begin_callback()

self_type& add_begin_callback ( std::function< void()> const &  callback)
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.

◆ add_end_callback()

self_type& add_end_callback ( std::function< void()> const &  callback)
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.

◆ add_on_enter_observer()

self_type& add_on_enter_observer ( std::function< void(WindowType const &)> const &  observer)
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.

◆ add_on_leave_observer()

self_type& add_on_leave_observer ( std::function< void(WindowType const &)> const &  observer)
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.

◆ begin()

Iterator begin ( )
inline

Definition at line 747 of file base_window_stream.hpp.

◆ clear_callbacks()

self_type& clear_callbacks ( )
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.

◆ clear_observers()

self_type& clear_observers ( )
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.

◆ end()

Iterator end ( )
inline

Definition at line 759 of file base_window_stream.hpp.

◆ get_begin_iterator_()

◆ get_end_iterator_()

◆ operator=() [1/2]

BaseWindowStream& operator= ( BaseWindowStream< InputStreamIterator, Data, WindowType > &&  )
default

◆ operator=() [2/2]

BaseWindowStream& operator= ( BaseWindowStream< InputStreamIterator, Data, WindowType > const &  )
default

Member Typedef Documentation

◆ const_reference

using const_reference = value_type const&

Definition at line 137 of file base_window_stream.hpp.

◆ DataType

using DataType = Data

Definition at line 128 of file base_window_stream.hpp.

◆ InputStreamType

using InputStreamType = InputStreamIterator

Definition at line 127 of file base_window_stream.hpp.

◆ InputType

using InputType = typename InputStreamIterator::value_type

Definition at line 131 of file base_window_stream.hpp.

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 133 of file base_window_stream.hpp.

◆ pointer

using pointer = value_type*

Definition at line 135 of file base_window_stream.hpp.

◆ reference

Definition at line 136 of file base_window_stream.hpp.

◆ self_type

using self_type = BaseWindowStream<InputStreamIterator, DataType, WindowType>

Definition at line 130 of file base_window_stream.hpp.

◆ value_type

using value_type = WindowType

Definition at line 134 of file base_window_stream.hpp.

Member Data Documentation

◆ chromosome_function

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.

◆ entry_input_function

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.

Definition at line 147 of file base_window_stream.hpp.

◆ Iterator

friend Iterator

Definition at line 633 of file base_window_stream.hpp.

◆ position_function

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.


The documentation for this class was generated from the following file: