bpp-phyl  2.2.0
Tree.h
Go to the documentation of this file.
1 //
2 // File: Tree.h
3 // Created by: Julien Dutheil
4 // Created on: Thu Mar 13 12:03:18 2003
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 
40 #ifndef _TREE_H_
41 #define _TREE_H_
42 
43 #include "TreeExceptions.h"
44 
45 // From Utils:
46 #include <Bpp/Clonable.h>
47 
48 // From the STL:
49 #include <string>
50 #include <vector>
51 #include <map>
52 
142 namespace bpp
143 {
144 
148  class Tree:
149  public virtual Clonable
150  {
151 
152  public: // Constructors and destructor:
153 
154  Tree() {}
155  virtual ~Tree() {}
156 
157  Tree* clone() const = 0;
158 
164  virtual Tree* cloneSubtree(int newRootId) const = 0;
165  public:
166 
172  virtual std::string getName() const = 0;
173 
174  virtual void setName(const std::string& name) = 0;
177  virtual size_t getNumberOfLeaves() const = 0;
178 
179  virtual size_t getNumberOfNodes() const = 0;
180 
181  virtual std::vector<double> getBranchLengths() const = 0;
182 
183  virtual std::vector<std::string> getLeavesNames() const = 0;
184 
190  virtual int getRootId() const = 0;
191 
192  virtual int getLeafId(const std::string& name) const throw (NodeNotFoundException)= 0;
193 
194  virtual std::vector<int> getLeavesId() const = 0;
195 
196  virtual std::vector<int> getNodesId() const = 0;
197 
198  virtual std::vector<int> getInnerNodesId() const = 0;
199 
200  virtual std::vector<int> getBranchesId() const = 0;
201 
202  virtual std::vector<int> getSonsId(int parentId) const throw (NodeNotFoundException) = 0;
203 
204  virtual std::vector<int> getAncestorsId(int nodeId) const throw (NodeNotFoundException) = 0;
205 
206  virtual int getFatherId(int parentId) const throw (NodeNotFoundException) = 0;
207 
208  virtual bool hasFather(int nodeId) const throw (NodeNotFoundException) = 0;
209 
217  virtual std::string getNodeName(int nodeId) const throw (NodeNotFoundException) = 0;
218 
219  virtual void setNodeName(int nodeId, const std::string& name) throw (NodeNotFoundException) = 0;
220 
221  virtual void deleteNodeName(int nodeId) throw (NodeNotFoundException) = 0;
222 
223  virtual bool hasNodeName(int nodeId) const throw (NodeNotFoundException) = 0;
231  virtual bool hasNode(int nodeId) const = 0;
232 
233  virtual bool isLeaf(int nodeId) const throw (NodeNotFoundException) = 0;
234 
235  virtual bool isRoot(int nodeId) const throw (NodeNotFoundException) = 0;
254  void swapNodes(const Tree& tree, int nodeId, size_t i1 = 0, size_t i2 = 1) throw (NodeNotFoundException,IndexOutOfBoundsException);
255 
263  virtual double getDistanceToFather(int nodeId) const = 0;
264 
265  virtual void setDistanceToFather(int nodeId, double length) = 0;
266 
267  virtual void deleteDistanceToFather(int nodeId) = 0;
268 
269  virtual bool hasDistanceToFather(int nodeId) const = 0;
277  virtual bool hasNodeProperty(int nodeId, const std::string& name) const throw (NodeNotFoundException) = 0;
278 
279  virtual void setNodeProperty(int nodeId, const std::string& name, const Clonable& property) throw (NodeNotFoundException) = 0;
280 
281  virtual Clonable* getNodeProperty(int nodeId, const std::string& name) throw (NodeNotFoundException) = 0;
282 
283  virtual const Clonable* getNodeProperty(int nodeId, const std::string& name) const throw (NodeNotFoundException) = 0;
284 
285  virtual Clonable* removeNodeProperty(int nodeId, const std::string& name) throw (NodeNotFoundException) = 0;
286 
287  virtual std::vector<std::string> getNodePropertyNames(int nodeId) const throw (NodeNotFoundException) = 0;
295  virtual bool hasBranchProperty(int nodeId, const std::string& name) const throw (NodeNotFoundException) = 0;
296 
297  virtual void setBranchProperty(int nodeId, const std::string& name, const Clonable & property) throw (NodeNotFoundException) = 0;
298 
299  virtual Clonable* getBranchProperty(int nodeId, const std::string& name) throw (NodeNotFoundException) = 0;
300 
301  virtual const Clonable* getBranchProperty(int nodeId, const std::string& name) const throw (NodeNotFoundException) = 0;
302 
303  virtual Clonable* removeBranchProperty(int nodeId, const std::string& name) throw (NodeNotFoundException) = 0;
304 
305  virtual std::vector<std::string> getBranchPropertyNames(int nodeId) const throw (NodeNotFoundException) = 0;
316  virtual void rootAt(int nodeId) throw (NodeNotFoundException) = 0;
317 
327  virtual void newOutGroup(int nodeId) throw (NodeNotFoundException) = 0;
328 
334  virtual bool isRooted() const = 0;
335 
342  virtual bool unroot() throw (UnrootedTreeException) = 0;
343 
347  virtual void resetNodesId() = 0;
348 
349  // Works on (multi)furcations:
350 
356  virtual bool isMultifurcating() const = 0;
357 
364  virtual std::vector<double> getBranchLengths() throw (NodeException) = 0;
365 
372  virtual double getTotalLength() throw (NodeException) = 0;
373 
379  virtual void setBranchLengths(double brLen) = 0;
380 
386  virtual void setVoidBranchLengths(double brLen) = 0;
387 
396  virtual void scaleTree(double factor) throw (NodeException) = 0;
397 
403  virtual int getNextId() = 0;
404 
405  };
406 
407 } //end of namespace bpp.
408 
409 #endif //_TREE_H_
410 
virtual Clonable * getNodeProperty(int nodeId, const std::string &name)=0
virtual size_t getNumberOfLeaves() const =0
virtual Tree * cloneSubtree(int newRootId) const =0
clones a Subtree rooted at given node Id
virtual void setVoidBranchLengths(double brLen)=0
Give a length to branches that don&#39;t have one in a tree.
virtual size_t getNumberOfNodes() const =0
virtual std::vector< std::string > getBranchPropertyNames(int nodeId) const =0
virtual std::vector< int > getInnerNodesId() const =0
virtual std::vector< int > getAncestorsId(int nodeId) const =0
Tree()
Definition: Tree.h:154
virtual int getRootId() const =0
virtual std::string getName() const =0
Tree name.
virtual void newOutGroup(int nodeId)=0
Root a tree by specifying an outgroup.
STL namespace.
virtual std::vector< int > getNodesId() const =0
virtual void scaleTree(double factor)=0
Scale a given tree.
virtual Clonable * removeNodeProperty(int nodeId, const std::string &name)=0
virtual void rootAt(int nodeId)=0
Change the root node.
virtual void setNodeName(int nodeId, const std::string &name)=0
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual bool hasNodeProperty(int nodeId, const std::string &name) const =0
virtual std::vector< int > getLeavesId() const =0
virtual void setBranchProperty(int nodeId, const std::string &name, const Clonable &property)=0
virtual int getFatherId(int parentId) const =0
virtual bool hasFather(int nodeId) const =0
virtual double getTotalLength()=0
Get the total length (sum of all branch lengths) of a tree.
virtual int getNextId()=0
Get an id.
virtual void setNodeProperty(int nodeId, const std::string &name, const Clonable &property)=0
virtual bool hasNode(int nodeId) const =0
virtual bool isLeaf(int nodeId) const =0
virtual std::vector< double > getBranchLengths() const =0
virtual ~Tree()
Definition: Tree.h:155
virtual bool hasBranchProperty(int nodeId, const std::string &name) const =0
virtual void setName(const std::string &name)=0
Exception thrown when something is wrong with a particular node.
virtual void deleteDistanceToFather(int nodeId)=0
virtual std::vector< std::string > getLeavesNames() const =0
virtual Clonable * removeBranchProperty(int nodeId, const std::string &name)=0
void swapNodes(const Tree &tree, int nodeId, size_t i1=0, size_t i2=1)
Swap two son nodes.
virtual void setDistanceToFather(int nodeId, double length)=0
virtual std::vector< std::string > getNodePropertyNames(int nodeId) const =0
virtual double getDistanceToFather(int nodeId) const =0
virtual bool unroot()=0
Unroot a rooted tree.
virtual bool hasNodeName(int nodeId) const =0
virtual bool isMultifurcating() const =0
Tell if the tree is multifurcating.
virtual int getLeafId(const std::string &name) const =0
virtual bool isRoot(int nodeId) const =0
virtual bool hasDistanceToFather(int nodeId) const =0
Exception thrown when a tree is expected to be rooted.
virtual std::vector< int > getBranchesId() const =0
virtual void deleteNodeName(int nodeId)=0
virtual void resetNodesId()=0
Number nodes.
virtual Clonable * getBranchProperty(int nodeId, const std::string &name)=0
virtual std::vector< int > getSonsId(int parentId) const =0
Tree * clone() const =0
General exception thrown when something is wrong with a particular node.
virtual void setBranchLengths(double brLen)=0
Set all the branch lengths of a tree.
virtual bool isRooted() const =0
Tell if the tree is rooted.
virtual std::string getNodeName(int nodeId) const =0