sample_t sample( gsl_rng * r, const poptype & p, const unsigned deme, const unsigned nsam, const bool removeFixed ) /*! Take a random sample of nsam chromosomes from a meta-population \param r A random-number generator \param p A population \param p the index of the deme to sample \param nsam The sample size \param removeFixed Whether or not to remove variants present in all nsam chromosomes \return A vector of both neutral and non-neutral variants */ { static_assert( std::is_same<typename poptype::popmodel_t,sugar::METAPOP_TAG>::value, "METAPOP_TAG required"); if(deme >= p.diploids.size()) { throw std::out_of_range("KTfwd::sample_separate: deme index out of range"); } auto temp = ms_sample_separate(r,p.mutations,p.gametes,p.diploids[deme],nsam,removeFixed); auto rv = std::move(temp.first); std::move(temp.second.begin(),temp.second.end(),std::back_inserter(rv)); std::sort(rv.begin(),rv.end(),[](const sample_site_t & a, const sample_site_t & b){ return a.first<b.first; }); if(!removeFixed) add_fixations(&rv,p.fixations,nsam,sugar::treat_neutral::ALL); return rv; }
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()); } }