Skip to content

Commit

Permalink
Rename all Window Iterators into Streams
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed Feb 28, 2024
1 parent 2bf4bd8 commit 0e0024e
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 478 deletions.
14 changes: 7 additions & 7 deletions lib/genesis/population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@
#include "genesis/population/streams/variant_parallel_input_stream.hpp"
#include "genesis/population/variant.hpp"
#include "genesis/population/window/base_window.hpp"
#include "genesis/population/window/base_window_iterator.hpp"
#include "genesis/population/window/chromosome_iterator.hpp"
#include "genesis/population/window/base_window_stream.hpp"
#include "genesis/population/window/chromosome_stream.hpp"
#include "genesis/population/window/functions.hpp"
#include "genesis/population/window/region_window_iterator.hpp"
#include "genesis/population/window/sliding_entries_window_iterator.hpp"
#include "genesis/population/window/sliding_interval_window_iterator.hpp"
#include "genesis/population/window/region_window_stream.hpp"
#include "genesis/population/window/sliding_entries_window_stream.hpp"
#include "genesis/population/window/sliding_interval_window_stream.hpp"
#include "genesis/population/window/sliding_window_generator.hpp"
#include "genesis/population/window/variant_window_iterator.hpp"
#include "genesis/population/window/variant_window_stream.hpp"
#include "genesis/population/window/vcf_window.hpp"
#include "genesis/population/window/window.hpp"
#include "genesis/population/window/window_view.hpp"
#include "genesis/population/window/window_view_iterator.hpp"
#include "genesis/population/window/window_view_stream.hpp"

#endif // include guard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef GENESIS_POPULATION_WINDOW_BASE_WINDOW_ITERATOR_H_
#define GENESIS_POPULATION_WINDOW_BASE_WINDOW_ITERATOR_H_
#ifndef GENESIS_POPULATION_WINDOW_BASE_WINDOW_STREAM_H_
#define GENESIS_POPULATION_WINDOW_BASE_WINDOW_STREAM_H_

/*
Genesis - A toolkit for working with phylogenetic data.
Expand Down Expand Up @@ -48,23 +48,23 @@ namespace genesis {
namespace population {

// =================================================================================================
// Base Window Iterator
// Base Window Stream
// =================================================================================================

/**
* @brief Base iterator class for Window%s over the chromosomes of a genome.
* @brief Base class for streams of Window%s over the chromosomes of a genome.
*
* This base class serves for sliding windows, windows over regions of a genome, etc.
*
* The template parameters are:
* * `InputIterator`: The type of the underlying iterator over the genome data (that is, the input
* iterator from which the windows take their data). Needs to have a member type
* `value_type` that specifies the actual input type that the iterator produces, which we here
* * `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 iterator that we get our data from.
* the same data type as the underlying stream that we get our data from.
*
* The three functors
*
Expand All @@ -74,12 +74,12 @@ namespace population {
*
* have to be set in the class prior to starting the iteration.
*
* The general usage of the derived classes that actually implement this iterator is as follows,
* on the example of the SlidingIntervalWindowIterator:
* The general usage of the derived classes that actually implement this stream is as follows,
* on the example of the SlidingIntervalWindowStream:
*
* // Make an iterator using some underlying data iterator
* // Make a window stream using some underlying data stream
* // that yields data for one position in the genome at a time.
* auto win_it = SlidingIntervalWindowIterator<InputIterator>( data_begin, data_end );
* auto win_it = SlidingIntervalWindowStream<InputStreamIterator>( data_begin, data_end );
*
* // Set functors to access the underlying data.
* win_it.entry_input_function = []( Data const& variant ) {
Expand All @@ -104,23 +104,23 @@ namespace population {
* Other derived classes work accordingly.
*/
template<
class InputIterator,
class Data = typename InputIterator::value_type,
class InputStreamIterator,
class Data = typename InputStreamIterator::value_type,
class WindowType = typename ::genesis::population::Window<Data>
>
class BaseWindowIterator
class BaseWindowStream
{
public:

// -------------------------------------------------------------------------
// Typedefs and Enums
// -------------------------------------------------------------------------

using InputIteratorType = InputIterator;
using InputStreamType = InputStreamIterator;
using DataType = Data;

using self_type = BaseWindowIterator<InputIterator, DataType, WindowType>;
using InputType = typename InputIterator::value_type;
using self_type = BaseWindowStream<InputStreamIterator, DataType, WindowType>;
using InputType = typename InputStreamIterator::value_type;

using iterator_category = std::input_iterator_tag;
using value_type = WindowType;
Expand All @@ -133,19 +133,19 @@ class BaseWindowIterator
// -------------------------------------------------------------------------

/**
* @brief Functor to convert from the underlying input iterator that provides the data
* @brief Functor to convert from the underlying input stream that provides the data
* to fill the windows to the data that is stored per window.
*/
std::function<DataType( InputType const& )> entry_input_function;

/**
* @brief Functor that yields the current chromosome, given the input iterator data.
* @brief Functor that yields the current chromosome, given the input stream data.
*/
std::function<std::string( InputType const& )> chromosome_function;

/**
* @brief Functor that yields the current position on the chromosome,
* given the input iterator data.
* given the input stream data.
*/
std::function<size_t( InputType const& )> position_function;

Expand Down Expand Up @@ -183,10 +183,10 @@ class BaseWindowIterator
// Constructors and Rule of Five
// -------------------------------------------------------------------------

using self_type = typename BaseWindowIterator<
InputIteratorType, DataType, WindowType
using self_type = typename BaseWindowStream<
InputStreamType, DataType, WindowType
>::Iterator;
using InputType = typename InputIteratorType::value_type;
using InputType = typename InputStreamType::value_type;

using iterator_category = std::input_iterator_tag;
using value_type = WindowType;
Expand Down Expand Up @@ -228,7 +228,7 @@ class BaseWindowIterator
return *this;
}

