bpp-phyl3 3.0.0
Tree.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_TREE_H
6#define BPP_PHYL_TREE_TREE_H
7
8
9#include "TreeExceptions.h"
10
11// From Utils:
12#include <Bpp/Clonable.h>
13
14// From the STL:
15#include <string>
16#include <vector>
17#include <map>
18
108namespace bpp
109{
113class Tree :
114 public virtual Clonable
115{
116public:
117 // Constructors and destructor:
118
119 Tree() {}
120 virtual ~Tree() {}
121
122 Tree* clone() const = 0;
123
129 virtual Tree* cloneSubtree(int newRootId) const = 0;
130
131public:
137 virtual std::string getName() const = 0;
138
139 virtual void setName(const std::string& name) = 0;
142 virtual size_t getNumberOfLeaves() const = 0;
143
144 virtual size_t getNumberOfNodes() const = 0;
145
146 virtual size_t getNumberOfBranches() const = 0;
147
148 virtual std::vector<double> getBranchLengths() const = 0;
149
150 virtual std::vector<std::string> getLeavesNames() const = 0;
151
157 virtual int getRootId() const = 0;
158
159 virtual int getLeafId(const std::string& name) const = 0;
160
161 virtual std::vector<int> getLeavesId() const = 0;
162
163 virtual std::vector<int> getNodesId() const = 0;
164
165 virtual std::vector<int> getInnerNodesId() const = 0;
166
167 virtual std::vector<int> getBranchesId() const = 0;
168
169 virtual std::vector<int> getSonsId(int parentId) const = 0;
170
171 virtual std::vector<int> getAncestorsId(int nodeId) const = 0;
172
173 virtual int getFatherId(int parentId) const = 0;
174
175 virtual bool hasFather(int nodeId) const = 0;
176
184 virtual std::string getNodeName(int nodeId) const = 0;
185
186 virtual void setNodeName(int nodeId, const std::string& name) = 0;
187
188 virtual void deleteNodeName(int nodeId) = 0;
189
190 virtual bool hasNodeName(int nodeId) const = 0;
198 virtual bool hasNode(int nodeId) const = 0;
199
200 virtual bool isLeaf(int nodeId) const = 0;
201
202 virtual bool hasNoSon(int nodeId) const = 0;
203
204 virtual bool isRoot(int nodeId) const = 0;
223 void swapNodes(const Tree& tree, int nodeId, size_t i1 = 0, size_t i2 = 1);
224
232 virtual double getDistanceToFather(int nodeId) const = 0;
233
234 virtual void setDistanceToFather(int nodeId, double length) = 0;
235
236 virtual void deleteDistanceToFather(int nodeId) = 0;
237
238 virtual bool hasDistanceToFather(int nodeId) const = 0;
246 virtual bool hasNodeProperty(int nodeId, const std::string& name) const = 0;
247
248 virtual void setNodeProperty(int nodeId, const std::string& name, const Clonable& property) = 0;
249
250 virtual Clonable* getNodeProperty(int nodeId, const std::string& name) = 0;
251
252 virtual const Clonable* getNodeProperty(int nodeId, const std::string& name) const = 0;
253
254 virtual Clonable* removeNodeProperty(int nodeId, const std::string& name) = 0;
255
256 virtual std::vector<std::string> getNodePropertyNames(int nodeId) const = 0;
264 virtual bool hasBranchProperty(int nodeId, const std::string& name) const = 0;
265
266 virtual void setBranchProperty(int nodeId, const std::string& name, const Clonable& property) = 0;
267
268 virtual Clonable* getBranchProperty(int nodeId, const std::string& name) = 0;
269
270 virtual const Clonable* getBranchProperty(int nodeId, const std::string& name) const = 0;
271
272 virtual Clonable* removeBranchProperty(int nodeId, const std::string& name) = 0;
273
274 virtual std::vector<std::string> getBranchPropertyNames(int nodeId) const = 0;
285 virtual void rootAt(int nodeId) = 0;
286
296 virtual void newOutGroup(int nodeId) = 0;
297
303 virtual bool isRooted() const = 0;
304
311 virtual bool unroot() = 0;
312
316 virtual void resetNodesId() = 0;
317
318 // Works on (multi)furcations:
319
325 virtual bool isMultifurcating() const = 0;
326
333 virtual std::vector<double> getBranchLengths() = 0;
334
341 virtual double getTotalLength() = 0;
342
348 virtual void setBranchLengths(double brLen) = 0;
349
355 virtual void setVoidBranchLengths(double brLen) = 0;
356
365 virtual void scaleTree(double factor) = 0;
366
372 virtual int getNextId() = 0;
373};
374} // end of namespace bpp.
375#endif // BPP_PHYL_TREE_TREE_H
Interface for phylogenetic tree objects.
Definition: Tree.h:115
virtual std::vector< std::string > getBranchPropertyNames(int nodeId) const =0
virtual Clonable * removeBranchProperty(int nodeId, const std::string &name)=0
virtual std::vector< std::string > getNodePropertyNames(int nodeId) const =0
virtual const Clonable * getBranchProperty(int nodeId, const std::string &name) const =0
virtual bool isRoot(int nodeId) const =0
void swapNodes(const Tree &tree, int nodeId, size_t i1=0, size_t i2=1)
Swap two son nodes.
virtual std::vector< int > getInnerNodesId() const =0
virtual bool isRooted() const =0
Tell if the tree is rooted.
virtual void setBranchLengths(double brLen)=0
Set all the branch lengths of a tree.
virtual size_t getNumberOfNodes() const =0
virtual bool hasFather(int nodeId) const =0
virtual void setDistanceToFather(int nodeId, double length)=0
virtual ~Tree()
Definition: Tree.h:120
virtual void setBranchProperty(int nodeId, const std::string &name, const Clonable &property)=0
virtual std::string getNodeName(int nodeId) const =0
virtual Clonable * removeNodeProperty(int nodeId, const std::string &name)=0
virtual const Clonable * getNodeProperty(int nodeId, const std::string &name) const =0
virtual std::vector< int > getSonsId(int parentId) const =0
virtual void setName(const std::string &name)=0
virtual int getFatherId(int parentId) const =0
virtual std::string getName() const =0
Tree name.
virtual bool hasNodeProperty(int nodeId, const std::string &name) const =0
virtual std::vector< int > getNodesId() const =0
virtual std::vector< double > getBranchLengths() const =0
virtual void resetNodesId()=0
Number nodes.
virtual bool unroot()=0
Unroot a rooted tree.
virtual int getNextId()=0
Get an id.
virtual bool hasNode(int nodeId) const =0
virtual std::vector< int > getAncestorsId(int nodeId) const =0
virtual void deleteNodeName(int nodeId)=0
virtual std::vector< int > getLeavesId() const =0
virtual bool isLeaf(int nodeId) const =0
virtual Clonable * getBranchProperty(int nodeId, const std::string &name)=0
virtual bool isMultifurcating() const =0
Tell if the tree is multifurcating.
virtual bool hasDistanceToFather(int nodeId) const =0
virtual Clonable * getNodeProperty(int nodeId, const std::string &name)=0
virtual void scaleTree(double factor)=0
Scale a given tree.
virtual double getTotalLength()=0
Get the total length (sum of all branch lengths) of a tree.
virtual bool hasNodeName(int nodeId) const =0
virtual void setNodeName(int nodeId, const std::string &name)=0
virtual void setVoidBranchLengths(double brLen)=0
Give a length to branches that don't have one in a tree.
virtual std::vector< std::string > getLeavesNames() const =0
virtual size_t getNumberOfBranches() const =0
virtual double getDistanceToFather(int nodeId) const =0
virtual bool hasNoSon(int nodeId) const =0
virtual void newOutGroup(int nodeId)=0
Root a tree by specifying an outgroup.
virtual bool hasBranchProperty(int nodeId, const std::string &name) const =0
virtual void deleteDistanceToFather(int nodeId)=0
virtual std::vector< double > getBranchLengths()=0
Get all the branch lengths of a tree.
virtual int getRootId() const =0
virtual void setNodeProperty(int nodeId, const std::string &name, const Clonable &property)=0
virtual Tree * cloneSubtree(int newRootId) const =0
clones a Subtree rooted at given node Id
virtual void rootAt(int nodeId)=0
Change the root node.
virtual std::vector< int > getBranchesId() const =0
virtual int getLeafId(const std::string &name) const =0
virtual size_t getNumberOfLeaves() const =0
Tree()
Definition: Tree.h:119
Tree * clone() const =0
Defines the basic types of data flow nodes.