A library for working with phylogenetic and population genetic data.
v0.32.0
ChromosomeWindowStream< InputStreamIterator, DataType > Class Template Referencefinal

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

Inherits BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >.

Detailed Description

template<class InputStreamIterator, class DataType = typename InputStreamIterator::value_type>
class genesis::population::ChromosomeWindowStream< InputStreamIterator, DataType >

Stream for traversing each chromosome as a whole, with an inner WindowView iterator over the positions of each chromosome.

With each step of the iteration, an inner WindowView iterator is yielded that traverses all positions on a chromosome of the underlying input data stream. Then, when incrementing the main iterator, we move forward to the next chromosome.

This class is merely meant as a simplification over manually keeping track of the current chromosome, for example when computing a statistic for whole chromosomes, so that those algorithms do not need to take care of when to produce their output. Instead, they can simply use this class, and produce output at each step of the main iterator. This class contains a quite unfortunate amount of boiler plate, but hopefully makes downstream algorithms easier to write.

The three functors

have to be set in the class prior to starting the iteration for the chromosome iterator. See make_chromosome_window_stream() and make_default_chromosome_window_stream() for helper functions that take care of this for most of our data types.

See BaseWindowStream for more details on the three functors, the template parameters. This class here however does not derive from the BaseWindowStream over normal Windows, but behaves in a similar way - with the exception that it does not produce Windows in each step of the iteration, as we do not want to keep the positions of a whole chromosome in memory. Hence, instead, it yields a WindowView iterator, directly streaming over the positions of the chromosome, without keeping all data in memory.

See also
make_chromosome_window_stream()
make_default_chromosome_window_stream()

Definition at line 90 of file chromosome_window_stream.hpp.

Public Member Functions

 ChromosomeWindowStream (ChromosomeWindowStream &&)=default
 
 ChromosomeWindowStream (ChromosomeWindowStream const &)=default
 
 ChromosomeWindowStream (InputStreamIterator begin, InputStreamIterator end)
 
virtual ~ChromosomeWindowStream () override=default
 
ChromosomeWindowStreamoperator= (ChromosomeWindowStream &&)=default
 
ChromosomeWindowStreamoperator= (ChromosomeWindowStream const &)=default
 
std::shared_ptr< genesis::sequence::SequenceDictsequence_dict () const
 Get the currently set sequence dictionary used for the chromosome lengths. More...
 
self_typesequence_dict (std::shared_ptr< genesis::sequence::SequenceDict > value)
 Set a sequence dictionary to be used for the chromosome lengths. More...
 
- Public Member Functions inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >
 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(::genesis::population::WindowView< 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_typeadd_on_leave_observer (std::function< void(::genesis::population::WindowView< 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_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 base_type = BaseWindowStream< InputStreamIterator, DataType, WindowViewType >
 
using const_reference = value_type const &
 
using InputType = typename InputStreamIterator::value_type
 
using iterator_category = std::input_iterator_tag
 
using pointer = value_type *
 
using reference = value_type &
 
using self_type = ChromosomeWindowStream< InputStreamIterator, DataType >
 
using value_type = WindowViewType
 
using WindowViewType = ::genesis::population::WindowView< DataType >
 
- Public Types inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type, ::genesis::population::WindowView< 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, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >
 
using value_type = ::genesis::population::WindowView< typename InputStreamIterator::value_type >
 

Public Attributes

friend DerivedIterator
 
- Public Attributes inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type, ::genesis::population::WindowView< 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 WindowViews. More...
 

Protected Member Functions

std::unique_ptr< typename base_type::BaseIteratorget_begin_iterator_ () override final
 Get the begin iterator. More...
 
std::unique_ptr< typename base_type::BaseIteratorget_end_iterator_ () override final
 Get the end iterator. More...
 
- Protected Member Functions inherited from BaseWindowStream< InputStreamIterator, typename InputStreamIterator::value_type, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >
 BaseWindowStream ()=default
 

Constructor & Destructor Documentation

◆ ChromosomeWindowStream() [1/3]

ChromosomeWindowStream ( InputStreamIterator  begin,
InputStreamIterator  end 
)
inline

Definition at line 362 of file chromosome_window_stream.hpp.

◆ ~ChromosomeWindowStream()

virtual ~ChromosomeWindowStream ( )
overridevirtualdefault

◆ ChromosomeWindowStream() [2/3]

ChromosomeWindowStream ( ChromosomeWindowStream< InputStreamIterator, DataType > const &  )
default

◆ ChromosomeWindowStream() [3/3]

ChromosomeWindowStream ( ChromosomeWindowStream< InputStreamIterator, DataType > &&  )
default

Member Function Documentation

◆ get_begin_iterator_()

std::unique_ptr<typename base_type::BaseIterator> get_begin_iterator_ ( )
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, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >.

Definition at line 414 of file chromosome_window_stream.hpp.

◆ get_end_iterator_()

std::unique_ptr<typename base_type::BaseIterator> get_end_iterator_ ( )
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, ::genesis::population::WindowView< typename InputStreamIterator::value_type > >.

Definition at line 423 of file chromosome_window_stream.hpp.

◆ operator=() [1/2]

ChromosomeWindowStream& operator= ( ChromosomeWindowStream< InputStreamIterator, DataType > &&  )
default

◆ operator=() [2/2]

ChromosomeWindowStream& operator= ( ChromosomeWindowStream< InputStreamIterator, DataType > const &  )
default

◆ sequence_dict() [1/2]

std::shared_ptr<genesis::sequence::SequenceDict> sequence_dict ( ) const
inline

Get the currently set sequence dictionary used for the chromosome lengths.

Definition at line 385 of file chromosome_window_stream.hpp.

◆ sequence_dict() [2/2]

self_type& sequence_dict ( std::shared_ptr< genesis::sequence::SequenceDict value)
inline

Set a sequence dictionary to be used for the chromosome lengths.

By default, we use the chromosome positions as given in the data to set the Window first and last positions. When setting a SequenceDict here, we use lengths as provided instead, throwing an exception should the dict not contain a chromosome of the input.

To un-set the dictionary, simply call this function with a nullptr.

Definition at line 401 of file chromosome_window_stream.hpp.

Member Typedef Documentation

◆ base_type

using base_type = BaseWindowStream<InputStreamIterator, DataType, WindowViewType>

Definition at line 102 of file chromosome_window_stream.hpp.

◆ const_reference

using const_reference = value_type const&

Definition at line 114 of file chromosome_window_stream.hpp.

◆ InputType

using InputType = typename InputStreamIterator::value_type

Definition at line 105 of file chromosome_window_stream.hpp.

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 110 of file chromosome_window_stream.hpp.

◆ pointer

using pointer = value_type*

Definition at line 112 of file chromosome_window_stream.hpp.

◆ reference

Definition at line 113 of file chromosome_window_stream.hpp.

◆ self_type

using self_type = ChromosomeWindowStream<InputStreamIterator, DataType>

Definition at line 101 of file chromosome_window_stream.hpp.

◆ value_type

Definition at line 111 of file chromosome_window_stream.hpp.

◆ WindowViewType

Member Data Documentation

◆ DerivedIterator

Definition at line 376 of file chromosome_window_stream.hpp.


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