-
Notifications
You must be signed in to change notification settings - Fork 1
/
msParamsSubpopTrans.c
76 lines (63 loc) · 1.54 KB
/
msParamsSubpopTrans.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*msParamsSubpop.c **************
/ makes a params file for 2
/ popn scenario
***************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <unistd.h>
#include "../coalLib/ranlib.h"
#include "../pgLib/bedFile.h"
void usage();
unsigned int devrand(void);
int main(int argc, char *argv[]){
int i,n;
long int length, seed1, seed2;
struct bedEl data[50000];
double t1, t2, n1, n2, theta, rho, rhops, thetaps,nAfr;
double pAdmix, tAdmix,xaRatio;
if(argc < 2){
usage();
exit(1);
}
seed1 = (long) abs(devrand() % 2147483399);
seed2 = (long) abs(devrand() % 2147483399);
setall(seed1, seed2);
n = bedFileImport3(argv[1],data);
xaRatio = 1.0;
t1 = atof(argv[2]) * xaRatio;
n1 = atof(argv[3]);
t2 = atof(argv[4]) * xaRatio;
thetaps = atof(argv[5]);
rhops = atof(argv[6]);
for(i = 0; i < n; i++){
length = (data[i].chromEnd) - data[i].chromStart;
theta = length *thetaps;
rho = length*rhops;
//adjust rho
if (rho > 600){
rho = 600;
}
//want theta, rho, length, trec, tbn, tAdmix, pAdmix,
printf("%lf\t%lf\t%ld\t%0.12lf\t%0.12lf\t%0.12lf\t%0.12lf\t%0.12lf\n",theta,rho, length, t1,n1,t2, \
thetaps, rhops);
}
return(0);
}
void usage(){
printf("msParamsSubpopTrans bedFile <5 args>\n");
}
/* used for getting random number seeds */
unsigned int devrand(void) {
int fn;
unsigned int r;
fn = open("/dev/urandom", O_RDONLY);
if (fn == -1)
exit(-1); /* Failed! */
if (read(fn, &r, 4) != 4)
exit(-1); /* Failed! */
close(fn);
return r;
}