bpp-phyl3  3.0.0
TreeTemplate.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_TREE_TREETEMPLATE_H
6 #define BPP_PHYL_TREE_TREETEMPLATE_H
7 
8 
9 #include "Tree.h"
10 #include "TreeExceptions.h"
11 #include "TreeTemplateTools.h"
12 
13 // From the STL:
14 #include <string>
15 #include <vector>
16 #include <map>
17 
18 namespace bpp
19 {
56 template<class N>
57 class TreeTemplate :
58  public Tree
59 {
64 private:
65  N* root_;
66  std::string name_;
67 
68 public:
69  // Constructors and destructor:
71  name_() {}
72 
74  root_(0),
75  name_(t.name_)
76  {
77  // Perform a hard copy of the nodes:
78  root_ = TreeTemplateTools::cloneSubtree<N>(*t.getRootNode());
79  }
80 
81  TreeTemplate(const Tree& t) :
82  root_(0),
83  name_(t.getName())
84  {
85  // Create new nodes from an existing tree:
86  root_ = TreeTemplateTools::cloneSubtree<N>(t, t.getRootId());
87  }
88 
89  TreeTemplate(N* root) : root_(root),
90  name_()
91  {
92  root_->removeFather(); // In case this is a subtree from somewhere else...
93  }
94 
96  {
97  // Perform a hard copy of the nodes:
99  root_ = TreeTemplateTools::cloneSubtree<N>(*t.getRootNode());
100  name_ = t.name_;
101  return *this;
102  }
103 
104  TreeTemplate<N>* cloneSubtree(int newRootId) const
105  {
106  N* newRoot = TreeTemplateTools::cloneSubtree<N>(*this, newRootId);
107  return new TreeTemplate<N>(newRoot);
108  }
109 
110  virtual ~TreeTemplate()
111  {
113  delete root_;
114  }
115 
116  TreeTemplate<N>* clone() const { return new TreeTemplate<N>(*this); }
117 
122 public:
123  std::string getName() const { return name_; }
124 
125  void setName(const std::string& name) { name_ = name; }
126 
127  int getRootId() const { return root_->getId(); }
128 
130 
132 
134 
135  int getLeafId(const std::string& name) const { return TreeTemplateTools::getLeafId(*root_, name); }
136 
137  std::vector<int> getLeavesId() const { return TreeTemplateTools::getLeavesId(*root_); }
138 
139  std::vector<int> getNodesId() const { return TreeTemplateTools::getNodesId(*root_); }
140 
141  std::vector<int> getInnerNodesId() const { return TreeTemplateTools::getInnerNodesId(*root_); }
142 
143  std::vector<int> getBranchesId() const
144  {
146  int rId = getRootId();
147  std::vector<int>::iterator rit(vRes.begin());
148  while (rit < vRes.end())
149  if (*rit == rId)
150  {
151  vRes.erase(rit, rit + 1);
152  return vRes;
153  }
154  else
155  rit++;
156 
157  return vRes;
158  }
159 
160  std::vector<double> getBranchLengths() const { return TreeTemplateTools::getBranchLengths(*root_); }
161 
162  std::vector<std::string> getLeavesNames() const { return TreeTemplateTools::getLeavesNames(*const_cast<const N*>( root_)); }
163 
164  std::vector<int> getSonsId(int parentId) const { return getNode(parentId)->getSonsId(); }
165 
166  std::vector<int> getAncestorsId(int nodeId) const { return TreeTemplateTools::getAncestorsId(*getNode(nodeId)); }
167 
168  int getFatherId(int parentId) const { return getNode(parentId)->getFatherId(); }
169 
170  bool hasFather(int nodeId) const { return getNode(nodeId)->hasFather(); }
171 
172  std::string getNodeName(int nodeId) const { return getNode(nodeId)->getName(); }
173 
174  bool hasNodeName(int nodeId) const { return getNode(nodeId)->hasName(); }
175 
176  void setNodeName(int nodeId, const std::string& name) { getNode(nodeId)->setName(name); }
177 
178  void deleteNodeName(int nodeId) { return getNode(nodeId)->deleteName(); }
179 
180  bool hasNode(int nodeId) const { return TreeTemplateTools::hasNodeWithId(*root_, nodeId); }
181 
182  bool isLeaf(int nodeId) const { return getNode(nodeId)->isLeaf(); }
183 
184  bool hasNoSon(int nodeId) const { return getNode(nodeId)->hasNoSon(); }
185 
186  bool isRoot(int nodeId) const { return TreeTemplateTools::isRoot(*getNode(nodeId)); }
187 
188  double getDistanceToFather(int nodeId) const { return getNode(nodeId)->getDistanceToFather(); }
189 
190  void setDistanceToFather(int nodeId, double length) { getNode(nodeId)->setDistanceToFather(length); }
191 
192  void deleteDistanceToFather(int nodeId) { getNode(nodeId)->deleteDistanceToFather(); }
193 
194  bool hasDistanceToFather(int nodeId) const { return getNode(nodeId)->hasDistanceToFather(); }
195 
196  bool hasNodeProperty(int nodeId, const std::string& name) const { return getNode(nodeId)->hasNodeProperty(name); }
197 
198  void setNodeProperty(int nodeId, const std::string& name, const Clonable& property) { getNode(nodeId)->setNodeProperty(name, property); }
199 
200  Clonable* getNodeProperty(int nodeId, const std::string& name) { return getNode(nodeId)->getNodeProperty(name); }
201 
202  const Clonable* getNodeProperty(int nodeId, const std::string& name) const { return getNode(nodeId)->getNodeProperty(name); }
203 
204  Clonable* removeNodeProperty(int nodeId, const std::string& name) { return getNode(nodeId)->removeNodeProperty(name); }
205 
206  std::vector<std::string> getNodePropertyNames(int nodeId) const { return getNode(nodeId)->getNodePropertyNames(); }
207 
208  bool hasBranchProperty(int nodeId, const std::string& name) const { return getNode(nodeId)->hasBranchProperty(name); }
209 
210  void setBranchProperty(int nodeId, const std::string& name, const Clonable& property) { getNode(nodeId)->setBranchProperty(name, property); }
211 
212  Clonable* getBranchProperty(int nodeId, const std::string& name) { return getNode(nodeId)->getBranchProperty(name); }
213 
214  const Clonable* getBranchProperty(int nodeId, const std::string& name) const { return getNode(nodeId)->getBranchProperty(name); }
215 
216  Clonable* removeBranchProperty(int nodeId, const std::string& name) { return getNode(nodeId)->removeBranchProperty(name); }
217 
218  std::vector<std::string> getBranchPropertyNames(int nodeId) const { return getNode(nodeId)->getBranchPropertyNames(); }
219 
220  void rootAt(int nodeId) { rootAt(getNode(nodeId)); }
221 
222  void newOutGroup(int nodeId) { newOutGroup(getNode(nodeId)); }
223 
224  bool isRooted() const { return root_->getNumberOfSons() == 2; }
225 
226  bool unroot()
227  {
228  if (!isRooted()) throw UnrootedTreeException("Tree::unroot", this);
229  else
230  {
231  N* son1 = dynamic_cast<N*>(root_->getSon(0));
232  N* son2 = dynamic_cast<N*>(root_->getSon(1));
233  if (son1->isLeaf() && son2->isLeaf()) return false; // We can't unroot a single branch!
234 
235  // We manage to have a subtree in position 0:
236  if (son1->isLeaf())
237  {
238  root_->swap(0, 1);
239  son1 = dynamic_cast<N*>(root_->getSon(0));
240  son2 = dynamic_cast<N*>(root_->getSon(1));
241  }
242 
243  // Take care of branch lengths:
244  if (son1->hasDistanceToFather())
245  {
246  if (son2->hasDistanceToFather())
247  {
248  // Both nodes have lengths, we sum them:
249  son2->setDistanceToFather(son1->getDistanceToFather() + son2->getDistanceToFather());
250  }
251  else
252  {
253  // Only node 1 has length, we set it to node 2:
254  son2->setDistanceToFather(son1->getDistanceToFather());
255  }
256  son1->deleteDistanceToFather();
257  } // Else node 2 may or may not have a branch length, we do not care!
258 
259  // Remove the root:
260  root_->removeSons();
261  son1->addSon(son2);
262  delete root_;
263  setRootNode(son1);
264  return true;
265  }
266  }
267 
269  {
270  std::vector<N*> nodes = getNodes();
271  for (size_t i = 0; i < nodes.size(); i++)
272  {
273  nodes[i]->setId(static_cast<int>(i));
274  }
275  }
276 
277  bool isMultifurcating() const
278  {
279  if (root_->getNumberOfSons() > 3) return true;
280  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
281  {
283  return true;
284  }
285  return false;
286  }
287 
301  template<class N2>
302  bool hasSameTopologyAs(const TreeTemplate<N2>& tree, bool ordered = false) const
303  {
304  const TreeTemplate<N>* t1 = 0;
305  const TreeTemplate<N2>* t2 = 0;
306  if (ordered)
307  {
308  t1 = this;
309  t2 = &tree;
310  }
311  else
312  {
313  TreeTemplate<N>* t1tmp = this->clone();
314  TreeTemplate<N2>* t2tmp = tree.clone();
315  TreeTemplateTools::orderTree(*t1tmp->getRootNode(), true, true);
316  TreeTemplateTools::orderTree(*t2tmp->getRootNode(), true, true);
317  t1 = t1tmp;
318  t2 = t2tmp;
319  }
321  if (!ordered)
322  {
323  delete t1;
324  delete t2;
325  }
326  return test;
327  }
328 
329  std::vector<double> getBranchLengths()
330  {
331  Vdouble brLen(1);
332  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
333  {
334  Vdouble sonBrLen = TreeTemplateTools::getBranchLengths(*root_->getSon(i));
335  for (size_t j = 0; j < sonBrLen.size(); j++) { brLen.push_back(sonBrLen[j]); }
336  }
337  return brLen;
338  }
339 
340  double getTotalLength()
341  {
343  }
344 
345  void setBranchLengths(double brLen)
346  {
347  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
348  {
349  TreeTemplateTools::setBranchLengths(*root_->getSon(i), brLen);
350  }
351  }
352 
353  void setVoidBranchLengths(double brLen)
354  {
355  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
356  {
358  }
359  }
360 
361  void scaleTree(double factor)
362  {
363  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
364  {
365  TreeTemplateTools::scaleTree(*root_->getSon(i), factor);
366  }
367  }
368 
369  int getNextId()
370  {
371  return TreeTools::getMPNUId(*this, root_->getId());
372  }
373 
374  void swapNodes(int parentId, size_t i1, size_t i2)
375  {
376  std::vector<N*> nodes = TreeTemplateTools::searchNodeWithId<N>(*root_, parentId);
377  if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate:swapNodes(): Node with id not found.", TextTools::toString(parentId));
378  for (size_t i = 0; i < nodes.size(); i++) { nodes[i]->swap(i1, i2); }
379  }
380 
381 
387  virtual void setRootNode(N* root) { root_ = root; root_->removeFather(); }
388 
389  virtual N* getRootNode() { return root_; }
390 
391  virtual const N* getRootNode() const { return root_; }
392 
393  virtual std::vector<const N*> getLeaves() const { return TreeTemplateTools::getLeaves(*const_cast<const N*>(root_)); }
394 
395  virtual std::vector<N*> getLeaves() { return TreeTemplateTools::getLeaves(*root_); }
396 
397  virtual std::vector<const N*> getNodes() const { return TreeTemplateTools::getNodes(*const_cast<const N*>(root_)); }
398 
399  virtual std::vector<N*> getNodes() { return TreeTemplateTools::getNodes(*root_); }
400 
401  virtual std::vector<const N*> getInnerNodes() const { return TreeTemplateTools::getInnerNodes(*const_cast<const N*>(root_)); }
402 
403  virtual std::vector<N*> getInnerNodes() { return TreeTemplateTools::getInnerNodes(*root_); }
404 
405  virtual N* getNode(int id, bool checkId = false)
406  {
407  if (checkId)
408  {
409  std::vector<N*> nodes;
410  TreeTemplateTools::searchNodeWithId<N>(*dynamic_cast<N*>(root_), id, nodes);
411  if (nodes.size() > 1) throw Exception("TreeTemplate::getNode(): Non-unique id! (" + TextTools::toString(id) + ").");
412  if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
413  return nodes[0];
414  }
415  else
416  {
417  N* node = dynamic_cast<N*>(TreeTemplateTools::searchFirstNodeWithId(*root_, id));
418  if (node)
419  return node;
420  else
421  throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
422  }
423  }
424 
425  virtual const N* getNode(int id, bool checkId = false) const
426  {
427  if (checkId)
428  {
429  std::vector<const N*> nodes;
430  TreeTemplateTools::searchNodeWithId<const N>(*root_, id, nodes);
431  if (nodes.size() > 1) throw Exception("TreeTemplate::getNode(): Non-unique id! (" + TextTools::toString(id) + ").");
432  if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
433  return nodes[0];
434  }
435  else
436  {
437  const N* node = dynamic_cast<const N*>(TreeTemplateTools::searchFirstNodeWithId(*root_, id));
438  if (node)
439  return node;
440  else
441  throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
442  }
443  }
444 
445  virtual N* getNode(const std::string& name)
446  {
447  std::vector<N*> nodes;
449  if (nodes.size() > 1) throw NodeNotFoundException("TreeTemplate::getNode(): Non-unique name.", "" + name);
450  if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with name not found.", "" + name);
451  return nodes[0];
452  }
453 
454  virtual const N* getNode(const std::string& name) const
455  {
456  std::vector<const N*> nodes;
457  TreeTemplateTools::searchNodeWithName<const N>(*root_, name, nodes);
458  if (nodes.size() > 1) throw NodeNotFoundException("TreeTemplate::getNode(): Non-unique name.", "" + name);
459  if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with name not found.", "" + name);
460  return nodes[0];
461  }
462 
463  void rootAt(N* newRoot)
464  {
465  if (root_ == newRoot) return;
466  if (isRooted()) unroot();
467  std::vector<Node*> path = TreeTemplateTools::getPathBetweenAnyTwoNodes(*root_, *newRoot);
468  for (size_t i = 0; i < path.size() - 1; i++)
469  {
470  if (path[i + 1]->hasDistanceToFather())
471  {
472  path[i]->setDistanceToFather(path[i + 1]->getDistanceToFather());
473  }
474  else path[i]->deleteDistanceToFather();
475  path[i]->removeSon(path[i + 1]);
476  path[i + 1]->addSon(path[i]);
477 
478  std::vector<std::string> names = path[i + 1]->getBranchPropertyNames();
479  for (size_t j = 0; j < names.size(); j++)
480  {
481  path[i]->setBranchProperty(names[j], *path[i + 1]->getBranchProperty(names[j]));
482  }
483  path[i + 1]->deleteBranchProperties();
484  }
485 
486  newRoot->deleteDistanceToFather();
487  newRoot->deleteBranchProperties();
488  root_ = newRoot;
489  }
490 
491  void newOutGroup(N* outGroup)
492  {
493  if (root_ == outGroup) return;
494  int rootId;
495  if (isRooted())
496  {
497  for (size_t i = 0; i < root_->getNumberOfSons(); i++)
498  {
499  if (root_->getSon(i) == outGroup) return; // This tree is already rooted appropriately.
500  }
501  rootId = getRootId();
502  unroot();
503  }
504  else
505  {
506  rootId = getNextId();
507  }
508  rootAt(dynamic_cast<N*>(outGroup->getFather()));
509  N* oldRoot = root_;
510  oldRoot->removeSon(outGroup);
511  root_ = new N();
512  root_->setId(rootId);
513  root_->addSon(oldRoot);
514  root_->addSon(outGroup);
515  // Check lengths:
516  if (outGroup->hasDistanceToFather())
517  {
518  double l = outGroup->getDistanceToFather() / 2.;
519  outGroup->setDistanceToFather(l);
520  oldRoot->setDistanceToFather(l);
521  }
522  }
523 
525 };
526 } // end of namespace bpp.
527 #endif // BPP_PHYL_TREE_TREETEMPLATE_H
Exception thrown when something is wrong with a particular node.
static size_t getNumberOfNodes(const Node &node)
Get the number of nodes of a subtree defined by a particular node.
static void setBranchLengths(Node &node, double brLen)
Set all the branch lengths of a subtree.
static bool hasNodeWithId(const N &node, int id)
static void deleteSubtree(N *node)
Recursively delete a subtree structure.
static std::vector< N * > getInnerNodes(N &node)
Retrieve all inner nodes from a subtree.
static size_t getNumberOfBranches(const Node &node)
Get the number of branches of a subtree defined by a particular node.
static void orderTree(Node &node, bool downward=true, bool orderLeaves=false)
Swap nodes in the subtree so that they are ordered according to the underlying number of leaves.
static std::vector< std::string > getLeavesNames(const Node &node)
Get the leaves names of a subtree defined by a particular node.
static std::vector< N * > getNodes(N &node)
Retrieve all son nodes from a subtree.
static Vdouble getBranchLengths(const Node &node)
Get all the branch lengths of a subtree.
static size_t getNumberOfLeaves(const Node &node)
Get the number of leaves of a subtree defined by a particular node.
static void scaleTree(Node &node, double factor)
Scale a given tree.
static std::vector< Node * > getPathBetweenAnyTwoNodes(Node &node1, Node &node2, bool includeAncestor=true, bool includeAncestorAtEndOfPath=true)
static Node * searchFirstNodeWithId(Node &node, int id)
static void setVoidBranchLengths(Node &node, double brLen)
Give a length to branches that don't have one in a subtree.
static std::vector< N * > searchNodeWithName(N &node, const std::string &name)
static double getTotalLength(const Node &node, bool includeAncestor=true)
Get the total length (sum of all branch lengths) of a subtree.
static bool isRoot(const Node &node)
Tell if a particular node is the root of a tree i.e. if it has a father node.
static std::vector< int > getInnerNodesId(const Node &node)
Retrieve all inner nodes ids from a subtree.
static std::vector< int > getAncestorsId(const Node &node)
Retrieve all nodes ids that are ancestors of a node.
static std::vector< int > getNodesId(const Node &node)
Retrieve all nodes ids from a subtree.
static std::vector< int > getLeavesId(const Node &node)
Retrieve all leaves ids from a subtree.
static std::vector< N * > getLeaves(N &node)
Retrieve all leaves from a subtree.
static bool isMultifurcating(const Node &node)
Tell is a subtree is multifurcating.
static bool haveSameOrderedTopology(const Node &n1, const Node &n2)
Tells if two subtrees have the same topology.
static int getLeafId(const Node &node, const std::string &name)
Get the id of a leaf given its name in a subtree.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
void setDistanceToFather(int nodeId, double length)
Definition: TreeTemplate.h:190
virtual std::vector< N * > getLeaves()
Definition: TreeTemplate.h:395
double getDistanceToFather(int nodeId) const
Definition: TreeTemplate.h:188
virtual void setRootNode(N *root)
Definition: TreeTemplate.h:387
bool unroot()
Unroot a rooted tree.
Definition: TreeTemplate.h:226
virtual ~TreeTemplate()
Definition: TreeTemplate.h:110
std::vector< double > getBranchLengths()
Get all the branch lengths of a tree.
Definition: TreeTemplate.h:329
double getTotalLength()
Get the total length (sum of all branch lengths) of a tree.
Definition: TreeTemplate.h:340
void swapNodes(int parentId, size_t i1, size_t i2)
Definition: TreeTemplate.h:374
std::string name_
Definition: TreeTemplate.h:66
size_t getNumberOfLeaves() const
Definition: TreeTemplate.h:129
bool isMultifurcating() const
Tell if the tree is multifurcating.
Definition: TreeTemplate.h:277
virtual const N * getNode(int id, bool checkId=false) const
Definition: TreeTemplate.h:425
std::vector< std::string > getNodePropertyNames(int nodeId) const
Definition: TreeTemplate.h:206
virtual std::vector< N * > getNodes()
Definition: TreeTemplate.h:399
void rootAt(N *newRoot)
Definition: TreeTemplate.h:463
std::vector< int > getLeavesId() const
Definition: TreeTemplate.h:137
TreeTemplate(N *root)
Definition: TreeTemplate.h:89
virtual std::vector< const N * > getNodes() const
Definition: TreeTemplate.h:397
void setName(const std::string &name)
Definition: TreeTemplate.h:125
void scaleTree(double factor)
Scale a given tree.
Definition: TreeTemplate.h:361
bool isRoot(int nodeId) const
Definition: TreeTemplate.h:186
bool isRooted() const
Tell if the tree is rooted.
Definition: TreeTemplate.h:224
TreeTemplate< N > * clone() const
Definition: TreeTemplate.h:116
bool hasNodeName(int nodeId) const
Definition: TreeTemplate.h:174
TreeTemplate< N > * cloneSubtree(int newRootId) const
clones a Subtree rooted at given node Id
Definition: TreeTemplate.h:104
std::vector< std::string > getLeavesNames() const
Definition: TreeTemplate.h:162
int getRootId() const
Definition: TreeTemplate.h:127
std::vector< int > getAncestorsId(int nodeId) const
Definition: TreeTemplate.h:166
std::vector< std::string > getBranchPropertyNames(int nodeId) const
Definition: TreeTemplate.h:218
void rootAt(int nodeId)
Change the root node.
Definition: TreeTemplate.h:220
TreeTemplate(const TreeTemplate< N > &t)
Definition: TreeTemplate.h:73
void resetNodesId()
Number nodes.
Definition: TreeTemplate.h:268
TreeTemplate< N > & operator=(const TreeTemplate< N > &t)
Definition: TreeTemplate.h:95
bool hasNodeProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:196
bool isLeaf(int nodeId) const
Definition: TreeTemplate.h:182
Clonable * getBranchProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:212
int getNextId()
Get an id.
Definition: TreeTemplate.h:369
Clonable * removeBranchProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:216
std::vector< double > getBranchLengths() const
Definition: TreeTemplate.h:160
int getLeafId(const std::string &name) const
Definition: TreeTemplate.h:135
const Clonable * getBranchProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:214
TreeTemplate(const Tree &t)
Definition: TreeTemplate.h:81
bool hasNode(int nodeId) const
Definition: TreeTemplate.h:180
bool hasSameTopologyAs(const TreeTemplate< N2 > &tree, bool ordered=false) const
Tells if this tree has the same topology as the one given for comparison.
Definition: TreeTemplate.h:302
void deleteNodeName(int nodeId)
Definition: TreeTemplate.h:178
std::vector< int > getSonsId(int parentId) const
Definition: TreeTemplate.h:164
virtual N * getNode(int id, bool checkId=false)
Definition: TreeTemplate.h:405
void setNodeName(int nodeId, const std::string &name)
Definition: TreeTemplate.h:176
virtual std::vector< const N * > getLeaves() const
Definition: TreeTemplate.h:393
virtual std::vector< const N * > getInnerNodes() const
Definition: TreeTemplate.h:401
virtual std::vector< N * > getInnerNodes()
Definition: TreeTemplate.h:403
bool hasNoSon(int nodeId) const
Definition: TreeTemplate.h:184
void setNodeProperty(int nodeId, const std::string &name, const Clonable &property)
Definition: TreeTemplate.h:198
Clonable * getNodeProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:200
std::string getName() const
Definition: TreeTemplate.h:123
bool hasDistanceToFather(int nodeId) const
Definition: TreeTemplate.h:194
std::vector< int > getBranchesId() const
Definition: TreeTemplate.h:143
std::vector< int > getInnerNodesId() const
Definition: TreeTemplate.h:141
std::vector< int > getNodesId() const
Definition: TreeTemplate.h:139
virtual N * getRootNode()
Definition: TreeTemplate.h:389
virtual const N * getRootNode() const
Definition: TreeTemplate.h:391
const Clonable * getNodeProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:202
void deleteDistanceToFather(int nodeId)
Definition: TreeTemplate.h:192
std::string getNodeName(int nodeId) const
Definition: TreeTemplate.h:172
int getFatherId(int parentId) const
Definition: TreeTemplate.h:168
bool hasFather(int nodeId) const
Definition: TreeTemplate.h:170
virtual N * getNode(const std::string &name)
Definition: TreeTemplate.h:445
void newOutGroup(N *outGroup)
Definition: TreeTemplate.h:491
virtual const N * getNode(const std::string &name) const
Definition: TreeTemplate.h:454
size_t getNumberOfNodes() const
Definition: TreeTemplate.h:131
Clonable * removeNodeProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:204
size_t getNumberOfBranches() const
Definition: TreeTemplate.h:133
void newOutGroup(int nodeId)
Root a tree by specifying an outgroup.
Definition: TreeTemplate.h:222
void setBranchProperty(int nodeId, const std::string &name, const Clonable &property)
Definition: TreeTemplate.h:210
bool hasBranchProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:208
void setVoidBranchLengths(double brLen)
Give a length to branches that don't have one in a tree.
Definition: TreeTemplate.h:353
void setBranchLengths(double brLen)
Set all the branch lengths of a tree.
Definition: TreeTemplate.h:345
static int getMPNUId(const Tree &tree, int id)
Get the minimum positive non-used identifier in a (sub)tree.
Definition: TreeTools.cpp:731
Interface for phylogenetic tree objects.
Definition: Tree.h:115
virtual int getRootId() const =0
Exception thrown when a tree is expected to be rooted.
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< int > Vint