|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_POPULATION_WINDOW_WINDOW_H_
2 #define GENESIS_POPULATION_WINDOW_WINDOW_H_
43 namespace population {
103 template<
class D,
class A = EmptyAccumulator>
253 if( first_position_ > last_position_ ) {
254 throw std::runtime_error(
255 "Invalidly set first and last position in the Window, with " +
259 return last_position_ - first_position_ + 1;
269 return entries_.size();
279 return entries_.size();
288 return entries_.empty();
296 double const frac =
static_cast<double>( entries_.size() ) /
static_cast<double>(
width() );
298 assert(
width() > 0 );
299 assert( frac >= 0.0 );
300 assert( frac <= 1.0 );
317 if( entries_.empty() ) {
320 return entries_.back().position - entries_.front().position + 1;
340 return first_position_;
350 first_position_ = value;
360 return last_position_;
370 last_position_ = value;
381 return { chromosome_, first_position_, last_position_ };
395 assert( index < entries_.size() );
396 return entries_[ index ];
406 assert( index < entries_.size() );
407 return entries_[ index ];
415 return entries_.at( index );
423 return entries_.at( index );
431 return entries_.begin();
439 return entries_.begin();
447 return entries_.end();
455 return entries_.end();
504 if( first_position_ == 0 ) {
505 throw std::runtime_error(
"Invalid Window with first_position() == 0." );
507 if( last_position_ < first_position_ ) {
508 throw std::runtime_error(
"Invalid Window with last_position() < first_position()." );
510 for(
auto const& entry : entries_ ) {
511 if( entry.position < first_position_ || entry.position > last_position_ ) {
512 throw std::runtime_error(
513 "Invalid Window::Entry in chromosome " + chromosome_ +
" at position " +
515 ", which is not between the window boundaries [" +
541 std::string chromosome_;
542 size_t first_position_ = 0;
543 size_t last_position_ = 0;
553 #endif // include guard
Accumulator & accumulator()
Get the Accumulator data that can be used for speeding up certain window computations.
reference operator[](size_t index)
Return a reference to the element at specified location index.
const_reference at(size_t index) const
Return a reference to the element at specified location pos, with bounds checking.
Window over the chromosomes of a genome.
size_t position
Genomic position (1-based) of the entry along a chromosome.
void validate() const
Validate the window data.
size_t index
Index of the entry, that is, how many other entries have there been in total in the underlying data f...
void last_position(size_t value)
Set the last position in the chromosome of the Window, that is, where the Window ends.
size_t entry_count() const
Get the number of D/Data Entries that are stored in the Window.
size_t size() const
Get the number of D/Data Entries that are stored in the Window.
Accumulator const & accumulator() const
Get the Accumulator data that can be used for speeding up certain window computations.
std::string to_string(GenomeLocus const &locus)
Entry(size_t index, size_t position, Data const &data)
Contructor that takes data by reference.
Data data
Data stored in the Window for this entry.
size_t last_position() const
Get the last position in the chromosome of the Window, that is, where the Window ends.
iterator end()
Iterator to the end of the Data Entries.
typename container::const_reverse_iterator const_reverse_iterator
bool empty() const
Return whether the Window is empty, that is, if it does not contain any Entries.
container const & entries() const
Immediate container access to the Data Entries.
size_t span() const
Get the distance that is spanned by the first and the last variant (entry) in the Window,...
const_reference operator[](size_t index) const
Return a reference to the element at specified location index.
Empty helper data struct to serve as a dummy for Window.
typename container::size_type size_type
GenomeRegion genome_region() const
Return the genome region that this Windows is defined over.
std::deque< Entry > container
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Data that is stored per entry that was enqueued in a window.
Entry(size_t index, size_t position, Data &&data)
Contructor that takes data by r-value reference (i.e., moved data); preferred if possible to use,...
reference at(size_t index)
Return a reference to the element at specified location pos, with bounds checking.
void chromosome(std::string const &value)
Set the chromosome name that this Window belongs to.
size_t width() const
Get the width of the Window.
typename container::difference_type difference_type
void first_position(size_t value)
Set the first position in the chromosome of the Window, that is, where the Window starts.
container & entries()
Immediate container access to the Data Entries.
const_iterator begin() const
Const iterator to the begin of the Data Entries.
const_iterator end() const
Const iterator to the end of the Data Entries.
Window & operator=(Window const &)=default
A region (between two positions) on a chromosome.
size_t first_position() const
Get the first position in the chromosome of the Window, that is, where the Window starts.
typename container::const_iterator const_iterator
void clear()
Clear all data from the Window.
iterator begin()
Iterator to the begin of the Data Entries.
std::string const & chromosome() const
Get the chromosome name that this Window belongs to.
typename container::reverse_iterator reverse_iterator
double saturation() const
Get the fraction of entries to window width.
typename container::iterator iterator
value_type const & const_reference