A library for working with phylogenetic and population genetic data.
v0.32.0
WindowView< D > Class Template Referencefinal

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

Inherits BaseWindow< D >.

Detailed Description

template<class D>
class genesis::population::WindowView< D >

Proxy view over window-like regions of a genome.

As opposed to the Window class, this WindowView merely is a proxy for iterating some underlying data, but without copying the entries into the window. It serves as an abstraction for algorithms that need to stream through a file in a window-like manner in a single pass.

It expexts the get_element function to be set, returning a pointer to the current underlying data entry, or a nullptr to signal the end of the iteration. The provided function needs to distinguish the inital call (get the first element of the underlying input iterator), from later calls, in which case the underlying iterator needs to be advanced first.

That is, this provided get_element function is also responsible for advancing the underlying stream. This abstraction allows the class to be used as an iterator pointing to some other data, without using the being() and end() functions of that data (which might not even need to have those). For example, when iteraing individual whole chromosomes as windows (see ChromosomeIterator for this), we want to stop the iteration of each window after a chromosome is done, which might be before the end of the data itself (if there are multiple chromosomes in the input). The get_element function of this WindowView class allows to define such conditions, and stops the iteration.

Because of its streaming approach, its memory footprint is smaller than that of a Window, and hence allows to iterator whole chromosomes or genomes. On the flipside, its a single pass iterator with no random access to the data in the window.

Definition at line 76 of file window_view.hpp.

Public Member Functions

 WindowView ()=default
 
 WindowView (Window< Data > &window)
 Constructor that takes a Window window and creates a view into it. More...
 
 WindowView (Window< Data > const &window)
 Constructor that takes a Window window and creates a view into it. More...
 
 WindowView (WindowView &&)=default
 
 WindowView (WindowView const &)=default
 
virtual ~WindowView () override=default
 
Iterator begin () const
 
Iterator end () const
 
WindowViewoperator= (WindowView &&)=default
 
WindowViewoperator= (WindowView const &)=default
 
- Public Member Functions inherited from BaseWindow< D >
 BaseWindow ()=default
 
 BaseWindow (BaseWindow &&)=default
 
 BaseWindow (BaseWindow const &)=default
 
virtual ~BaseWindow ()=default
 
std::string const & chromosome () const
 Get the chromosome name that this Window belongs to. More...
 
void chromosome (std::string const &value)
 Set the chromosome name that this Window belongs to. More...
 
std::unordered_map< std::string, size_t > & chromosomes ()
 Get the list of all chromosomes along the genome, with their length. More...
 
std::unordered_map< std::string, size_t > const & chromosomes () const
 Get the list of all chromosomes along the genome, with their length. More...
 
void clear ()
 Clear all data from the Window. More...
 
size_t first_position () const
 Get the first position in the chromosome of the Window, that is, where the Window starts. More...
 
void first_position (size_t value)
 Set the first position in the chromosome of the Window, that is, where the Window starts. More...
 
GenomeRegion genome_region () const
 Return the genome region that this Windows is defined over. More...
 
bool is_whole_genome () const
 Return if this instance is intended to be used for a whole genome stream. More...
 
void is_whole_genome (bool value)
 Set whether this instance is intended to be used for a whole genome stream. More...
 
size_t last_position () const
 Get the last position in the chromosome of the Window, that is, where the Window ends. More...
 
void last_position (size_t value)
 Set the last position in the chromosome of the Window, that is, where the Window ends. More...
 
BaseWindowoperator= (BaseWindow &&)=default
 
BaseWindowoperator= (BaseWindow const &)=default
 
size_t width () const
 Get the width of the Window. More...
 

Public Types

using const_reference = value_type const &
 
using Data = D
 
using iterator_category = std::input_iterator_tag
 
using reference = value_type &
 
using self_type = WindowView< Data >
 
using value_type = Data
 
- Public Types inherited from BaseWindow< D >
using Data = D
 

Public Attributes

std::function< Data *()> get_element
 Function to read the next element from some input source. More...
 
friend Iterator
 

Classes

class  Iterator
 

Additional Inherited Members

- Protected Member Functions inherited from BaseWindow< D >
virtual void clear_ ()
 Virtual clear function for derived classes to clear their data. More...
 

Constructor & Destructor Documentation

◆ WindowView() [1/5]

WindowView ( )
default

◆ WindowView() [2/5]

WindowView ( Window< Data > const &  window)
inline

Constructor that takes a Window window and creates a view into it.

This is just a simple way of "converting" a Window to a WindowView, by having the view access all the data of the Window. This automatically sets the get_element function.

It is required and the users responsibility that the scope of the window outlives this WindowView.

Definition at line 252 of file window_view.hpp.

◆ WindowView() [3/5]

WindowView ( Window< Data > &  window)
inline

Constructor that takes a Window window and creates a view into it.

This is just a simple way of "converting" a Window to a WindowView, by having the view access all the data of the Window. This automatically sets the get_element function.

It is required and the users responsibility that the scope of the window outlives this WindowView.

Definition at line 268 of file window_view.hpp.

◆ ~WindowView()

virtual ~WindowView ( )
overridevirtualdefault

◆ WindowView() [4/5]

WindowView ( WindowView< D > const &  )
default

◆ WindowView() [5/5]

WindowView ( WindowView< D > &&  )
default

Member Function Documentation

◆ begin()

Iterator begin ( ) const
inline

Definition at line 293 of file window_view.hpp.

◆ end()

Iterator end ( ) const
inline

Definition at line 311 of file window_view.hpp.

◆ operator=() [1/2]

WindowView& operator= ( WindowView< D > &&  )
default

◆ operator=() [2/2]

WindowView& operator= ( WindowView< D > const &  )
default

Member Typedef Documentation

◆ const_reference

using const_reference = value_type const&

Definition at line 91 of file window_view.hpp.

◆ Data

using Data = D

Definition at line 84 of file window_view.hpp.

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 87 of file window_view.hpp.

◆ reference

Definition at line 90 of file window_view.hpp.

◆ self_type

Definition at line 85 of file window_view.hpp.

◆ value_type

using value_type = Data

Definition at line 89 of file window_view.hpp.

Member Data Documentation

◆ get_element

std::function<Data*()> get_element

Function to read the next element from some input source.

The return value of the function is expected to be a pointer to the current element in the underlying input source. When called multiple times, the function is expected to advance the underlying iterator first. That also means it usually needs to distinguish between its first call and subsequent calls, which would require incrementing.

Definition at line 330 of file window_view.hpp.

◆ Iterator

friend Iterator

Definition at line 93 of file window_view.hpp.


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