void add_fixations(sample_t &sample, const vec_mutation_t &fixations, const unsigned nsam, const sugar::treat_neutral treat, const std::pair<double, double> &boundary) { for (const auto &f : fixations) { if (f.pos >= boundary.first && f.pos < boundary.second) { if (treat == sugar::treat_neutral::ALL) { sample.emplace_back(f.pos, std::string(nsam, '1')); } else if (treat == sugar::treat_neutral::NEUTRAL && f.neutral) { // only add neutral mutations sample.emplace_back(f.pos, std::string(nsam, '1')); } else if (treat == sugar::treat_neutral::SELECTED && !f.neutral) { // only add selected mutations sample.emplace_back(f.pos, std::string(nsam, '1')); } } } }
void update_sample_block(sample_t & block, const gamete_mcont_t & variants, const mcont_t & mutations, const size_t & i, const size_t & n, const pos_finder & pf, const size_t & offset = 0, const size_t & scalar = 2) { for( const auto & m : variants ) { auto mutpos = mutations[m].pos; auto itr = std::find_if(block.begin(),block.end(),std::bind(pf,std::placeholders::_1,mutpos)); if( itr == block.end() ) { block.push_back( std::make_pair(mutpos,std::string(n,'0')) ); block[block.size()-1].second[scalar*i+offset] = '1'; } else { itr->second[scalar*i+offset]='1'; } } }
void finish_sample(sample_t &sample, const vec_mutation_t &fixations, const unsigned nsam, const bool removeFixed, const sugar::treat_neutral treat) { if (!removeFixed) { add_fixations(sample, fixations, nsam, treat); } std::sort(sample.begin(), sample.end(), [](const sample_site_t &a, const sample_site_t &b) noexcept { return a.first < b.first; }); if (!removeFixed) { sample.erase(std::unique(sample.begin(), sample.end()), sample.end()); } }