42 #include "../TreeTemplate.h" 43 #include "../TreeTemplateTools.h" 45 #include <Bpp/Text/TextTools.h> 63 return string(
"New hampshire parenthesis format. ") +
64 "See http://evolution.genetics.washington.edu/phylip/newicktree.html for more info.";
69 #if defined(NO_VIRTUAL_COV) 77 if (! in) {
throw IOException (
"Newick::read: failed to read from stream"); }
80 string temp, description;
82 while (getline(in, temp,
'\n'))
84 string::size_type index = temp.find(
";");
85 if(index != string::npos)
87 description += temp.substr(0, index + 1);
90 else description += temp;
93 if (allowComments_) description = TextTools::removeSubstrings(description,
'[',
']');
94 if (TextTools::isEmpty(description))
95 throw IOException(
"Newick::read: no tree was found!");
104 if (! out) {
throw IOException (
"Newick::writeTree: failed to write to stream"); }
121 if (! out) {
throw IOException (
"Newick::writeTree: failed to write to stream"); }
134 void Newick::read(istream& in, vector<Tree*>& trees)
const throw (Exception)
137 if (! in) {
throw IOException (
"Newick::read: failed to read from stream"); }
140 string temp, description;
141 string::size_type index;
143 while (getline(in, temp,
'\n'))
145 index = temp.find(
";");
146 if (index != string::npos)
148 description += temp.substr(0, index + 1);
149 if (allowComments_) description = TextTools::removeSubstrings(description,
'[',
']');
151 description = temp.substr(index + 1);
153 else description += temp;
160 void Newick::write_(
const vector<Tree*>& trees, ostream& out)
const throw (Exception)
163 if (! out) {
throw IOException (
"Newick::write: failed to write to stream"); }
164 for(
unsigned int i = 0; i < trees.size(); i++)
183 if (! out) {
throw IOException (
"Newick::write: failed to write to stream"); }
184 for(
unsigned int i = 0; i < trees.size(); i++)
const std::string getFormatName() const
The phylogenetic tree class.
Interface for phylogenetic tree objects.
const std::string getFormatDescription() const
TreeTemplate< Node > * read(const std::string &path) const
Read a tree from a file.
void write_(const Tree &tree, std::ostream &out) const