-
Notifications
You must be signed in to change notification settings - Fork 0
/
WriteResults.h
205 lines (172 loc) · 6.78 KB
/
WriteResults.h
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef WRITERESULTS_H
#define WRITERESULTS_H
#include <map>
#include <set>
#include <vector>
#include <utility>
/// Write all results to a given file.
///
/// @author Mario Valle - Swiss National Supercomputing Centre (CSCS)
/// @date 2012-09-24 (initial version)
/// @version 1.1
///
///
class WriteResults {
public:
/// Constructor
///
/// @param[in] aFilename The filename to which the output should go. If null
/// no printing will happen
///
explicit WriteResults(const char *aFilename) : mFilename(aFilename) {}
/// Destructor.
///
~WriteResults() {
mLnL[0].clear();
mLnL[1].clear();
mPositiveSelSites.clear();
}
/// Output the results to the file given
/// @param[in] aIbSet Set of internal branches
/// @param[in] aBranchAll Whether fg branches are just internal or internals+leaves
///
void outputResults(std::set<int> aIbSet, bool aBranchAll);
/// Save the likelihood for later printing.
///
/// @param[in] aFgBranch The foreground branch to which the log-likelihood
/// refers
/// @param[in] aLnL The log-likelihood
/// @param[in] aHypothesis The hypothesis (0 for H0 and 1 for H1) for which
/// the log-likelihood has been computed
///
void saveLnL(size_t aFgBranch, double aLnL, unsigned int aHypothesis);
/// Save the positive selection sites and corresponding probabilities for
/// later printing.
///
/// @param[in] aFgBranch The foreground branch to which the sites refers
/// @param[in] aPositiveSelSites The site in which the positive selection
/// appears as computed by the BEB test
/// @param[in] aPositiveSelSitesProb The corresponding probability as computed
/// by the BEB test
///
void savePositiveSelSites(size_t aFgBranch,
const std::vector<unsigned int> &aPositiveSelSites,
const std::vector<double> &aPositiveSelSitesProb);
/// Check if anything will be output at the end.
///
/// @return True if the output to file is enabled.
///
bool isWriteResultsEnabled(void) const { return mFilename != NULL; }
/// Returns the correct index order to have the sites printed in the correct
/// order.
///
/// @param[in] aSites The vector of site numbers
///
/// @return The list of indices that gives the sites in the correct order.
///
const std::vector<size_t> &
orderSites(const std::vector<unsigned int> &aSites) const;
/// Save the parameters string for later printing.
///
/// @param[in] aFgBranch The foreground branch to which the log-likelihood
/// refers
/// @param[in] aParamStr The parameters string
/// @param[in] aHypothesis The hypothesis (0 for H0 and 1 for H1) for which
/// the log-likelihood has been computed
///
void saveParameters(size_t aFgBranch, std::string &aParamStr,
unsigned int aHypothesis);
private:
const char *mFilename; ///< The file to which the results should be written.
/// If null, no printing appear
std::map<size_t, double> mLnL[2]; ///< The log-likelihood for the given fg
/// branch and for the two hypothesis
std::map<size_t, std::pair<std::vector<unsigned int>, std::vector<double> > >
mPositiveSelSites; ///< The sites under positive selection and the
/// corresponding probabilities for a given fg branch
mutable std::vector<size_t>
mSiteOrder; ///< The new site+prob order computed by orderSites routine
std::map<size_t, std::string> mParamStr[2]; ///< The parameters string for the
/// given fg branch and for the two
/// hypothesis
};
/// Write all results to a given file for the case of fg branches marked in nwk file.
class WriteResultsMfg {
public:
/// Constructor
///
/// @param[in] aFilename The filename to which the output should go. If null
/// no printing will happen
///
explicit WriteResultsMfg(const char *aFilename) : mFilename(aFilename) {}
/// Destructor.
///
~WriteResultsMfg() {
mLnL[0].clear();
mLnL[1].clear();
mPositiveSelSites.clear();
}
/// Output the results to the file given
/// @param[in] aFgSet The set of marked fg branches
///
void outputResults(std::set<int> aFgSet);
/// Save the likelihood for later printing.
///
/// @param[in] aFgBranchSet The marked foreground branches to which the log-likelihood
/// refers
/// @param[in] aLnL The log-likelihood
/// @param[in] aHypothesis The hypothesis (0 for H0 and 1 for H1) for which
/// the log-likelihood has been computed
///
void saveLnL(std::set<int> aFgBranchSet, double aLnL, unsigned int aHypothesis);
/// Save the positive selection sites and corresponding probabilities for
/// later printing.
///
/// @param[in] aFgBranchSet The marked foreground branches to which the sites refers
/// @param[in] aPositiveSelSites The site in which the positive selection
/// appears as computed by the BEB test
/// @param[in] aPositiveSelSitesProb The corresponding probability as computed
/// by the BEB test
///
void savePositiveSelSites(std::set<int> aFgBranchSet,
const std::vector<unsigned int> &aPositiveSelSites,
const std::vector<double> &aPositiveSelSitesProb);
/// Check if anything will be output at the end.
///
/// @return True if the output to file is enabled.
///
bool isWriteResultsEnabled(void) const { return mFilename != NULL; }
/// Returns the correct index order to have the sites printed in the correct
/// order.
///
/// @param[in] aSites The vector of site numbers
///
/// @return The list of indices that gives the sites in the correct order.
///
const std::vector<size_t> &
orderSites(const std::vector<unsigned int> &aSites) const;
/// Save the parameters string for later printing.
///
/// @param[in] aFgBranchSet The marked foreground branches to which the log-likelihood
/// refers
/// @param[in] aParamStr The parameters string
/// @param[in] aHypothesis The hypothesis (0 for H0 and 1 for H1) for which
/// the log-likelihood has been computed
///
void saveParameters(std::set<int> aFgBranchSet, std::string &aParamStr,
unsigned int aHypothesis);
private:
const char *mFilename; ///< The file to which the results should be written.
/// If null, no printing appear
std::map<size_t, double> mLnL[2]; ///< The log-likelihood for the given marekd fg
/// branches and for the two hypothesis
std::map<size_t, std::pair<std::vector<unsigned int>, std::vector<double> > >
mPositiveSelSites; ///< The sites under positive selection and the
/// corresponding probabilities for a given marked fg branches
mutable std::vector<size_t>
mSiteOrder; ///< The new site+prob order computed by orderSites routine
std::map<size_t, std::string> mParamStr[2]; ///< The parameters string for the
/// given marked fg branches and for the two
/// hypothesis
};
#endif