WriteResults.h 3.19 KB
Newer Older
1
2
3
4

#ifndef WRITERESULTS_H
#define WRITERESULTS_H

5
6
7
#include <map>
#include <vector>
#include <utility>
8

9
/// Write all results to a given file.
10
11
12
13
14
15
16
17
18
19
20
///
///     @author Mario Valle - Swiss National Supercomputing Centre (CSCS)
///     @date 2012-09-24 (initial version)
///     @version 1.0
///
///
class WriteResults
{
public:
	/// Constructor
	///
21
	/// @param[in] aFilename The filename to which the output should go. If null no printing will happen
22
	///
23
24
	explicit WriteResults(const char* aFilename) : mFilename(aFilename) {}

mvalle's avatar
mvalle committed
25
26
27
28
29
30
31
32
33
	/// Destructor.
	///
	~WriteResults()
	{
		mLnL[0].clear();
		mLnL[1].clear();
		mPositiveSelSites.clear();
	}

34
	/// Output the results to the file given
35
	///
36
	void outputResults(void);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

	/// 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);

54
55
56
57
58
	/// 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; }
59

60
61
62
63
64
65
66
67
	/// 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;

68
69
70
71
72
73
74
75
76

    /// 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);

77
private:
78
	const char*					mFilename;			///< The file to which the results should be written. If null, no printing appear
79
80
81
	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
82
	mutable std::vector<size_t>	mSiteOrder;			///< The new site+prob order computed by orderSites routine
83
84

	std::map<size_t, std::string>	mParamStr[2];			///< The parameters string for the given fg branch and for the two hypothesis
85
86
87
88
};

#endif