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

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

Inherits BaseWindow< D >.

Detailed Description

template<class D, class A = EmptyAccumulator>
class genesis::population::Window< D, A >

Window over the chromosomes of a genome.

This class is a container for the Window::Data (of template type D) that is produced when sliding over the chromosomes of a genome in windows, or filling genomic region windows. It is for example produced by the SlidingIntervalWindowIterator class (and the deprecated SlidingWindowGenerator).

We here define a window to have a first_position() and a last_position() that can be set independently of the content of the window. For example, for a sliding window, they would be determined by the width and stride of the slider. Within that window, entries can be added, as for example found in a variant call file, or other data type along the genome.

For example, we might have a Window between two positions | (e.g., determined by a sliding window), filled with several entries x coming from the underlying data source like this:

-----|--------x-----x-xx---xxxx---xxxx-xxx----|-----

The width() of the window then is the number of bases in the genome between the first_position() and last_position(), that is, the distance between the two | (plus one, due to using inclusive intervals), On the other hand, the span() of the window is the distance between the first and last entry x in the window (again plus one). Furthermore, the entry_count() or size() is the number of entries in that window, that is, the total number of x in the window.

Remark: We use 1-based inclusive intervals to denote genome regions. That means that the numeric values returned from both first_position() and last_position() are both positions that are part of the window.

The class is mostly meant to be used to be read/iterated over, where the data is filled in beforehand (e.g., via the SlidingIntervalWindowIterator), and can then be processed to compute some values for the Window. That is, from the user side, the const access functions are mostly important, while the non-const modification functions are chiefly meant for the code that fills the Window in the first place.

This means that data from an input file has to be copied into the Window first, which is a bit of a waste, but, given that we might want to do things such as sliding windows with stride smaller than window with, probably a necessary cost to have in order to keep the design simple and easy to use.

Definition at line 105 of file window.hpp.

Public Member Functions

 Window ()=default
 
 Window (Window &&)=default
 
 Window (Window const &)=default
 
virtual ~Window () override=default
 
Accumulatoraccumulator ()
 Get the Accumulator data that can be used for speeding up certain window computations. More...
 
Accumulator const & accumulator () const
 Get the Accumulator data that can be used for speeding up certain window computations. More...
 
reference at (size_t index)
 Return a reference to the element at specified location pos, with bounds checking. More...
 
const_reference at (size_t index) const
 Return a reference to the element at specified location pos, with bounds checking. More...
 
iterator begin ()
 Iterator to the begin of the Data Entries. More...
 
const_iterator begin () const
 Const iterator to the begin of the Data Entries. More...
 
bool empty () const
 Return whether the Window is empty, that is, if it does not contain any Entries. More...
 
iterator end ()
 Iterator to the end of the Data Entries. More...
 
const_iterator end () const
 Const iterator to the end of the Data Entries. More...
 
containerentries ()
 Immediate container access to the Data Entries. More...
 
container const & entries () const
 Immediate container access to the Data Entries. More...
 
size_t entry_count () const
 Get the number of D/Data Entries that are stored in the Window. More...
 
Windowoperator= (Window &&)=default
 
Windowoperator= (Window const &)=default
 
reference operator[] (size_t index)
 Return a reference to the element at specified location index. More...
 
const_reference operator[] (size_t index) const
 Return a reference to the element at specified location index. More...
 
double saturation () const
 Get the fraction of entries to window width. More...
 
size_t size () const
 Get the number of D/Data Entries that are stored in the Window. More...
 
size_t span () const
 Get the distance that is spanned by the first and the last variant (entry) in the Window, that is, the number of bases between them (including both). More...
 
void validate () const
 Validate the window data. More...
 
- 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 Accumulator = A
 
using const_iterator = typename container::const_iterator
 
using const_reference = value_type const &
 
using const_reverse_iterator = typename container::const_reverse_iterator
 
using container = std::deque< Entry >
 
using Data = D
 
using difference_type = typename container::difference_type
 
using iterator = typename container::iterator
 
using reference = value_type &
 
using reverse_iterator = typename container::reverse_iterator
 
using self_type = Window< Data, Accumulator >
 
using size_type = typename container::size_type
 
using value_type = Entry
 
- Public Types inherited from BaseWindow< D >
using Data = D
 

Classes

struct  Entry
 Data that is stored per entry that was enqueued in a window. More...
 

Additional Inherited Members

Constructor & Destructor Documentation

◆ Window() [1/3]

Window ( )
default

◆ ~Window()

virtual ~Window ( )
overridevirtualdefault

◆ Window() [2/3]

Window ( Window< D, A > const &  )
default

◆ Window() [3/3]

Window ( Window< D, A > &&  )
default

