bpp-phyl  2.4.0
GlobalClockTreeLikelihoodFunctionWrapper.cpp
Go to the documentation of this file.
1 //
2 // File: GlobalClockTreeLikelihoodFunctionWrapper.cpp
3 // Created by: Julien Dutheil
4 // Created on: Thu Jul 14 10:53 2011
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
41 
42 using namespace bpp;
43 
45 {
46  // filter parameters:
47  ParameterList pl2;
48  bool recomputeHeights = false;
49  for (unsigned int i = 0; i < pl.size(); ++i)
50  {
51  if (pl[i].getName().substr(0, 7) == "HeightP" || pl[i].getName() == "TotalHeight")
52  recomputeHeights = true;
53  else
54  pl2.addParameter(pl[i]);
55  }
56  if (recomputeHeights)
57  {
59  computeBranchLengthsFromHeights_(tree.getRootNode(), getParameter("TotalHeight").getValue(), pl2);
60  }
61  tl_->setParameters(pl2);
62 }
63 
65 {
66  ParameterList pl;
67 
68  for (unsigned int i = 0; i < getNumberOfParameters(); ++i)
69  {
70  Parameter p = getParameter_(i);
71  if (p.getName().substr(0, 7) == "HeightP" || p.getName() == "TotalHeight")
72  pl.addParameter(p);
73  }
74  return pl;
75 }
76 
78 {
79  // Check if the tree is rooted:
81  if (!tree.isRooted()) throw Exception("GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(). Tree is unrooted!");
82  if (TreeTemplateTools::isMultifurcating(*(tree.getRootNode()))) throw Exception("GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(). Tree is multifurcating.");
83  std::map<const Node*, double> heights;
84  TreeTemplateTools::getHeights(*(tree.getRootNode()), heights);
85  double totalHeight = heights[tree.getRootNode()];
86  addParameter_(new Parameter("TotalHeight", totalHeight, &Parameter::R_PLUS_STAR));
87  for (std::map<const Node*, double>::iterator it = heights.begin(); it != heights.end(); it++)
88  {
89  if (!it->first->isLeaf() && it->first->hasFather())
90  {
91  double fatherHeight = heights[it->first->getFather()];
92  addParameter_(new Parameter("HeightP" + TextTools::toString(it->first->getId()), it->second / fatherHeight, &Parameter::PROP_CONSTRAINT_IN));
93  }
94  }
95  // We add other parameters:
97  for (unsigned int i = 0; i < pl.size(); ++i)
98  {
99  if (pl[i].getName().substr(0, 5) != "BrLen")
100  addParameter_(pl[i].clone());
101  }
102  // Compute everything:
104 }
105 
107 {
108  for (unsigned int i = 0; i < node->getNumberOfSons(); i++)
109  {
110  const Node* son = node->getSon(i);
111  if (son->isLeaf())
112  {
113  brlenPl.addParameter(Parameter("BrLen" + TextTools::toString(son->getId()), std::max(0.0000011, height), new IntervalConstraint(1, 0.000001, false), true));
114  }
115  else
116  {
117  double sonHeightP = getParameter("HeightP" + TextTools::toString(son->getId())).getValue();
118  double sonHeight = sonHeightP * height;
119  brlenPl.addParameter(Parameter("BrLen" + TextTools::toString(son->getId()), std::max(0.0000011, height - sonHeight), new IntervalConstraint(1, 0.000001, false), true));
120  computeBranchLengthsFromHeights_(son, sonHeight, brlenPl);
121  }
122  }
123 }
124 
virtual void setParameters(const ParameterList &parameters)=0
virtual const std::string & getName() const
virtual double getValue() const
virtual const ParameterList & getParameters() const =0
static const IntervalConstraint R_PLUS_STAR
The phylogenetic tree class.
virtual int getId() const
Get the node&#39;s id.
Definition: Node.h:203
size_t getNumberOfParameters() const
virtual const Tree & getTree() const =0
Get the tree (topology and branch lengths).
void computeBranchLengthsFromHeights_(const Node *node, double height, ParameterList &brlenPl)
virtual const Node * getSon(size_t pos) const
Definition: Node.h:395
GlobalClockTreeLikelihoodFunctionWrapper * clone() 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 &#39;node&#39;, i.e. the maximum distance betwe...
size_t size() const
The phylogenetic node class.
Definition: Node.h:90
virtual void addParameter(const Parameter &param)
virtual size_t getNumberOfSons() const
Definition: Node.h:388
static bool isMultifurcating(const Node &node)
Tell is a subtree is multifurcating.
virtual void addParameter_(Parameter *parameter)
static const IntervalConstraint PROP_CONSTRAINT_IN
const ParameterList & getParameters() const
Parameter & getParameter_(const std::string &name)
const Parameter & getParameter(const std::string &name) const
virtual bool isLeaf() const
Definition: Node.h:692
std::string toString(T t)