5 #include "../SitePatterns.h"
6 #include "../Tree/Tree.h"
7 #include "../PatternTools.h"
8 #include "../Io/Newick.h"
38 auto desc = make_unique<MetaOptimizerInfos>();
41 std::vector<std::string> name;
42 auto procMb = dynamic_pointer_cast<SubstitutionProcessCollectionMember>(process_);
45 name.push_back(
"BrLen0");
46 name.push_back(
"BrLen1");
50 const auto& vTn = procMb->getCollection()->getTreeNumbers();
51 numProc_ = *std::max_element(vTn.begin(),vTn.end())+1;
60 ParameterList tmp = process_->getSubstitutionModelParameters(
true);
61 tmp.
addParameters(process_->getRateDistributionParameters(
true));
62 tmp.
addParameters(process_->getRootFrequenciesParameters(
true));
65 defaultOptimizer_ = std::make_shared<MetaOptimizer>(
nullptr, std::move(desc));
66 defaultOptimizer_->setMessageHandler(
nullptr);
67 defaultOptimizer_->setProfiler(
nullptr);
68 defaultOptimizer_->getStopCondition()->setTolerance(0.0001);
69 optimizer_ = dynamic_pointer_cast<OptimizerInterface>(defaultOptimizer_);
76 size_t n = sites_->getNumberOfSequences();
77 vector<string> names = sites_->getSequenceNames();
78 dist_ = std::shared_ptr<DistanceMatrix>(
new DistanceMatrix(names));
79 optimizer_->setVerbose(
static_cast<unsigned int>(max(
static_cast<int>(verbose_) - 2, 0)));
83 auto autoProc = dynamic_pointer_cast<AutonomousSubstitutionProcessInterface>(process_);
84 auto procMb = dynamic_pointer_cast<SubstitutionProcessCollectionMember>(process_);
85 if (!autoProc && !procMb)
86 throw Exception(
"DistanceMatrix::computeMatrix : unknown process type. Ask developpers.");
90 treeN = procMb->getTreeNumber();
92 for (
size_t i = 0; i < n; ++i)
99 for (
size_t j = i + 1; j < n; ++j)
106 auto phyloTree = make_shared<bpp::ParametrizablePhyloTree>(*reader.
parenthesisToPhyloTree(
"(" + names[j] +
":0.01," + names[i] +
":0.01);",
false,
"",
false,
false));
109 autoProc->setPhyloTree(*phyloTree);
113 auto& coll = procMb->collection();
114 if (!coll.hasTreeNumber(numProc_))
115 coll.addTree(phyloTree, numProc_);
117 coll.replaceTree(phyloTree, numProc_);
118 procMb->setTreeNumber(numProc_,
false);
121 auto lik = std::make_shared<LikelihoodCalculationSingleProcess>(context, sites_, process_);
122 auto llh = std::make_shared<SingleProcessPhyloLikelihood>(context, lik);
125 optimizer_->setFunction(llh);
130 optimizer_->init(params);
131 optimizer_->optimize();
135 (*dist_)(i, j) = (*dist_)(j, i) = llh->getParameterValue(
"BrLen0") + llh->getParameterValue(
"BrLen1");
146 procMb->setTreeNumber(treeN,
false);
static std::string CONSTRAINTS_AUTO
Context for dataflow node construction.
void computeMatrix()
Perform the distance computation.
The so-called 'newick' parenthetic format.
std::unique_ptr< PhyloTree > parenthesisToPhyloTree(const std::string &description, bool bootstrap=false, const std::string &propertyName="", bool withId=false, bool verbose=false) const
virtual void addParameters(const ParameterList ¶ms)
virtual std::vector< std::string > getParameterNames() const
std::string toString(T t)
Defines the basic types of data flow nodes.