bpp-phyl3 3.0.0
GlobalClockTreeLikelihoodFunctionWrapper.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
7using namespace bpp;
8
9void GlobalClockTreeLikelihoodFunctionWrapper::fireParameterChanged(const bpp::ParameterList& pl)
10{
11 // filter parameters:
12 ParameterList pl2;
13 bool recomputeHeights = false;
14 for (unsigned int i = 0; i < pl.size(); ++i)
15 {
16 if (pl[i].getName().substr(0, 7) == "HeightP" || pl[i].getName() == "TotalHeight")
17 recomputeHeights = true;
18 else
19 pl2.addParameter(pl[i]);
20 }
21 if (recomputeHeights)
22 {
23 TreeTemplate<Node> tree(tl_->tree());
25 }
26 tl_->setParameters(pl2);
27}
28
30{
32
33 for (unsigned int i = 0; i < getNumberOfParameters(); ++i)
34 {
36 if (p.getName().substr(0, 7) == "HeightP" || p.getName() == "TotalHeight")
37 pl.addParameter(p);
38 }
39 return pl;
40}
41
43{
44 // Check if the tree is rooted:
45 TreeTemplate<Node> tree(tl_->tree());
46 if (!tree.isRooted())
47 throw Exception("GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(). Tree is unrooted!");
49 throw Exception("GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(). Tree is multifurcating.");
50 std::map<const Node*, double> heights;
52 double totalHeight = heights[tree.getRootNode()];
53 addParameter_(new Parameter("TotalHeight", totalHeight, Parameter::R_PLUS_STAR));
54 for (std::map<const Node*, double>::iterator it = heights.begin(); it != heights.end(); it++)
55 {
56 if (!it->first->isLeaf() && it->first->hasFather())
57 {
58 double fatherHeight = heights[it->first->getFather()];
59 addParameter_(new Parameter("HeightP" + TextTools::toString(it->first->getId()), it->second / fatherHeight, Parameter::PROP_CONSTRAINT_IN));
60 }
61 }
62 // We add other parameters:
63 ParameterList pl = tl_->getParameters();
64 for (unsigned int i = 0; i < pl.size(); ++i)
65 {
66 if (pl[i].getName().substr(0, 5) != "BrLen")
67 addParameter_(pl[i].clone());
68 }
69 // Compute everything:
71}
72
74{
75 for (unsigned int i = 0; i < node->getNumberOfSons(); i++)
76 {
77 const Node* son = node->getSon(i);
78 if (son->isLeaf())
79 {
80 brlenPl.addParameter(Parameter("BrLen" + TextTools::toString(son->getId()), std::max(0.0000011, height), std::make_shared<IntervalConstraint>(1, 0.000001, false)));
81 }
82 else
83 {
84 double sonHeightP = parameter("HeightP" + TextTools::toString(son->getId())).getValue();
85 double sonHeight = sonHeightP * height;
86 brlenPl.addParameter(Parameter("BrLen" + TextTools::toString(son->getId()), std::max(0.0000011, height - sonHeight), std::make_shared<IntervalConstraint>(1, 0.000001, false)));
87 computeBranchLengthsFromHeights_(son, sonHeight, brlenPl);
88 }
89 }
90}
const Parameter & parameter(const std::string &name) const override
virtual void addParameter_(Parameter *parameter)
size_t getNumberOfParameters() const override
const ParameterList & getParameters() const override
Parameter & getParameter_(const std::string &name)
void computeBranchLengthsFromHeights_(const Node *node, double height, ParameterList &brlenPl)
GlobalClockTreeLikelihoodFunctionWrapper * clone() const
The phylogenetic node class.
Definition: Node.h:59
virtual int getId() const
Get the node's id.
Definition: Node.h:170
virtual const Node * getSon(size_t pos) const
Definition: Node.h:362
virtual bool isLeaf() const
Definition: Node.h:679
virtual size_t getNumberOfSons() const
Definition: Node.h:355
size_t size() const
virtual void addParameter(const Parameter &param)
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
virtual double getValue() const
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
virtual const std::string & getName() const
static double getHeights(const Node &node, std::map< const Node *, double > &heights)
Get the heights of all nodes within a subtree defined by node 'node', i.e. the maximum distance betwe...
static bool isMultifurcating(const Node &node)
Tell is a subtree is multifurcating.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
bool isRooted() const
Tell if the tree is rooted.
Definition: TreeTemplate.h:224
virtual N * getRootNode()
Definition: TreeTemplate.h:389
std::string toString(T t)
Defines the basic types of data flow nodes.