/***** minrec3.c ************************************************ * (modified from Hudson's ms_ss.c and minrec.c) * Generates samples of gametes with given numbers of segsites. Usage: minrec3 npop sample[1] ... sample[npop] nsites segsites r (mig_rate if npop>1) howmany seed1 where these arguments are : npop: Number of subpopulations which make up the total population sample[i]: the sample size from the i th subpopulation (can be zero). nsites: number of sites between which recombination can occur ( # of bp's) segsites: Number of polymorphic sites in the total sample r: recombination rate between ends of segment times 4N mig_rate: migration rate: the fraction of each subpop made up of migrants times 4N. (This argument is left off if npop is one.) howmany: howmany samples to generate. seed1: seed for random number generator Output consists of the command line arguments followed by the following arrays: B'[a] = # of trials with B' = a QS[a] = # of trials with QS = a * ***************************************************************************/ #include "my.h" #include "max.h" #include struct node{ int abv; int ndes; float time; }; struct segl { int beg; struct node *ptree; int next; }; int **gamete; /* Array of 4-gamete test results */ /* New function declarations */ void Fu1 (int a, int b, double *c); double Fu2 (int d, int e, int *f, double *g); int numcmp (double *h, double *i); void printG (double j, int k, double *l); int Min_rec (char **, int, int, int); main(argc,argv) int argc; char *argv[]; { int nsam ,nsites, i, ns, howmany, npop, *config, pop, count, print_flag, narg ; double theta, r, *posit, mig_rate, estimator, gst, alpha, within, between ; char **list, **cmatrix(); FILE *pf, *fopen(); struct runsum est_m, gst_m, within_m, between_m ; double ttot ; int histest[HISTLIM+1], histgst[HISTLIM+1], segsites ; /* New variables, different from Hudson's program */ int a, b, c, ndes, *spectrum, run, lbun, run_total, blist, hlist; int runtemp, singtemp, *num_bunch, *sing_bunch, issame, ctr = 0; int *diff_bunch, *num_hap, *composite, ctime, *spect_temp, *sing; int p, q, *pi, *spect_actual, gtest, *RM, *max_run, maxtemp; double *var_eta, *G_eta, Gdummy, Gactual; char **bunchlist, **haplist; time_t start, finish; clock_t cstart, cfinish; long seed1; int counter = 0; time (&start); cstart = clock(); THINK_C_CL ; if (argc==1) { printf("Usage: \nminrec3 npop samplesize[1] ... samplesize[npop] nsites segsites r"); printf(" (migrate if npop>1) howmany seed1\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]); seed1 = atol (argv[++narg]); srand48 (seed1); /* Initialize random number generator */ lbun = 2; while( pop MAXCHR) perror("nsam too big.\n"); /* Initialize new variables */ bunchlist = (char **) malloc ((unsigned) (nsam * sizeof (char *))); haplist = (char **) malloc ((unsigned) (nsam * sizeof (char *))); for (a=0; a 1) { printf("%f ",mig_rate);} printf("%d %d\n\n",howmany, seed1); list = cmatrix(nsam,segsites+1); posit = (double *)malloc((unsigned)(segsites*sizeof(double))); if(posit==NULL) perror("malloc error. main"); Fu1 (nsam, segsites, var_eta); Gactual = Fu2 (nsam, segsites, spect_actual, var_eta); for (count=0; count maxtemp) maxtemp = run; if (run >= lbun) { /* New bunch found */ ++run_total; ++runtemp; if (ndes == 1 || ndes == (nsam - 1)) ++singtemp; /* Determine if partition type is new */ for (b=0; b < blist; ++b) { for (c=0; c0 && (G_eta[b] == G_eta[b-1]); --b) ; printf("G_eta[%d] = %f\t", b, G_eta[b]); for (b=a+1; (G_eta[b] == G_eta[b+1]) && b<(howmany-2); ++b) ; printf("G_eta[%d] = %f\n", b+1, G_eta[b+1]); } } int Min_rec (char **list, int x, int size, int nsam) { /* Calculate min # rec. events */ int a, b, c, e, gtest, flag = 0; if (size<2 || x >= (size-1)) return (0); for (a=x+1; a 0) return (1); else return (0); } void Fu1 (int nsam, int segsites, double *var_eta) { double *var_xi, *beta, *sigma, *cov, temp, temp2, theta; int i, b; var_xi = (double *) malloc (nsam * sizeof (double)); beta = (double *) malloc (nsam * sizeof (double)); sigma = (double *) malloc (nsam * sizeof (double)); cov = (double *) malloc (nsam * sizeof (double)); temp = 0.0; for (i=1; i0; 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; } } */