44       double t = (beg+2*nsam-2)->time;
    73       for(i=0;i<2*nsam-3;i++)
    75           time += (beg + (beg+i)->abv)->time - (beg+i)->time;
    76           if(time >= rtime) 
return i;
    94       assert( branch <= 2*nsam-2 );
    95       std::vector<int> desc;
    97       for(
int i=0;i<nsam;++i)
    99           for(j=i;j<branch;j=(beg+j)->abv){};
   100           if(j==branch) desc.push_back(i);
   124           assert( (beg+i)->abv != -1 );
   131                               const int & total_number_of_sites )
   143       size_t seg=0,nsegs=sample_history.size();
   144       Sequence::coalsim::arg::const_iterator i = sample_history.begin(),j=i;
   149       for( ; seg < nsegs ; ++seg,++i,++j )
   152           assert( i->beg < total_number_of_sites );
   153           if( i->beg > total_number_of_sites )
   155               throw std::runtime_error(
"Sequence::coalsim::total_time_on_arg - beginning of marginal tree > number of sites simulated");
   158           int end = (seg<nsegs-1) ? j->beg : total_number_of_sites;
   164             double(end-beg)/double(total_number_of_sites);
   177       arg::iterator i = sample_history->begin(),
   180       assert(j->beg > i->beg);
   181       size_t nsegs = sample_history->size();
   182       for(
size_t seg=0;seg<nsegs-1;++seg,++i,++j)
   184           bool same_tree = 
true;
   185           for( marginal::iterator mi = i->end()-1,
   187                same_tree == 
true && (mi >= i->begin() && mj >= j->begin()) ;
   190               if(std::fabs( mi->time - mj->time ) > std::numeric_limits<double>::epsilon() ||
   196           if(same_tree == 
true)
   198               sample_history->erase(j);
   211       std::vector<double> times;
   214       sfs_times_impl() : times(std::vector<double>()),tt(0.),nbins(0){}
   215       sfs_times_impl( 
const sfs_times_impl & s ) :
   216         times(s.times),tt(s.tt),nbins(s.nbins) {}
   217       sfs_times_impl(arg::const_iterator & sample_history_beg,
   218                      const arg::size_type & nsegs,
   219                      const int & total_nsites_simulated,
   221       inline bool operator==(
const sfs_times_impl & rhs)
 const   223         return (this->times==rhs.times &&
   224                 std::fabs(this->tt-rhs.tt)<=std::numeric_limits<double>::epsilon() &&
   225                 this->nbins == rhs.nbins);
   229     sfs_times_impl::sfs_times_impl(arg::const_iterator & sample_history_beg,
   230                                    const arg::size_type & nsegs,
   231                                    const int & total_nsites_simulated,
   233       : times(std::vector<double>(std::vector<double>::size_type((folded==
false) ? sample_history_beg->nsam-1 : 
   234                                                                  (sample_history_beg->nsam/2)),0.)),
   236         nbins(
size_t((folded==
false) ? sample_history_beg->nsam-1 : 
   237                      (sample_history_beg->nsam/2)))
   239       arg::const_iterator i = sample_history_beg,j=i;
   242       for(
unsigned seg = 0; seg < nsegs ; ++seg,++i,++j)
   244           int end = (seg<nsegs-1) ? j->beg : total_nsites_simulated;
   246           const double scale = 
double(end-beg)/double(total_nsites_simulated);
   248           const marginal::const_iterator treebeg = i->begin();
   249           for(
int tip = 0 ; tip < i->nsam ; ++tip)
   252               t = ( (treebeg+((treebeg+tip )->abv))->time - 
   253                     (treebeg+tip)->time)*scale;
   261               t = ( (treebeg+((treebeg+
node )->abv))->time - 
   262                     (treebeg+
node)->time)*scale;
   263               std::vector<int>::size_type index = (folded==
false) ? descendants.size()-1 : 
   264                 std::min(descendants.size(),std::vector<int>::size_type(i->nsam)-descendants.size())-1;
   272     sfs_times::sfs_times() : 
   273       impl(std::unique_ptr<sfs_times_impl>(
new sfs_times_impl()))
   278     sfs_times::sfs_times(
const sfs_times & sfst) : impl(
new sfs_times_impl(*(sfst.impl)))
   285     sfs_times::sfs_times(arg::const_iterator sample_history_beg,
   286                          const arg::size_type & nsegs,
   287                          const int & total_nsites_simulated,
   289       impl(
new sfs_times_impl(sample_history_beg,nsegs,total_nsites_simulated,folded))
   301     sfs_times::~sfs_times()
   305     double sfs_times::operator[](std::vector<double>::size_type 
const & i) 
const   312       assert(i>0 && i<=impl->nbins);
   313       return impl->times[i-1];
   316     sfs_times & sfs_times::operator=(
const sfs_times & rhs)
   321       if(*
this==rhs) 
return *
this;
   322       this->impl->times = rhs.impl->times;
   323       this->impl->tt = rhs.impl->tt;
   324       this->impl->nbins = rhs.impl->nbins;
   328     bool sfs_times::operator==(
const sfs_times & rhs) 
const   333       return ( *(this->impl) == *(rhs.impl) );
   336     double sfs_times::ttime() 
const   344     size_t sfs_times::size() 
const   353     sfs_times::const_iterator sfs_times::begin() 
const   358       return impl->times.begin();
   361     sfs_times::const_iterator sfs_times::end() 
const   366       return impl->times.end();
 std::list< marginal > arg
Ancestral Recombination Graph. 
A point on a marginal tree at which a coalescent event occurs. 
int pick_branch(marginal::const_iterator beg, const int &nsam, const double &rtime)
pick a random branch of a marginal tree 
void minimize_arg(arg *sample_history)
The namespace in which this library resides. 
double total_time(const marginal::const_iterator beg, const int &nsam)
Calculate total time on a marginal tree. 
double total_time_on_arg(const Sequence::coalsim::arg &sample_history, const int &total_number_of_sites)
Returns the total time on an ancestral recombination graph. 
std::vector< int > get_all_descendants(marginal::const_iterator beg, const int &nsam, const int &branch)
Find all the descendants of a branch on a marginal tree. 
bool is_descendant(marginal::const_iterator beg, const int &ind, const int &branch)
Ask if a tip of a tree is a descendant of a particular branch.