forked from StephanePeyregne/ELS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
142 lines (124 loc) · 4.93 KB
/
main.cc
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <popt.h>
#include <time.h>
using namespace std;
#include "hillclimbing.h"
int main(int argc, const char *argv[])
{
// Commandline parameters
int length_internal = 0;
int length_external = 0;
int length_long_external = 0;
double LErate = 0.;
char *configfile = 0;
double prob_fixD_internal = 0.;
double prob_fixD_external = 0.;
double converThrld = 0.1;
bool baum_welch = false;
bool nelderMead = false;
int additionalParameters = 0;
char *logFileName = 0;
double EXTERNAL_ULINDI_DERIVED_PROB = 0.01; // This should be a parameter
struct poptOption optionsTable[] = {
{"length_internal", 'L', POPT_ARG_INT, &length_internal, 0, "Average length of internal region", "length"},
{"length_external", 'l', POPT_ARG_INT, &length_external, 0, "Average length of external region", "length"},
{"emission_probabilities", 'e', POPT_ARG_STRING, &configfile, 0, "Emission probabilities for internal state by frequency", "file"},
{"Baum-Welch", 'B', POPT_ARG_DOUBLE, &converThrld, 0, "Baum-Welch algorithm to re-estimate parameters", "value"},
{"NelderMead", 'N', POPT_ARG_DOUBLE, &converThrld, 0, "NelderMead algorithm", "converThrld"},
{"prob_fixD_internal", 'F', POPT_ARG_DOUBLE, &prob_fixD_internal, 0, "Probability for sharing fixed derived when in an internal region", "prob"},
{"prob_fixD_external", 'f', POPT_ARG_DOUBLE, &prob_fixD_external, 0, "Probability for sharing fixed derived when in an external region", "prob"},
{"length_long_external", 'S', POPT_ARG_INT, &length_long_external, 0, "Average length of long external regions", "length"},
{"long_external_rate", 'r', POPT_ARG_DOUBLE, &LErate, 0, "Proportion of external regions produced by positive selection", "rate"},
{"logfile", 'o', POPT_ARG_STRING, &logFileName, 0, "Set log file name", "path/name"},
POPT_AUTOHELP{NULL, 0, 0, NULL, 0} // Should we change something here?
};
poptContext optCon;
optCon = poptGetContext("sweep_hmm", argc, argv, optionsTable, 0);
poptSetOtherOptionHelp(optCon, "[OPTIONS]* <inputfile>");
int rc = poptGetNextOpt(optCon);
if (rc != -1)
{
poptPrintUsage(optCon, stderr, 0);
return 1;
}
// inputfile present?
const char *infile = poptGetArg(optCon);
if (!infile)
{
cerr << "Error: need inputfile as argument." << endl;
poptPrintUsage(optCon, stderr, 0);
return 1;
}
// all other parameters present?
if (length_internal <= 0 || length_external <= 0 || !configfile || prob_fixD_internal <= 0. || prob_fixD_external <= 0. || prob_fixD_internal >= 1. || prob_fixD_external >= 1.)
{
cerr << "Error: length_internal, length_external, configfile, prob_fixD_internal and prob_fixD_external must be set." << endl;
poptPrintUsage(optCon, stderr, 0);
return 1;
}
// Baum-Welch and/or 3-state algorithm turned on?
for (int i = 0; i < argc; i++)
{
if (strcmp(argv[i], "-B") == 0)
{
baum_welch = true;
}
if ((strcmp(argv[i], "-S") == 0) || (strcmp(argv[i], "-r") == 0))
{
additionalParameters += 1;
}
if (strcmp(argv[i], "-N") == 0)
{
nelderMead = true;
}
}
if (additionalParameters == 1)
{
cerr << "Error: length_long_external and long_external_rate must be both set when using the 3-state model." << endl;
poptPrintUsage(optCon, stderr, 0);
return 1;
}
if (additionalParameters == 0)
{
hillClimbing mAlgorithm(infile, configfile, length_internal, length_external, prob_fixD_internal, prob_fixD_external, EXTERNAL_ULINDI_DERIVED_PROB);
// Si param nom fichier log
if (logFileName != 0)
{
mAlgorithm.setLogFileName(logFileName);
}
if (baum_welch == false)
{
mAlgorithm.hmmOnly();
}
else
{
mAlgorithm.randomSearch(converThrld);
}
}
else if (additionalParameters == 2)
{
hillClimbing mAlgorithm(
infile, configfile, length_internal, length_external, length_long_external, LErate, prob_fixD_internal, prob_fixD_external, EXTERNAL_ULINDI_DERIVED_PROB);
// Si param nom fichier log
if (logFileName != 0)
{
mAlgorithm.setLogFileName(logFileName);
}
if (baum_welch == false && nelderMead == false)
{
mAlgorithm.hmmOnly3states();
}
else if (nelderMead == true)
{
mAlgorithm.nelderMeadSimplex(converThrld);
}
else
{
mAlgorithm.randomSearch3states(converThrld);
}
}
}