Member Function Documentation

◆ accumulator() [1/2]

Accumulator& accumulator ( )
inline

Get the Accumulator data that can be used for speeding up certain window computations.

Definition at line 378 of file window.hpp.

◆ accumulator() [2/2]

Accumulator const& accumulator ( ) const
inline

Get the Accumulator data that can be used for speeding up certain window computations.

Definition at line 387 of file window.hpp.

◆ at() [1/2]

reference at ( size_t  index)
inline

Return a reference to the element at specified location pos, with bounds checking.

Definition at line 314 of file window.hpp.

◆ at() [2/2]

const_reference at ( size_t  index) const
inline

Return a reference to the element at specified location pos, with bounds checking.

Definition at line 322 of file window.hpp.

◆ begin() [1/2]

iterator begin ( )
inline

Iterator to the begin of the Data Entries.

Definition at line 330 of file window.hpp.

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Const iterator to the begin of the Data Entries.

Definition at line 338 of file window.hpp.

◆ empty()

bool empty ( ) const
inline

Return whether the Window is empty, that is, if it does not contain any Entries.

Definition at line 246 of file window.hpp.

◆ end() [1/2]

iterator end ( )
inline

Iterator to the end of the Data Entries.

Definition at line 346 of file window.hpp.

◆ end() [2/2]

const_iterator end ( ) const
inline

Const iterator to the end of the Data Entries.

Definition at line 354 of file window.hpp.

◆ entries() [1/2]

container& entries ( )
inline

Immediate container access to the Data Entries.

Definition at line 370 of file window.hpp.

◆ entries() [2/2]

container const& entries ( ) const
inline

Immediate container access to the Data Entries.

Definition at line 362 of file window.hpp.

◆ entry_count()

size_t entry_count ( ) const
inline

Get the number of D/Data Entries that are stored in the Window.

See also
size() for an alias.

Definition at line 227 of file window.hpp.

◆ operator=() [1/2]

Window& operator= ( Window< D, A > &&  )
default

◆ operator=() [2/2]

Window& operator= ( Window< D, A > const &  )
default

◆ operator[]() [1/2]

reference operator[] ( size_t  index)
inline

Return a reference to the element at specified location index.

No bounds checking is performed.

Definition at line 294 of file window.hpp.

◆ operator[]() [2/2]

const_reference operator[] ( size_t  index) const
inline

Return a reference to the element at specified location index.

No bounds checking is performed.

Definition at line 305 of file window.hpp.

◆ saturation()

double saturation ( ) const
inline

Get the fraction of entries to window width.

Definition at line 254 of file window.hpp.

◆ size()

size_t size ( ) const
inline

Get the number of D/Data Entries that are stored in the Window.

See also
entry_count() for an alias.

Definition at line 237 of file window.hpp.

◆ span()

size_t span ( ) const
inline

Get the distance that is spanned by the first and the last variant (entry) in the Window, that is, the number of bases between them (including both).

This is the distance between the positions of the first and the last variant (entry) in the Window, plus one as we are working with closed intervals where both positions are included. It differs from width(), which instead gives the distance between the first and last position as set for the Window (plus one again).

See the class documentation for an example of the difference between the two functions.

Definition at line 277 of file window.hpp.

◆ validate()

void validate ( ) const
inline

Validate the window data.

The function checks that 0 < first_position() <= last_position(), and that all entries in the Window are within first_position() and last_position().

Definition at line 403 of file window.hpp.

Member Typedef Documentation

◆ Accumulator

using Accumulator = A

Definition at line 114 of file window.hpp.

◆ const_iterator

using const_iterator = typename container::const_iterator

Definition at line 198 of file window.hpp.

◆ const_reference

using const_reference = value_type const&

Definition at line 195 of file window.hpp.

◆ const_reverse_iterator

using const_reverse_iterator = typename container::const_reverse_iterator

Definition at line 200 of file window.hpp.

◆ container

using container = std::deque<Entry>

Definition at line 191 of file window.hpp.

◆ Data

using Data = D

Definition at line 113 of file window.hpp.

◆ difference_type

using difference_type = typename container::difference_type

Definition at line 202 of file window.hpp.

◆ iterator

using iterator = typename container::iterator

Definition at line 197 of file window.hpp.

◆ reference

Definition at line 194 of file window.hpp.

◆ reverse_iterator

using reverse_iterator = typename container::reverse_iterator

Definition at line 199 of file window.hpp.

◆ self_type

Definition at line 190 of file window.hpp.

◆ size_type

using size_type = typename container::size_type

Definition at line 203 of file window.hpp.

◆ value_type

using value_type = Entry

Definition at line 193 of file window.hpp.


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