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
18namespace bpp
19{
56template<class N>
58 public Tree
59{
64private:
66 std::string name_;
67
68public:
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.rootNode());
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.rootNode());
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
111 {
113 delete root_;
114 }
115
116 TreeTemplate<N>* clone() const { return new TreeTemplate<N>(*this); }
117
122public:
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->rootNode(), true, true);
316 TreeTemplateTools::orderTree(t2tmp->rootNode(), 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
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
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 N& rootNode()
394 {
395 if (root_)
396 {
397 return *root_;
398 }
399 else
400 {
401 throw NullPointerException("TreeTemplate::rootNode. No associated root node.");
402 }
403 }
404
405 virtual const N& rootNode() const
406 {
407 if (root_)
408 {
409 return *root_;
410 }
411 else
412 {
413 throw NullPointerException("TreeTemplate::rootNode const. No associated root node.");
414 }
415 }
416
417 virtual std::vector<const N*> getLeaves() const { return TreeTemplateTools::getLeaves(*const_cast<const N*>(root_)); }
418
419 virtual std::vector<N*> getLeaves() { return TreeTemplateTools::getLeaves(*root_); }
420
421 virtual std::vector<const N*> getNodes() const { return TreeTemplateTools::getNodes(*const_cast<const N*>(root_)); }
422
423 virtual std::vector<N*> getNodes() { return TreeTemplateTools::getNodes(*root_); }
424
425 virtual std::vector<const N*> getInnerNodes() const { return TreeTemplateTools::getInnerNodes(*const_cast<const N*>(root_)); }
426
427 virtual std::vector<N*> getInnerNodes() { return TreeTemplateTools::getInnerNodes(*root_); }
428
429 virtual N* getNode(int id, bool checkId = false)
430 {
431 if (checkId)
432 {
433 std::vector<N*> nodes;
434 TreeTemplateTools::searchNodeWithId<N>(*dynamic_cast<N*>(root_), id, nodes);
435 if (nodes.size() > 1) throw Exception("TreeTemplate::getNode(): Non-unique id! (" + TextTools::toString(id) + ").");
436 if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
437 return nodes[0];
438 }
439 else
440 {
441 N* node = dynamic_cast<N*>(TreeTemplateTools::searchFirstNodeWithId(*root_, id));
442 if (node)
443 return node;
444 else
445 throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
446 }
447 }
448
449 virtual const N* getNode(int id, bool checkId = false) const
450 {
451 if (checkId)
452 {
453 std::vector<const N*> nodes;
454 TreeTemplateTools::searchNodeWithId<const N>(*root_, id, nodes);
455 if (nodes.size() > 1) throw Exception("TreeTemplate::getNode(): Non-unique id! (" + TextTools::toString(id) + ").");
456 if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
457 return nodes[0];
458 }
459 else
460 {
461 const N* node = dynamic_cast<const N*>(TreeTemplateTools::searchFirstNodeWithId(*root_, id));
462 if (node)
463 return node;
464 else
465 throw NodeNotFoundException("TreeTemplate::getNode(): Node with id not found.", TextTools::toString(id));
466 }
467 }
468
469 virtual N* getNode(const std::string& name)
470 {
471 std::vector<N*> nodes;
473 if (nodes.size() > 1) throw NodeNotFoundException("TreeTemplate::getNode(): Non-unique name.", "" + name);
474 if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with name not found.", "" + name);
475 return nodes[0];
476 }
477
478 virtual const N* getNode(const std::string& name) const
479 {
480 std::vector<const N*> nodes;
481 TreeTemplateTools::searchNodeWithName<const N>(*root_, name, nodes);
482 if (nodes.size() > 1) throw NodeNotFoundException("TreeTemplate::getNode(): Non-unique name.", "" + name);
483 if (nodes.size() == 0) throw NodeNotFoundException("TreeTemplate::getNode(): Node with name not found.", "" + name);
484 return nodes[0];
485 }
486
487 void rootAt(N* newRoot)
488 {
489 if (root_ == newRoot) return;
490 if (isRooted()) unroot();
491 std::vector<Node*> path = TreeTemplateTools::getPathBetweenAnyTwoNodes(*root_, *newRoot);
492 for (size_t i = 0; i < path.size() - 1; i++)
493 {
494 if (path[i + 1]->hasDistanceToFather())
495 {
496 path[i]->setDistanceToFather(path[i + 1]->getDistanceToFather());
497 }
498 else path[i]->deleteDistanceToFather();
499 path[i]->removeSon(path[i + 1]);
500 path[i + 1]->addSon(path[i]);
501
502 std::vector<std::string> names = path[i + 1]->getBranchPropertyNames();
503 for (size_t j = 0; j < names.size(); j++)
504 {
505 path[i]->setBranchProperty(names[j], *path[i + 1]->getBranchProperty(names[j]));
506 }
507 path[i + 1]->deleteBranchProperties();
508 }
509
510 newRoot->deleteDistanceToFather();
511 newRoot->deleteBranchProperties();
512 root_ = newRoot;
513 }
514
515 void newOutGroup(N* outGroup)
516 {
517 if (root_ == outGroup) return;
518 int rootId;
519 if (isRooted())
520 {
521 for (size_t i = 0; i < root_->getNumberOfSons(); i++)
522 {
523 if (root_->getSon(i) == outGroup) return; // This tree is already rooted appropriately.
524 }
525 rootId = getRootId();
526 unroot();
527 }
528 else
529 {
530 rootId = getNextId();
531 }
532 rootAt(dynamic_cast<N*>(outGroup->getFather()));
533 N* oldRoot = root_;
534 oldRoot->removeSon(outGroup);
535 root_ = new N();
536 root_->setId(rootId);
537 root_->addSon(oldRoot);
538 root_->addSon(outGroup);
539 // Check lengths:
540 if (outGroup->hasDistanceToFather())
541 {
542 double l = outGroup->getDistanceToFather() / 2.;
543 outGroup->setDistanceToFather(l);
544 oldRoot->setDistanceToFather(l);
545 }
546 }
547
549};
550} // end of namespace bpp.
551#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 std::vector< N * > searchNodeWithName(N &node, const std::string &name)
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< int > getLeavesId(const Node &node)
Retrieve all leaves ids 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 std::vector< N * > getNodes(N &node)
Retrieve all son nodes from a subtree.
static void setVoidBranchLengths(Node &node, double brLen)
Give a length to branches that don't have one in a subtree.
static std::vector< int > getNodesId(const Node &node)
Retrieve all nodes ids from a subtree.
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 > getAncestorsId(const Node &node)
Retrieve all nodes ids that are ancestors of a node.
static Node * searchFirstNodeWithId(Node &node, int id)
static bool isMultifurcating(const Node &node)
Tell is a subtree is multifurcating.
static std::vector< int > getInnerNodesId(const Node &node)
Retrieve all inner nodes ids from a subtree.
static bool haveSameOrderedTopology(const Node &n1, const Node &n2)
Tells if two subtrees have the same topology.
static std::vector< N * > getLeaves(N &node)
Retrieve all leaves from a subtree.
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 * > getNodes()
Definition: TreeTemplate.h:423
double getDistanceToFather(int nodeId) const
Definition: TreeTemplate.h:188
Clonable * getBranchProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:212
std::vector< std::string > getBranchPropertyNames(int nodeId) const
Definition: TreeTemplate.h:218
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
virtual const N * getNode(int id, bool checkId=false) const
Definition: TreeTemplate.h:449
std::vector< int > getAncestorsId(int nodeId) const
Definition: TreeTemplate.h:166
Clonable * getNodeProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:200
double getTotalLength()
Get the total length (sum of all branch lengths) of a tree.
Definition: TreeTemplate.h:340
const Clonable * getBranchProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:214
std::vector< int > getNodesId() const
Definition: TreeTemplate.h:139
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
void rootAt(N *newRoot)
Definition: TreeTemplate.h:487
virtual std::vector< N * > getLeaves()
Definition: TreeTemplate.h:419
TreeTemplate(N *root)
Definition: TreeTemplate.h:89
std::vector< int > getLeavesId() const
Definition: TreeTemplate.h:137
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
bool hasNodeName(int nodeId) const
Definition: TreeTemplate.h:174
virtual N * getNode(const std::string &name)
Definition: TreeTemplate.h:469
int getRootId() const
Definition: TreeTemplate.h:127
std::vector< std::string > getNodePropertyNames(int nodeId) const
Definition: TreeTemplate.h:206
TreeTemplate< N > & operator=(const TreeTemplate< N > &t)
Definition: TreeTemplate.h:95
std::vector< double > getBranchLengths()
Get all the branch lengths of a tree.
Definition: TreeTemplate.h:329
std::vector< int > getBranchesId() const
Definition: TreeTemplate.h:143
void rootAt(int nodeId)
Change the root node.
Definition: TreeTemplate.h:220
TreeTemplate(const TreeTemplate< N > &t)
Definition: TreeTemplate.h:73
virtual N * getRootNode()
Definition: TreeTemplate.h:389
void resetNodesId()
Number nodes.
Definition: TreeTemplate.h:268
std::vector< int > getSonsId(int parentId) const
Definition: TreeTemplate.h:164
virtual std::vector< N * > getInnerNodes()
Definition: TreeTemplate.h:427
TreeTemplate< N > * clone() const
Definition: TreeTemplate.h:116
bool hasNodeProperty(int nodeId, const std::string &name) const
Definition: TreeTemplate.h:196
Clonable * removeBranchProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:216
bool isLeaf(int nodeId) const
Definition: TreeTemplate.h:182
int getNextId()
Get an id.
Definition: TreeTemplate.h:369
int getLeafId(const std::string &name) const
Definition: TreeTemplate.h:135
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
TreeTemplate< N > * cloneSubtree(int newRootId) const
clones a Subtree rooted at given node Id
Definition: TreeTemplate.h:104
void setNodeName(int nodeId, const std::string &name)
Definition: TreeTemplate.h:176
virtual const N * getNode(const std::string &name) const
Definition: TreeTemplate.h:478
std::vector< double > getBranchLengths() const
Definition: TreeTemplate.h:160
bool hasNoSon(int nodeId) const
Definition: TreeTemplate.h:184
void setNodeProperty(int nodeId, const std::string &name, const Clonable &property)
Definition: TreeTemplate.h:198
std::string getName() const
Definition: TreeTemplate.h:123
bool hasDistanceToFather(int nodeId) const
Definition: TreeTemplate.h:194
std::vector< int > getInnerNodesId() const
Definition: TreeTemplate.h:141
virtual std::vector< const N * > getNodes() const
Definition: TreeTemplate.h:421
virtual N & rootNode()
Definition: TreeTemplate.h:393
virtual std::vector< const N * > getInnerNodes() const
Definition: TreeTemplate.h:425
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
void newOutGroup(N *outGroup)
Definition: TreeTemplate.h:515
size_t getNumberOfNodes() const
Definition: TreeTemplate.h:131
virtual N * getNode(int id, bool checkId=false)
Definition: TreeTemplate.h:429
size_t getNumberOfBranches() const
Definition: TreeTemplate.h:133
virtual const N * getRootNode() const
Definition: TreeTemplate.h:391
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
virtual std::vector< const N * > getLeaves() const
Definition: TreeTemplate.h:417
void setVoidBranchLengths(double brLen)
Give a length to branches that don't have one in a tree.
Definition: TreeTemplate.h:353
virtual const N & rootNode() const
Definition: TreeTemplate.h:405
Clonable * removeNodeProperty(int nodeId, const std::string &name)
Definition: TreeTemplate.h:204
std::vector< std::string > getLeavesNames() const
Definition: TreeTemplate.h:162
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:730
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