Skip to content

Commit a5dad30

Browse files
committed
fixed a bug with ancient samples + sweeps
1 parent aaaf288 commit a5dad30

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

discoalFunctions.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,13 +2241,20 @@ void admixPopns(int popnSrc, int popnDest1, int popnDest2, double admixProp){
22412241
}
22422242

22432243
//addAncientSample -- adds ancient samples by basically flipping population id of already alloced alleles and sets there time
2244-
void addAncientSample(int lineageNumber, int popnDest, double addTime){
2244+
void addAncientSample(int lineageNumber, int popnDest, double addTime, int stillSweeping, double currentFreq){
22452245
int i;
22462246
int count = 0;
2247+
double rn;
22472248
for(i=0; i < alleleNumber && count < lineageNumber; i++){
22482249
if(nodes[i]->population == (popnDest+1) * -1){
22492250
nodes[i]->population = popnDest;
22502251
nodes[i]->time = addTime;
2252+
if(stillSweeping == 1){
2253+
rn = ranf();
2254+
if(rn<currentFreq){
2255+
nodes[i]->sweepPopn=1;
2256+
}
2257+
}
22512258
//printf("time for %d: %f\n", i, nodes[i]->time);
22522259
popnSizes[popnDest]++;
22532260
count++;
@@ -2358,8 +2365,8 @@ rootedNode *pickNodePopnSweep(int popn,int sp){
23582365

23592366
void printNode(rootedNode *aNode){
23602367
int i;
2361-
printf("node: %p time: %f lLim: %d rLim: %d nancSites: %d popn: %d\n nsites:\n",aNode, aNode->time,aNode->lLim,\
2362-
aNode->rLim, aNode->nancSites, aNode->population );
2368+
printf("node: %p time: %f lLim: %d rLim: %d nancSites: %d popn: %d sweepPopn: %d\n",aNode, aNode->time,aNode->lLim,\
2369+
aNode->rLim, aNode->nancSites, aNode->population, aNode->sweepPopn);
23632370
for(i=0;i<nSites;i++)printf("%d",aNode->ancSites[i]);
23642371
printf("\n");
23652372
}
@@ -2409,6 +2416,13 @@ void printAllNodes(){
24092416
}
24102417
}
24112418

2419+
void printAllActiveNodes(){
2420+
int i;
2421+
for(i = 0 ; i < alleleNumber; i++){
2422+
printNode(nodes[i]);
2423+
}
2424+
}
2425+
24122426
/********** event stuff */
24132427
int compare_events(const void *a,const void *b){
24142428
struct event *pa = (struct event *) a;

discoalFunctions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void errorCheckMutations();
3030

3131
void mergePopns(int popnSrc, int popnDest);
3232
void admixPopns(int popnSrc, int popnDest1, int popnDest2, double admixProp);
33-
void addAncientSample(int lineageNumber, int popnDest, double addTime);
33+
void addAncientSample(int lineageNumber, int popnDest, double addTime, int stillSweeping, double currentFreq);
3434

3535

3636
void recurrentMutAtTime(double cTime,int srcPopn, int sp);
@@ -83,6 +83,7 @@ int isCoalNode(rootedNode *aNode);
8383
void newickRecurse(rootedNode *aNode, float site,float tempTime);
8484
void printTreeAtSite(float site);
8585
void printAllNodes();
86+
void printAllActiveNodes();
8687

8788
unsigned int devrand(void);
8889
int compare_doubles(const void *a,const void *b);

discoal_multipop.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ int main(int argc, const char * argv[]){
131131

132132
currentTime = sweepPhaseEventsConditionalTrajectory(&breakPoints[0], currentTime, nextTime, sweepSite, \
133133
currentFreq, &currentFreq, &activeSweepFlag, alpha, currentSize, sweepMode, f0, uA);
134-
// printf("currentFreqAfter: %f alleleNumber:%d\n",currentFreq,alleleNumber);
135-
// printf("pn0:%d pn1:%d alleleNumber: %d sp1: %d sp2: %d \n", popnSizes[0],popnSizes[1], alleleNumber,sweepPopnSizes[1],
136-
// sweepPopnSizes[0]);
134+
//printf("currentFreqAfter: %f alleleNumber:%d currentTime:%f\n",currentFreq,alleleNumber,currentTime);
135+
//printf("pn0:%d pn1:%d alleleNumber: %d sp1: %d sp2: %d \n", popnSizes[0],popnSizes[1], alleleNumber,sweepPopnSizes[1],
136+
// sweepPopnSizes[0]);
137137
if (currentTime < nextTime)
138138
currentTime = neutralPhaseGeneralPopNumber(&breakPoints[0], currentTime, nextTime, currentSize);
139139

@@ -194,7 +194,9 @@ int main(int argc, const char * argv[]){
194194
break;
195195
case 'A':
196196
currentTime = events[j].time;
197-
addAncientSample(events[j].lineageNumber, events[j].popID, events[j].time);
197+
//printAllActiveNodes();
198+
addAncientSample(events[j].lineageNumber, events[j].popID, events[j].time, activeSweepFlag, currentFreq);
199+
//printAllActiveNodes();
198200
if(activeSweepFlag == 0){
199201
if(recurSweepMode ==0){
200202
currentTime = neutralPhaseGeneralPopNumber(&breakPoints[0], currentTime, nextTime, currentSize);

0 commit comments

Comments
 (0)