Commit d6205ef5 authored by omid's avatar omid
Browse files

Some correction in reporting the final tree (based on the chosen

hypothesis)
parent 78a52c80
......@@ -93,7 +93,7 @@ int main(int aRgc, char **aRgv) {
// std::cout<<"num of thr: "<< num_threads <<std::endl;
omp_set_num_threads(num_threads);
/*if (num_threads < 2)
/*if (num_threads < 2)
cmd.mForceSerial = true;
else
cmd.mForceSerial = false;*/
......@@ -103,7 +103,7 @@ int main(int aRgc, char **aRgv) {
cmd.mForceSerial = true;
#endif
/*#ifdef _OPENMP
/*#ifdef _OPENMP
int num_threads = omp_get_max_threads();
if(num_threads < 2 || cmd.mForceSerial)
{
......@@ -135,7 +135,8 @@ int main(int aRgc, char **aRgv) {
std::cout << "Tree file: " << cmd.mTreeFile << std::endl;
std::cout << "Gene file: " << cmd.mGeneFile << std::endl;
std::cout << "Verbose level: " << cmd.mVerboseLevel << " ("
<< decodeVerboseLevel(cmd.mVerboseLevel) << ')' << std::endl;
<< decodeVerboseLevel(cmd.mVerboseLevel) << ')'
<< std::endl;
if (cmd.mSeed)
std::cout << "Seed: " << cmd.mSeed << std::endl;
if (cmd.mBranchFromFile)
......@@ -165,14 +166,15 @@ int main(int aRgc, char **aRgv) {
if (cmd.mInitH0fromH1)
std::cout << "Starting val.: From H1" << std::endl;
else if (cmd.mInitFromParams && cmd.mBranchLengthsFromFile)
std::cout << "Starting val.: Times from tree file and params from "
"const (see below)"
<< std::endl;
std::cout
<< "Starting val.: Times from tree file and params from "
"const (see below)" << std::endl;
else if (cmd.mInitFromParams)
std::cout << "Starting val.: Params from const (see below)"
<< std::endl;
else if (cmd.mBranchLengthsFromFile)
std::cout << "Starting val.: Times from tree file" << std::endl;
std::cout << "Starting val.: Times from tree file"
<< std::endl;
if (cmd.mNoMaximization)
std::cout << "Maximization: No" << std::endl;
if (cmd.mTrace)
......@@ -187,17 +189,21 @@ int main(int aRgc, char **aRgv) {
std::cout << "Graph times: From H" << cmd.mExportComputedTimes
<< std::endl;
if (!cmd.mNoMaximization)
std::cout << "Optimizer: " << cmd.mOptimizationAlgo << std::endl;
std::cout << "Optimizer: " << cmd.mOptimizationAlgo
<< std::endl;
if (cmd.mMaxIterations != MAX_ITERATIONS)
std::cout << "Max iterations: " << cmd.mMaxIterations << std::endl;
std::cout << "Max iterations: " << cmd.mMaxIterations
<< std::endl;
if (cmd.mDeltaValueForGradient > 0.0)
std::cout << "Delta value: " << cmd.mDeltaValueForGradient
<< std::endl;
std::cout << "Relative error: " << cmd.mRelativeError << std::endl;
if (cmd.mResultsFile)
std::cout << "Results file: " << cmd.mResultsFile << std::endl;
std::cout << "Results file: " << cmd.mResultsFile
<< std::endl;
if (cmd.mNumThreads)
std::cout << "Number of threads: " << cmd.mNumThreads << std::endl;
std::cout << "Number of threads: " << cmd.mNumThreads
<< std::endl;
if (cmd.mFixedBranchLength)
std::cout << "Branch lengths are fixed" << std::endl;
#ifdef _OPENMP
......@@ -248,8 +254,7 @@ int main(int aRgc, char **aRgv) {
#endif
std::cout << std::endl << std::endl;
if (cmd.mInitFromParams) {
std::cout << "Param initial values:" << std::endl
<< std::endl
std::cout << "Param initial values:" << std::endl << std::endl
<< ParseParameters::getInstance();
}
}
......@@ -305,9 +310,11 @@ int main(int aRgc, char **aRgv) {
if (zero_on_leaf_cnt > 0 || zero_on_int_cnt > 0) {
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << "Found null or missing branch length in tree file: on "
std::cout
<< "Found null or missing branch length in tree file: on "
<< zero_on_leaf_cnt << " leave(s) and on "
<< zero_on_int_cnt << " internal branch(es)." << std::endl;
<< zero_on_int_cnt << " internal branch(es)."
<< std::endl;
}
}
}
......@@ -317,9 +324,10 @@ int main(int aRgc, char **aRgv) {
tree.printTreeAnnotated(std::cout);
// Load the forest
forest.loadTreeAndGenes(
tree, msa, cmd.mIgnoreFreq ? CodonFrequencies::CODON_FREQ_MODEL_UNIF
: CodonFrequencies::CODON_FREQ_MODEL_F3X4);
forest.loadTreeAndGenes(tree, msa,
cmd.mIgnoreFreq ?
CodonFrequencies::CODON_FREQ_MODEL_UNIF :
CodonFrequencies::CODON_FREQ_MODEL_F3X4);
// Reduce the forest merging common subtrees. Add also more reduction, then
// clean the no more useful data.
......@@ -357,9 +365,9 @@ int main(int aRgc, char **aRgv) {
// Get the time needed by data preprocessing
if (cmd.mVerboseLevel >= VERBOSE_INFO_OUTPUT) {
timer.stop();
std::cout << std::endl
<< "TIMER (preprocessing) ncores: " << std::setw(2)
<< num_threads << " time: " << timer.get() << std::endl;
std::cout << std::endl << "TIMER (preprocessing) ncores: "
<< std::setw(2) << num_threads << " time: " << timer.get()
<< std::endl;
}
// Print few statistics
......@@ -398,9 +406,7 @@ int main(int aRgc, char **aRgv) {
// getBranchRange function
std::vector<double> mVar; // to save optimization variables
forest.getBranchRange(
cmd, branch_start, branch_end, fg_set,
ib_set); // fgset is added to save a list of fg branches
forest.getBranchRange(cmd, branch_start, branch_end, fg_set, ib_set); // fgset is added to save a list of fg branches
// for (std::set<int>::iterator it=ib_set.begin(); it!=ib_set.end(); ++it)
// std::cout << " " << *it << ",";
......@@ -415,13 +421,15 @@ int main(int aRgc, char **aRgv) {
{
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS)
std::cout << std::endl
<< "Doing foreground branch(es) from tree file " << std::endl;
<< "Doing foreground branch(es) from tree file "
<< std::endl;
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS)
std::cout << "-------------------------------------------" << std::endl;
std::cout << "-------------------------------------------"
<< std::endl;
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << "Doing foreground branch(es) ";
for (std::set<int>::iterator it = fg_set.begin(); it != fg_set.end();
++it)
for (std::set<int>::iterator it = fg_set.begin();
it != fg_set.end(); ++it)
std::cout << " " << *it << " ";
std::cout << std::endl;
}
......@@ -460,7 +468,8 @@ int main(int aRgc, char **aRgv) {
h0.initFromTree();
}
lnl0 = h0(fg_set, cmd.mStopIfNotLRT && cmd.mComputeHypothesis != 0,
lnl0 = h0(fg_set,
cmd.mStopIfNotLRT && cmd.mComputeHypothesis != 0,
lnl1 - THRESHOLD_FOR_LRT);
// std::cout << "lnl0 = " << lnl0 << std::endl;
......@@ -476,7 +485,8 @@ int main(int aRgc, char **aRgv) {
if (lnl0 == std::numeric_limits<double>::infinity())
std::cout << "**Invalid result**";
else if (lnl0 < DBL_MAX)
std::cout << std::setprecision(15) << std::fixed << lnl0;
std::cout << std::setprecision(15) << std::fixed
<< lnl0;
else
std::cout << "(Doesn't pass LRT, skipping)";
std::cout << " Function calls: " << h0.getNumEvaluations()
......@@ -494,7 +504,8 @@ int main(int aRgc, char **aRgv) {
if (lnl1 == std::numeric_limits<double>::infinity())
std::cout << "**Invalid result**";
else
std::cout << std::setprecision(15) << std::fixed << lnl1;
std::cout << std::setprecision(15) << std::fixed
<< lnl1;
std::cout << " Function calls: " << h1.getNumEvaluations();
std::cout << std::endl << std::endl;
if (lnl1 != std::numeric_limits<double>::infinity()) {
......@@ -505,17 +516,17 @@ int main(int aRgc, char **aRgv) {
std::cout << std::endl;
}
if (cmd.mComputeHypothesis > 1) {
if (lnl0 == std::numeric_limits<double>::infinity() ||
lnl1 == std::numeric_limits<double>::infinity())
if (lnl0 == std::numeric_limits<double>::infinity()
|| lnl1 == std::numeric_limits<double>::infinity())
std::cout << "LRT: **Invalid result**";
else if (lnl0 < DBL_MAX)
std::cout << "LRT: " << std::setprecision(15) << std::fixed
<< lnl1 - lnl0
<< " (threshold: " << std::setprecision(15)
<< std::fixed << THRESHOLD_FOR_LRT << ')';
std::cout << "LRT: " << std::setprecision(15)
<< std::fixed << lnl1 - lnl0 << " (threshold: "
<< std::setprecision(15) << std::fixed
<< THRESHOLD_FOR_LRT << ')';
else
std::cout << "LRT: < " << std::setprecision(15) << std::fixed
<< THRESHOLD_FOR_LRT;
std::cout << "LRT: < " << std::setprecision(15)
<< std::fixed << THRESHOLD_FOR_LRT;
std::cout << std::endl;
}
}
......@@ -543,13 +554,12 @@ int main(int aRgc, char **aRgv) {
// If the two hypothesis are computed, H0 has not been stopped and the run
// passes the LRT, then compute the BEB
if (cmd.mComputeHypothesis > 1 && lnl0 < DBL_MAX &&
BranchSiteModel::performLRT(lnl0, lnl1)) {
if (cmd.mComputeHypothesis > 1 && lnl0 < DBL_MAX
&& BranchSiteModel::performLRT(lnl0, lnl1)) {
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS)
std::cout << std::endl
<< "LRT is significant. Computing sites under positive "
"selection ... "
<< std::endl;
"selection ... " << std::endl;
// Get the scale values from the latest optimized h1.
std::vector<double> scales(2);
......@@ -602,7 +612,7 @@ int main(int aRgc, char **aRgv) {
{
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << std::endl << "H1 Final ";
std::cout << std::endl << "Final ";
tree.printTreeAnnotated(std::cout, NULL, 0, true);
}
}
......@@ -610,10 +620,18 @@ int main(int aRgc, char **aRgv) {
else
{
mVar = h1.getVariables();
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << std::endl << "H1 Final ";
tree.printTreeAnnotatedWithEstLens(std::cout, NULL, 0, true, &mVar);
if (cmd.mComputeHypothesis == 0)
mVar = h0.getVariables();
else
mVar = h1.getVariables();
if (cmd.mComputeHypothesis == 0)
std::cout << std::endl << "H0 Final ";
else
std::cout << std::endl << "H0 Final ";
tree.printTreeAnnotatedWithEstLens(std::cout, NULL, 0, true,
&mVar);
}
// tree.printTreeAnnotatedWithEstLens(std::cout, NULL, 0, true,
// &h1.getVariables());
......@@ -634,10 +652,12 @@ int main(int aRgc, char **aRgv) {
std::cout << "lnl1 (multiple fg) = " << lnl1 << std::endl;*/
timer_app.stop();
std::cout << std::endl
<< "Time used: " << timer_app.get() / 60000 << ":"
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << std::endl << "Time used: "
<< timer_app.get() / 60000 << ":"
<< (timer_app.get() / 1000) % 60 << std::endl;
std::cout << "Cores used: " << num_threads << std::endl;
}
return 0;
}
......@@ -656,23 +676,26 @@ int main(int aRgc, char **aRgv) {
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
if (cmd.mBranchAll)
std::cout << std::endl << "Doing all foreground branches" << std::endl;
std::cout << std::endl << "Doing all foreground branches"
<< std::endl;
else
std::cout << std::endl
<< "Doing internal foreground branches" << std::endl;
std::cout << std::endl << "Doing internal foreground branches"
<< std::endl;
std::cout << "------------------------------------" << std::endl;
}
for (size_t fg_branch = branch_start; fg_branch <= branch_end;
++fg_branch) {
if (cmd.mBranchAll or
(!cmd.mBranchAll and ib_set.find(fg_branch) != ib_set.end()))
if (cmd.mBranchAll
or (!cmd.mBranchAll
and ib_set.find(fg_branch) != ib_set.end()))
{
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS)
std::cout << "Doing foreground branch " << fg_branch << std::endl;
std::cout << "Doing foreground branch " << fg_branch
<< std::endl;
// Compute the alternate model maximum loglikelihood
double lnl1 = 0.;
......@@ -702,7 +725,8 @@ int main(int aRgc, char **aRgv) {
h0.initFromTree();
}
lnl0 = h0(fg_branch, cmd.mStopIfNotLRT && cmd.mComputeHypothesis != 0,
lnl0 = h0(fg_branch,
cmd.mStopIfNotLRT && cmd.mComputeHypothesis != 0,
lnl1 - THRESHOLD_FOR_LRT);
// Save the value for formatted output (only if has not be forced to
......@@ -717,11 +741,12 @@ int main(int aRgc, char **aRgv) {
if (lnl0 == std::numeric_limits<double>::infinity())
std::cout << "**Invalid result**";
else if (lnl0 < DBL_MAX)
std::cout << std::setprecision(15) << std::fixed << lnl0;
std::cout << std::setprecision(15) << std::fixed
<< lnl0;
else
std::cout << "(Doesn't pass LRT, skipping)";
std::cout << " Function calls: " << h0.getNumEvaluations()
<< " ";
std::cout << " Function calls: "
<< h0.getNumEvaluations() << " ";
std::cout << std::endl << std::endl;
if (lnl0 != std::numeric_limits<double>::infinity()) {
std::string s0 = h0.printFinalVars(std::cout);
......@@ -734,8 +759,10 @@ int main(int aRgc, char **aRgv) {
if (lnl1 == std::numeric_limits<double>::infinity())
std::cout << "**Invalid result**";
else
std::cout << std::setprecision(15) << std::fixed << lnl1;
std::cout << " Function calls: " << h1.getNumEvaluations();
std::cout << std::setprecision(15) << std::fixed
<< lnl1;
std::cout << " Function calls: "
<< h1.getNumEvaluations();
std::cout << std::endl << std::endl;
if (lnl1 != std::numeric_limits<double>::infinity()) {
std::string s1 = h1.printFinalVars(std::cout);
......@@ -744,17 +771,18 @@ int main(int aRgc, char **aRgv) {
std::cout << std::endl;
}
if (cmd.mComputeHypothesis > 1) {
if (lnl0 == std::numeric_limits<double>::infinity() ||
lnl1 == std::numeric_limits<double>::infinity())
if (lnl0 == std::numeric_limits<double>::infinity()
|| lnl1
== std::numeric_limits<double>::infinity())
std::cout << "LRT: **Invalid result**";
else if (lnl0 < DBL_MAX)
std::cout << "LRT: " << std::setprecision(15) << std::fixed
<< lnl1 - lnl0
std::cout << "LRT: " << std::setprecision(15)
<< std::fixed << lnl1 - lnl0
<< " (threshold: " << std::setprecision(15)
<< std::fixed << THRESHOLD_FOR_LRT << ')';
else
std::cout << "LRT: < " << std::setprecision(15) << std::fixed
<< THRESHOLD_FOR_LRT;
std::cout << "LRT: < " << std::setprecision(15)
<< std::fixed << THRESHOLD_FOR_LRT;
std::cout << std::endl;
}
}
......@@ -782,13 +810,12 @@ int main(int aRgc, char **aRgv) {
// If the two hypothesis are computed, H0 has not been stopped and the
// run passes the LRT, then compute the BEB
if (cmd.mComputeHypothesis > 1 && lnl0 < DBL_MAX &&
BranchSiteModel::performLRT(lnl0, lnl1)) {
if (cmd.mComputeHypothesis > 1 && lnl0 < DBL_MAX
&& BranchSiteModel::performLRT(lnl0, lnl1)) {
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS)
std::cout << std::endl
<< "LRT is significant. Computing sites under positive "
"selection ... "
<< std::endl;
"selection ... " << std::endl;
// Get the scale values from the latest optimized h1.
std::vector<double> scales(2);
......@@ -811,8 +838,8 @@ int main(int aRgc, char **aRgv) {
std::vector<double> positive_sel_sites_prob;
beb.extractPositiveSelSites(positive_sel_sites,
positive_sel_sites_prob);
output_results.savePositiveSelSites(fg_branch, positive_sel_sites,
positive_sel_sites_prob);
output_results.savePositiveSelSites(fg_branch,
positive_sel_sites, positive_sel_sites_prob);
}
}
......@@ -820,7 +847,7 @@ int main(int aRgc, char **aRgv) {
{
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << std::endl << "H1 Final ";
std::cout << std::endl << "Final ";
tree.printTreeAnnotated(std::cout, NULL, 0, true);
std::cout << std::endl;
}
......@@ -829,10 +856,17 @@ int main(int aRgc, char **aRgv) {
else {
// std :: cout << std::endl;
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
if (cmd.mComputeHypothesis == 0)
mVar = h0.getVariables();
else
mVar = h1.getVariables();
std::cout << std::endl << "H1 Final ";
tree.printTreeAnnotatedWithEstLens(std::cout, NULL, 0, true, &mVar);
std::cout << std::endl;
if (cmd.mComputeHypothesis == 0)
std::cout << std::endl << "H0 Final ";
else
std::cout << std::endl << "H0 Final ";
tree.printTreeAnnotatedWithEstLens(std::cout, NULL, 0,
true, &mVar);
}
}
}
......@@ -841,16 +875,17 @@ int main(int aRgc, char **aRgv) {
// Get the time needed by the parallel part
if (cmd.mVerboseLevel >= VERBOSE_INFO_OUTPUT) {
timer.stop();
std::cout << std::endl
<< "TIMER (processing) ncores: " << std::setw(2) << num_threads
<< " time: " << timer.get() << std::endl;
std::cout << std::endl << "TIMER (processing) ncores: "
<< std::setw(2) << num_threads << " time: " << timer.get()
<< std::endl;
}
timer_app.stop();
std::cout << std::endl
<< "Time used: " << timer_app.get() / 60000 << ":"
<< (timer_app.get() / 1000) % 60 << std::endl;
if (cmd.mVerboseLevel >= VERBOSE_ONLY_RESULTS) {
std::cout << std::endl << "Time used: " << timer_app.get() / 60000
<< ":" << (timer_app.get() / 1000) % 60 << std::endl;
std::cout << "Cores used: " << num_threads << std::endl;
}
// Output the results
// output_results.outputResults();
......@@ -870,8 +905,7 @@ int main(int aRgc, char **aRgv) {
std::cout << std::endl << e.what() << std::endl << std::endl;
return 1;
} catch (...) {
std::cout << std::endl
<< "Default exception caught." << std::endl
std::cout << std::endl << "Default exception caught." << std::endl
<< std::endl;
return 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment