1 #ifndef GENESIS_POPULATION_WINDOW_REGION_WINDOW_ITERATOR_H_
2 #define GENESIS_POPULATION_WINDOW_REGION_WINDOW_ITERATOR_H_
45 #include <type_traits>
50 namespace population {
83 template<
class ForwardIterator,
class InputType,
class DataType = InputType>
98 using settings_type = RegionWindowIteratorSettings<InputType, DataType>;
138 ForwardIterator begin, ForwardIterator end
146 throw std::runtime_error(
147 "Need to set RegionWindowIteratorSettings::entry_input_function before using it "
148 "to construct a RegionWindowIterator"
152 throw std::runtime_error(
153 "Need to set RegionWindowIteratorSettings::chromosome_function before using it "
154 "to construct a RegionWindowIterator"
158 throw std::runtime_error(
159 "Need to set RegionWindowIteratorSettings::position_function before using it "
160 "to construct a RegionWindowIterator"
187 return &(window_.front());
192 return &(window_.front());
197 return window_.front();
202 return window_.front();
225 operator bool()
const
227 return ! windows_.empty();
236 return cur_locus_ == it.cur_locus_;
241 return !(*
this == other);
253 if( cur_locus_ == end_locus_ ) {
259 window_.chromosome( settings_.chromosome_function( *cur_locus_ ));
260 is_first_window_ =
true;
261 is_last_window_ =
false;
264 if( settings_.emit_leading_empty_windows ) {
265 cur_locus_start_ = 1;
269 auto const pos = settings_.position_function( *cur_locus_ );
270 cur_locus_start_ = pos - (( pos - 1 ) % settings_.stride );
278 auto const cur_chr = windows_.front().chromosome();
281 windows_.pop_front();
285 if( windows_.empty() ) {
289 nope not
if we are already at the next chr...
292 cur_locus_ != end_locus_ &&
299 if( cur_locus_ == end_locus_ ) {
316 auto const& tree = parent_->region_list_->get_chromosome_regions( new_chr );
317 if( tree.begin() != tree.end() ) {
318 cur_region_ = tree.begin();
319 end_region_ = tree.end();
327 while( cur_locus_ != end_locus_ ) {
333 while( cur_region_ != end_region_ && cur_region_->interval().within( cur_pos )) {
336 windows_.emplace_back();
337 auto& window = windows_.back();
338 window.chromosome( cur_chr );
339 window.first_position( cur_region_.->interval().low() );
340 window.last_position( cur_region_->interval().high() );
348 cur_region_ == end_region_ ||
349 cur_region_->interval().low() >= window.first_position()
354 for(
auto& window : windows_ ) {
358 assert( cur_chr == window.chromosome() );
359 assert( cur_pos >= window.first_position() );
362 if( cur_pos <= window.last_position() ) {
363 window.entries().emplace_back(
385 RegionWindowIterator<>
const* parent_ =
nullptr;
388 ForwardIterator cur_locus_;
389 ForwardIterator end_locus_;
390 size_t cur_index_ = 0;
397 std::deque<Window> windows_;
410 ForwardIterator begin, ForwardIterator end
454 bool skip_empty_regions =
true;
463 #endif // include guard