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

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

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 104 of file window.hpp.

Public Member Functions

 Window ()=default
 
 Window (Window &&)=default
 
 Window (Window const &)=default
 
 ~Window ()=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...
 
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...
 
void clear ()
 Clear all data from the Window. 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...
 
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...
 
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...
 
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...
 
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
 

Classes

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

Constructor & Destructor Documentation

◆ Window() [1/3]

Window ( )
default

◆ ~Window()

~Window ( )
default

◆ 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 477 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 486 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 413 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 421 of file window.hpp.

◆ begin() [1/2]

iterator begin ( )
inline

Iterator to the begin of the Data Entries.

Definition at line 429 of file window.hpp.

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Const iterator to the begin of the Data Entries.

Definition at line 437 of file window.hpp.

◆ chromosome() [1/2]

std::string const& chromosome ( ) const
inline

Get the chromosome name that this Window belongs to.

Definition at line 224 of file window.hpp.

◆ chromosome() [2/2]

void chromosome ( std::string const &  value)
inline

Set the chromosome name that this Window belongs to.

Definition at line 232 of file window.hpp.

◆ clear()

void clear ( )
inline

Clear all data from the Window.

Definition at line 526 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 286 of file window.hpp.

◆ end() [1/2]

iterator end ( )
inline

Iterator to the end of the Data Entries.

Definition at line 445 of file window.hpp.

◆ end() [2/2]

const_iterator end ( ) const
inline

Const iterator to the end of the Data Entries.

Definition at line 453 of file window.hpp.

◆ entries() [1/2]

container& entries ( )
inline

Immediate container access to the Data Entries.

Definition at line 469 of file window.hpp.

◆ entries() [2/2]

container const& entries ( ) const
inline

Immediate container access to the Data Entries.

Definition at line 461 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 267 of file window.hpp.

◆ first_position() [1/2]

size_t first_position ( ) const
inline

Get the first position in the chromosome of the Window, that is, where the Window starts.

The first and last position in the Window are determined for example by the sliding window width and stride, or by a genomic region that the window represents. They are hence independent of the actual data entries stored in the window, but obviously should be covering their positions. See the Window class documentation for an example.

We use 1-based coordinates and closed intervals, where both the first and the last position are inclusive.

Definition at line 338 of file window.hpp.

◆ first_position() [2/2]

void first_position ( size_t  value)
inline

Set the first position in the chromosome of the Window, that is, where the Window starts.

The first and last position in the Window are determined for example by the sliding window width and stride, or by a genomic region that the window represents. They are hence independent of the actual data entries stored in the window, but obviously should be covering their positions. See the Window class documentation for an example.

We use 1-based coordinates and closed intervals, where both the first and the last position are inclusive.

Definition at line 348 of file window.hpp.

◆ genome_region()

GenomeRegion genome_region ( ) const
inline

Return the genome region that this Windows is defined over.

This is a convenience function that gives the chromosome(), as well as first_position() and last_position(), combined into a GenomeRegion object, for ease of use.

Definition at line 379 of file window.hpp.

◆ last_position() [1/2]

size_t last_position ( ) const
inline

Get the last position in the chromosome of the Window, that is, where the Window ends.

The first and last position in the Window are determined for example by the sliding window width and stride, or by a genomic region that the window represents. They are hence independent of the actual data entries stored in the window, but obviously should be covering their positions. See the Window class documentation for an example.

We use 1-based coordinates and closed intervals, where both the first and the last position are inclusive.

Definition at line 358 of file window.hpp.

◆ last_position() [2/2]

void last_position ( size_t  value)
inline

Set the last position in the chromosome of the Window, that is, where the Window ends.

The first and last position in the Window are determined for example by the sliding window width and stride, or by a genomic region that the window represents. They are hence independent of the actual data entries stored in the window, but obviously should be covering their positions. See the Window class documentation for an example.

We use 1-based coordinates and closed intervals, where both the first and the last position are inclusive.

Definition at line 368 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 393 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 404 of file window.hpp.

◆ saturation()

double saturation ( ) const
inline

Get the fraction of entries to window width.

Definition at line 294 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 277 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 315 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 502 of file window.hpp.

◆ width()

size_t width ( ) const
inline

Get the width of the Window.

This is the distance between first_position() and last_position(), i.e., the distance between the start of the Window and its end as denoted by these positions, plus one, as we are using closed intervals where both positions are included.

See span() for a function that computes the distance between the positions of the first and last entry in the window instead, which might be smaller than the width, if there are no entries in the beginning or end of the window.

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

Definition at line 250 of file window.hpp.

Member Typedef Documentation

◆ Accumulator

using Accumulator = A

Definition at line 113 of file window.hpp.

◆ const_iterator

using const_iterator = typename container::const_iterator

Definition at line 197 of file window.hpp.

◆ const_reference

using const_reference = value_type const&

Definition at line 194 of file window.hpp.

◆ const_reverse_iterator

using const_reverse_iterator = typename container::const_reverse_iterator

Definition at line 199 of file window.hpp.

◆ container

using container = std::deque<Entry>

Definition at line 190 of file window.hpp.

◆ Data

using Data = D

Definition at line 112 of file window.hpp.

◆ difference_type

using difference_type = typename container::difference_type

Definition at line 201 of file window.hpp.

◆ iterator

using iterator = typename container::iterator

Definition at line 196 of file window.hpp.

◆ reference

Definition at line 193 of file window.hpp.

◆ reverse_iterator

using reverse_iterator = typename container::reverse_iterator

Definition at line 198 of file window.hpp.

◆ self_type

Definition at line 189 of file window.hpp.

◆ size_type

using size_type = typename container::size_type

Definition at line 202 of file window.hpp.

◆ value_type

using value_type = Entry

Definition at line 192 of file window.hpp.


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