/***** hrmpg2.c ************************************************ * (modified from Hudson's ms_ss.c and rmhap_lik.c) Generates samples with specified number of segregating sites and calculates the distributions of the number of haplotypes (W) and the minimum number of inferred recombination events (RM). Does this for all specified values of 4Nr. Calculates MLE of 4Nr based on W alone, RM alone, and both. Note that likW[nsam] diverges, so we arbitrarily set likW[nsam] = likW[nsam - 1]. Model of exp. growth considered. Usage: hrmpg2 npop samplesize[1] . . . samplesize[npop] nsites segsites Rmin Rmax pts alpha t0(if alpha!=0.0) (migrate if npop>1) howmany where these arguments are: npop: Number of populations samplesize[i]: Number of individuals sampled from the i-th island nsites: Number of sites between which recombination can occur (# of bp's) segsites: Number of polymorphic sites in the total sample Rmin: Minimum value of 4Nr considered. Rmax: Maximum value of 4Nr considered. pts: Number of different values of 4Nr considered. alpha: Growth rate t0: Time (in units of 4N generations, where N is the current pop. size) since the start of growth howmany: Howmany samples to generate. Output consists of the command line arguments followed by the following variables and arrays: likW[a] = value of 4Nr that maximizes the likelihood of observing exactly a different haplotypes. likRM[a] = value of 4Nr that maximizes the likelihood of observing RM = a. likRMW[a][b] = value of 4Nr that maximizes the likelihood of observing RM = a and W = b. hap[a][b] = number of trials with 4Nr = Rmin + a * (Rmax - Rmin) / (pts - 1) with exactly b different haplotypes. RM[a][b] = number of trials with 4Nr = Rmin + a * (Rmax - Rmin) / (pts - 1) with RM = b. RMhap[a][b][c] = # of trials with 4Nr = Rmin + a * (Rmax - Rmin) / (pts - 1) with RM = b and W = c. * ***************************************************************************/ #include "my.h" #define SITESINC 10 #define SSMAX 1000 #include unsigned maxsites = SITESINC; struct node{ int abv; int ndes; float time; }; struct segl { int beg; struct node *ptree; int next; }; double *posit; char **haplist; /* Dummy variable used in hapcount */ /* New function declarations */ int hapcount (char **p, int q, int r, int s); int min_rec (char **a, int b, int c, int d, int e); main(argc,argv) int argc; char *argv[]; { int nsam ,nsites, i, ns, howmany, npop, *config, pop, count, print_flag, narg ; double theta, r, mig_rate, estimator, gst, alpha, within, between ; char **list, **cmatrix(); FILE *pf, *fopen(), *pfseed; struct runsum est_m, gst_m, within_m, between_m ; double ttot, alphag, t0; int segsites; unsigned short seedv[3], *pseed, *seed48(); /* New variables, different from Hudson's program */ int **hap, **RM, ***RMhap, a, b, c, d, x, pts, ctime, dummy, dummy2; int Hctr, Wctr, RMctr, RMWctr, Wmax, RMmax, RMWmax; double *likW, *likRM, **likRMW, R, Rmin, Rmax, C, chud(); double Hsum, Hsqrsum, Hmsesum, Hmean, Hmeansqr, Hvar, Hmse; double Wsum, Wsqrsum, Wmsesum, Wmean, Wmeansqr, Wvar, Wmse; double RMsum, RMsqrsum, RMmsesum, RMmean, RMmeansqr, RMvar, RMmse; double RMWsum, RMWsqrsum, RMWmsesum, RMWmean, RMWmeansqr, RMWvar, RMWmse; time_t start, finish; clock_t cstart, cfinish; long seed1; int Min_rec(); time (&start); cstart = clock(); THINK_C_CL ; if (argc == 1) { printf("Usage: \nhrmpg2.1 npop samplesize[1] . . . samplesize[npop] nsites segsites Rmin Rmax pts alpha t0(if alpha!=0.0) (migrate if npop>1) howmany\n"); exit(0); } npop = atoi( argv[1] ); config = (int *)malloc((unsigned)((npop+1)*sizeof(int))); for( pop=0, narg=1 ; pop 1 ) mig_rate = atof( argv[++narg]); else mig_rate = 0.0 ; howmany = atoi( argv[++narg]); pfseed = fopen("seedms","r"); for(i=0;i<3;i++) fscanf(pfseed," %hd",seedv+i); fclose( pfseed); seed48( seedv ); while( pop 1) { printf("%f ",mig_rate);} printf("%d %d %d %d\n",howmany, seedv[0], seedv[1], seedv[2] ); maxsites = segsites +2; list = cmatrix(nsam,maxsites+1); posit = (double *)malloc((unsigned)(maxsites*sizeof(double))); if(posit==NULL) perror("malloc error. main"); for (x=0; xhap[b][a]) b = c; if (hap[b][a]>0) likW[a] = Rmin + (b * (Rmax - Rmin)) / (float) (pts - 1); else likW[a] = -1.0; } likW[nsam] = likW[nsam - 1]; for (a=0; aRM[b][a]) b = c; if (RM[b][a]>0) likRM[a] = Rmin + (b * (Rmax - Rmin)) / (float) (pts - 1); else likRM[a] = -1.0; } for (d=0; dRMhap[b][d][a]) b = c; if (RMhap[b][d][a]>0) likRMW[d][a] = Rmin + (b * (Rmax - Rmin)) / (float) (pts - 1); else likRMW[d][a] = -1.0; } } time (&finish); cfinish = clock(); ctime = (cfinish - cstart) / CLOCKS_PER_SEC; printf("\n"); printf("Runtime, ctime = %d %d\n\n", (finish - start), ctime); for (a=2; a<=nsam; ++a) printf("likW[%d] = %f\n", a, likW[a]); printf("\n"); for (a=0; a0; gap /= 2) for( i=gap; i=0 && pbuf[j]>pbuf[j+gap]; j -=gap) { temp = pbuf[j]; pbuf[j] = pbuf[j+gap]; pbuf[j+gap] = temp; } } */