24 #include <Sequence/Coalescent/Coalesce.hpp> 31 const int & pos,
unsigned * offset )
50 for( ; (seg+*offset)->beg <= pos && (*offset) < nsegs; ++(*offset) )
51 if ((seg+*offset)->end>=pos)
return true;
57 const int & current_nsam,
62 std::vector<chromosome> * sample,
92 int ch1=(c1<c2)?c1:c2, ch2=(c2>c1)?c2:c1;
94 assert( (sample->begin()+ch1)->nsegs>0 );
95 assert( (sample->begin()+ch2)->nsegs>0 );
97 std::vector<chromosome>::iterator sbegin=sample->begin();
100 ch2beg=(sbegin+ch2)->begin();
101 unsigned seg1=0,seg2=0;
108 int k=0,nsegs=int(sample_history->size());
109 arg::iterator imarg = sample_history->begin(),
112 for ( ; k<nsegs ; ++imarg,++jmarg,++k )
116 bool yes1 =
isseg(ch1beg,(sbegin+ch1)->nsegs,imarg->beg,&seg1);
117 bool yes2 =
isseg(ch2beg,(sbegin+ch2)->nsegs,imarg->beg,&seg2);
121 (tsp+tseg)->beg = imarg->beg;
122 (tsp+tseg)->end = (k<(nsegs-1)) ? jmarg->beg-1 : nsites-1;
127 if( imarg->nnodes >= (2*ttl_nsam-2))
133 (tsp+tseg)->desc = imarg->nnodes;
135 marginal::iterator mi = imarg->begin();
136 (mi+imarg->nnodes)->time = time;
137 (mi+(ch1beg+seg1)->desc)->abv = imarg->nnodes;
138 (mi+(ch2beg+seg2)->desc)->abv = imarg->nnodes;
139 assert( (mi+(ch1beg+seg1)->desc)->abv <=
int(2*ttl_nsam-2) );
140 assert( (mi+(ch2beg+seg2)->desc)->abv <=
int(2*ttl_nsam-2) );
144 (tsp+tseg)->desc = (yes1==
true) ? (ch1beg+seg1)->desc : (ch2beg+seg2)->desc;
145 assert( (tsp+tseg)->desc < 2*ttl_nsam-1 );
149 *nlinks -= (sbegin+ch1)->links();
154 (sbegin+ch1)->swap_with(*(sbegin+current_nsam-1));
155 if(ch2 == current_nsam-1)
160 assert( (sbegin+ch1)->nsegs>0 );
161 assert( (sbegin+ch2)->nsegs>0 );
165 assert( (sbegin+ch1) < sample->end() );
166 (sbegin+ch1)->assign_allocated_segs(tsp,
unsigned(tseg+1));
167 *nlinks += (sbegin+ch1)->links();
170 *nlinks -= (sbegin+ch2)->links();
171 (sbegin+ch2)->swap_with(*(sbegin+current_nsam-1-flag));
172 return ((tseg<0)?2:1);
std::list< marginal > arg
Ancestral Recombination Graph.
The namespace in which this library resides.
bool isseg(chromosome::const_iterator seg, const unsigned &nsegs, const int &pos, unsigned *offset)
ask if a chromosome beginning at seg and containing nsegs contains a segment containing the position ...
A portion of a recombining chromosome.
int coalesce(const double &time, const int &ttl_nsam, const int ¤t_nsam, const int &c1, const int &c2, const int &nsites, int *nlinks, std::vector< chromosome > *sample, arg *sample_history)
Common ancestor routine for coalescent simulation. Merges chromosome segments and updates marginal tr...