bpp-phyl  2.2.0
Newick.h
Go to the documentation of this file.
1 //
2 // File: Newick.h
3 // Created by: Julien Dutheil
4 // Created on: Thu Oct 23 15:35:03 2003
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (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 _NEWICK_H_
41 #define _NEWICK_H_
42 
43 #include "IoTree.h"
44 #include "../TreeTemplate.h"
45 
46 namespace bpp
47 {
48 
83 class Newick:
84  public AbstractITree,
85  public AbstractOTree,
86  public AbstractIMultiTree,
87  public AbstractOMultiTree
88 {
89  protected:
91  bool writeId_;
94 
95  public:
96 
105  Newick(bool allowComments = false, bool writeId = false):
106  allowComments_(allowComments),
107  writeId_(writeId),
108  useBootstrap_(true),
109  bootstrapPropertyName_(TreeTools::BOOTSTRAP) {}
110 
111  virtual ~Newick() {}
112 
113  public:
114 
115  void enableExtendedBootstrapProperty(const std::string& propertyName)
116  {
117  useBootstrap_ = false;
118  bootstrapPropertyName_ = propertyName;
119  }
121  {
122  useBootstrap_ = true;
124  }
125 
131  const std::string getFormatName() const;
132  const std::string getFormatDescription() const;
133  /* @} */
134 
140  TreeTemplate<Node>* read(const std::string& path) const throw (Exception)
141  {
142  return dynamic_cast<TreeTemplate<Node>*>(AbstractITree::read(path));
143  }
144 
145  TreeTemplate<Node>* read(std::istream& in) const throw (Exception);
153  void write(const Tree& tree, const std::string& path, bool overwrite = true) const throw (Exception)
154  {
155  AbstractOTree::write(tree, path, overwrite);
156  }
157 
158  void write(const Tree& tree, std::ostream& out) const throw (Exception)
159  {
160  write_(tree, out);
161  }
169  void read(const std::string& path, std::vector<Tree*>& trees) const throw (Exception)
170  {
171  AbstractIMultiTree::read(path, trees);
172  }
173  void read(std::istream& in, std::vector<Tree*>& trees) const throw (Exception);
181  void write(const std::vector<Tree*>& trees, const std::string& path, bool overwrite = true) const throw (Exception)
182  {
183  AbstractOMultiTree::write(trees, path, overwrite);
184  }
185  void write(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception)
186  {
187  write_(trees, out);
188  }
191  protected:
192  void write_(const Tree& tree, std::ostream& out) const throw (Exception);
193 
194  template<class N>
195  void write_(const TreeTemplate<N>& tree, std::ostream& out) const throw (Exception);
196 
197  void write_(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception);
198 
199  template<class N>
200  void write_(const std::vector<TreeTemplate<N>*>& trees, std::ostream& out) const throw (Exception);
201 
202 };
203 
204 } //end of namespace bpp.
205 
206 #endif //_NEWICK_H_
207 
void write(const std::vector< Tree *> &trees, std::ostream &out) const =0
Write trees to a stream.
const std::string getFormatName() const
Definition: Newick.cpp:57
Generic utilitary methods dealing with trees.
Definition: TreeTools.h:66
void write(const Tree &tree, std::ostream &out) const =0
Write a tree to a stream.
Partial implementation of the ITree interface.
Definition: IoTree.h:134
bool writeId_
Definition: Newick.h:91
void write(const std::vector< Tree *> &trees, const std::string &path, bool overwrite=true) const
Write trees to a file.
Definition: Newick.h:181
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
void write(const Tree &tree, std::ostream &out) const
Write a tree to a stream.
Definition: Newick.h:158
const std::string getFormatDescription() const
Definition: Newick.cpp:61
bool allowComments_
Definition: Newick.h:90
virtual ~Newick()
Definition: Newick.h:111
TreeTemplate< Node > * read(const std::string &path) const
Read a tree from a file.
Definition: Newick.h:140
The so-called &#39;newick&#39; parenthetic format.
Definition: Newick.h:83
virtual Tree * read(std::istream &in) const =0
Read a tree from a stream.
void read(const std::string &path, std::vector< Tree *> &trees) const
Read trees from a file.
Definition: Newick.h:169
void write(const Tree &tree, const std::string &path, bool overwrite=true) const
Write a tree to a file.
Definition: Newick.h:153
virtual void read(std::istream &in, std::vector< Tree *> &trees) const =0
Read trees from a stream.
bool useBootstrap_
Definition: Newick.h:92
static const std::string BOOTSTRAP
Bootstrap tag.
Definition: TreeTools.h:723
void write_(const Tree &tree, std::ostream &out) const
Definition: Newick.cpp:101
void write(const std::vector< Tree *> &trees, std::ostream &out) const
Write trees to a stream.
Definition: Newick.h:185
std::string bootstrapPropertyName_
Definition: Newick.h:93
Partial implementation of the OTree interface.
Definition: IoTree.h:156
void disableExtendedBootstrapProperty()
Definition: Newick.h:120
Partial implementation of the OTree interface.
Definition: IoTree.h:274
Partial implementation of the IMultiTree interface.
Definition: IoTree.h:253
void enableExtendedBootstrapProperty(const std::string &propertyName)
Definition: Newick.h:115
Newick(bool allowComments=false, bool writeId=false)
Build a new Newick reader/writer.
Definition: Newick.h:105