3
// Created by: Julien Dutheil
4
// Created on: Thu Oct 23 15:35:03 2003
8
Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for phylogenetic data analysis.
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".
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
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.
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.
42
#include "../TreeTemplate.h"
43
#include "../TreeTemplateTools.h"
45
#include <Bpp/Text/TextTools.h>
55
/******************************************************************************/
57
const string Newick::getFormatName() const { return "Newick"; }
59
/******************************************************************************/
61
const string Newick::getFormatDescription() const
63
return string("New hampshire parenthesis format. ") +
64
"See http://evolution.genetics.washington.edu/phylip/newicktree.html for more info.";
67
/******************************************************************************/
69
#if defined(NO_VIRTUAL_COV)
74
Newick::read(istream& in) const throw (Exception)
76
// Checking the existence of specified file
77
if (! in) { throw IOException ("Newick::read: failed to read from stream"); }
79
//We concatenate all line in file till we reach the ending semi colon:
80
string temp, description;// Initialization
81
// Main loop : for all file lines
84
getline(in, temp, '\n'); // Copy current line in temporary string
85
string::size_type index = temp.find(";");
86
if(index != string::npos)
88
description += temp.substr(0, index + 1);
91
else description += temp;
93
if (allowComments_) description = TextTools::removeSubstrings(description, '[', ']');
94
return TreeTemplateTools::parenthesisToTree(description, useBootstrap_, bootstrapPropertyName_);
97
/******************************************************************************/
99
void Newick::write_(const Tree& tree, ostream& out) const throw (Exception)
101
// Checking the existence of specified file, and possibility to open it in write mode
102
if (! out) { throw IOException ("Newick::writeTree: failed to write to stream"); }
105
out << TreeTools::treeToParenthesis(tree, writeId_);
109
out << TreeTools::treeToParenthesis(tree, false, bootstrapPropertyName_);
113
/******************************************************************************/
116
void Newick::write_(const TreeTemplate<N>& tree, ostream& out) const throw (Exception)
118
// Checking the existence of specified file, and possibility to open it in write mode
119
if (! out) { throw IOException ("Newick::writeTree: failed to write to stream"); }
122
out << TreeTemplateTools::treeToParenthesis(tree, writeId_);
126
out << TreeTemplateTools::treeToParenthesis(tree, false, bootstrapPropertyName_);
130
/******************************************************************************/
132
void Newick::read(istream& in, vector<Tree*>& trees) const throw (Exception)
134
// Checking the existence of specified file
135
if (! in) { throw IOException ("Newick::read: failed to read from stream"); }
137
// Main loop : for all file lines
138
string temp, description;// Initialization
139
string::size_type index;
142
//We concatenate all line in file till we reach the ending semi colon:
145
getline(in, temp, '\n'); // Copy current line in temporary string
146
index = temp.find(";");
147
if (index != string::npos)
149
description += temp.substr(0, index + 1);
150
if (allowComments_) description = TextTools::removeSubstrings(description, '[', ']');
151
trees.push_back(TreeTemplateTools::parenthesisToTree(description, useBootstrap_, bootstrapPropertyName_));
152
description = temp.substr(index + 1);
154
else description += temp;
159
/******************************************************************************/
161
void Newick::write_(const vector<Tree*>& trees, ostream& out) const throw (Exception)
163
// Checking the existence of specified file, and possibility to open it in write mode
164
if (! out) { throw IOException ("Newick::write: failed to write to stream"); }
165
for(unsigned int i = 0; i < trees.size(); i++)
169
out << TreeTools::treeToParenthesis(*trees[i], writeId_);
173
out << TreeTools::treeToParenthesis(*trees[i], false, bootstrapPropertyName_);
178
/******************************************************************************/
181
void Newick::write_(const vector<TreeTemplate<N>*>& trees, ostream& out) const throw (Exception)
183
// Checking the existence of specified file, and possibility to open it in write mode
184
if (! out) { throw IOException ("Newick::write: failed to write to stream"); }
185
for(unsigned int i = 0; i < trees.size(); i++)
189
out << TreeTemplateTools::treeToParenthesis(*trees[i], writeId_);
193
out << TreeTemplateTools::treeToParenthesis(*trees[i], false, bootstrapPropertyName_);
198
/******************************************************************************/