-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmodeltest_d.c
77 lines (56 loc) · 1.46 KB
/
modeltest_d.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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include "d_model.h"
////* Usage and main *////
static int usage(char **argv)
{
printf("\nUsage: %s %s file.bin\n\n", argv[-1], argv[0]);
return 1;
}
int dmodel_main(int argc, char **argv)
{
if (argc < 2) {
return usage(argv);
}
char *in = argv[1];
const double a1[4] = {1, 0, 0, 0};
const double m1[3] = {0.5, 0, 0};
const double a2[4] = {0.5, 0.5, 0, 0};
const double m2[3] = {0.33, 0.67, 0};
const double a3[4] = {0.33, 0.33, 0.33, 0};
const double m3[3] = {0.25, 0.5, 0.75};
const double w[3] = {0.01, 0.01, 0.01};
int f = 0; f |= 4;
FILE *file = NULL;
file = fopen(in, "rb");
if (!file) {
printf("Can't open input file: %s\n\n", argv[1]);
return usage(argv);
}
all_f *arr = NULL;
arr = read_arr(file);
em_data em;
em.arr = arr;
setup_EMstr(&em, a1, m1, w, f);
run_EM(&em);
printf("\nfinal diploid loglik: %f\n", em.ll);
printf(" sd1 = %f\n", em.w[0]);
setup_EMstr(&em, a2, m2, w, f);
run_EM(&em);
printf("\nfinal triploid loglik: %f\n", em.ll);
printf(" sd1 = %f\n", em.w[0]);
printf(" sd2 = %f\n", em.w[1]);
setup_EMstr(&em, a3, m3, w, f);
run_EM(&em);
printf("\nfinal tetraploid loglik: %f\n", em.ll);
printf(" sd1 = %f\n", em.w[0]);
printf(" sd2 = %f\n", em.w[1]);
printf(" sd3 = %f\n", em.w[2]);
printf("\n");
fclose(file);
free_arr(arr);
return 0;
}