friend BaseWindowIterator;
friend BaseWindowStream;

// -------------------------------------------------------------------------
// Properties
Expand Down Expand Up @@ -320,7 +320,7 @@ class BaseWindowIterator
* Any two iterators that are copies of each other or started from the same parent
* will compare equal, as long as neither of them is past-the-end.
* A valid (not past-the-end) iterator and an end() iterator will not compare equal,
* no matter from which BaseWindowIterator they were created.
* no matter from which BaseWindowStream they were created.
* Two past-the-end iterators compare equal.
*/
bool operator==( self_type const& other ) const
Expand Down Expand Up @@ -388,10 +388,10 @@ class BaseWindowIterator
// Constructors and Rule of Five
// -------------------------------------------------------------------------

using self_type = typename BaseWindowIterator<
InputIteratorType, DataType, WindowType
using self_type = typename BaseWindowStream<
InputStreamType, DataType, WindowType
>::BaseIterator;
using InputType = typename InputIteratorType::value_type;
using InputType = typename InputStreamType::value_type;

using iterator_category = std::input_iterator_tag;
using value_type = WindowType;
Expand All @@ -409,7 +409,7 @@ class BaseWindowIterator
* @brief Construct the base class, which does initialization checks on its member
* variables to ensure that the user has set up the functors correctly.
*/
BaseIterator( BaseWindowIterator const* parent )
BaseIterator( BaseWindowStream const* parent )
{
init_( parent );
}
Expand All @@ -426,7 +426,7 @@ class BaseWindowIterator
// BaseIterator& operator= ( self_type const& ) = default;
// BaseIterator& operator= ( self_type&& ) = default;

friend BaseWindowIterator;
friend BaseWindowStream;
friend Iterator;

// -------------------------------------------------------------------------
Expand All @@ -438,7 +438,7 @@ class BaseWindowIterator
/**
* @brief Initialize the base iterator class and check that it is set up correctly.
*/
void init_( BaseWindowIterator const* parent )
void init_( BaseWindowStream const* parent )
{
// We use the parent as a check if this Iterator is intended to be a begin()
// or end() iterator. If its the former, init. If the latter, we are done here.
Expand All @@ -454,19 +454,19 @@ class BaseWindowIterator
// Check that the functors are set up.
if( ! parent->entry_input_function ) {
throw std::runtime_error(
"Need to set BaseWindowIterator::entry_input_function "
"Need to set BaseWindowStream::entry_input_function "
"before iterating over Windows with a Window Iterator."
);
}
if( ! parent->chromosome_function ) {
throw std::runtime_error(
"Need to set BaseWindowIterator::chromosome_function "
"Need to set BaseWindowStream::chromosome_function "
"before iterating over Windows with a Window Iterator."
);
}
if( ! parent->position_function ) {
throw std::runtime_error(
"Need to set BaseWindowIterator::position_function "
"Need to set BaseWindowStream::position_function "
"before iterating over Windows with a Window Iterator."
);
}
Expand Down Expand Up @@ -498,17 +498,17 @@ class BaseWindowIterator
* In the derived class implementation, this should be a pointer to the _derived_ parent
* class, to make sure that it contains the correct settings etc needed for the iteration.
*/
virtual BaseWindowIterator const* get_parent_() const = 0;
virtual BaseWindowStream const* get_parent_() const = 0;

protected:

// Need to manually keep track of those...
bool is_first_window_ = true;
bool is_last_window_ = false;

// Underlying iterator
InputIterator current_;
InputIterator end_;
// Underlying data stream
InputStreamIterator current_;
InputStreamIterator end_;

};

Expand All @@ -522,18 +522,18 @@ class BaseWindowIterator
// Constructors and Rule of Five
// -------------------------------------------------------------------------

BaseWindowIterator( InputIterator begin, InputIterator end )
BaseWindowStream( InputStreamIterator begin, InputStreamIterator end )
: begin_(begin)
, end_(end)
{}

virtual ~BaseWindowIterator() = default;
virtual ~BaseWindowStream() = default;

BaseWindowIterator( BaseWindowIterator const& ) = default;
BaseWindowIterator( BaseWindowIterator&& ) = default;
BaseWindowStream( BaseWindowStream const& ) = default;
BaseWindowStream( BaseWindowStream&& ) = default;

BaseWindowIterator& operator= ( BaseWindowIterator const& ) = default;
BaseWindowIterator& operator= ( BaseWindowIterator&& ) = default;
BaseWindowStream& operator= ( BaseWindowStream const& ) = default;
BaseWindowStream& operator= ( BaseWindowStream&& ) = default;

friend Iterator;

Expand Down Expand Up @@ -588,8 +588,8 @@ class BaseWindowIterator

protected:

// Need a default for WindowViewIterator.
BaseWindowIterator() = default;
// Need a default for WindowViewStream.
BaseWindowStream() = default;

virtual std::unique_ptr<BaseIterator> get_begin_iterator_() = 0;
virtual std::unique_ptr<BaseIterator> get_end_iterator_() = 0;
Expand All @@ -601,8 +601,8 @@ class BaseWindowIterator
private:

// Underlying iterator to the data that we want to put in windows.
InputIterator begin_;
InputIterator end_;
InputStreamIterator begin_;
InputStreamIterator end_;

// Keep the observers for each window view.
std::vector<std::function<void(WindowType const&)>> observers_;
Expand Down
Loading

0 comments on commit 0e0024e

Please sign in to comment.