bpp-phyl  2.4.0
bpp::Newick Class Reference

The so-called 'newick' parenthetic format. More...

#include <Bpp/Phyl/Io/Newick.h>

+ Inheritance diagram for bpp::Newick:
+ Collaboration diagram for bpp::Newick:

Public Member Functions

 Newick (bool allowComments=false, bool writeId=false, bool verbose=false)
 Build a new Newick reader/writer. More...
 
virtual ~Newick ()
 
void enableExtendedBootstrapProperty (const std::string &propertyName)
 
void disableExtendedBootstrapProperty ()
 
virtual const std::string getDataType () const
 
The IOTree interface
const std::string getFormatName () const
 
const std::string getFormatDescription () const
 
The ITree interface
TreeTemplate< Node > * read (const std::string &path) const
 Read a tree from a file. More...
 
TreeTemplate< Node > * read (std::istream &in) const
 Read a tree from a stream. More...
 
The OTree interface
void write (const Tree &tree, const std::string &path, bool overwrite=true) const
 Write a tree to a file. More...
 
void write (const Tree &tree, std::ostream &out) const
 Write a tree to a stream. More...
 
The IMultiTree interface
void read (const std::string &path, std::vector< Tree * > &trees) const
 Read trees from a file. More...
 
void read (std::istream &in, std::vector< Tree * > &trees) const
 Read trees from a stream. More...
 
The OMultiTree interface
void write (const std::vector< Tree * > &trees, const std::string &path, bool overwrite=true) const
 Write trees to a file. More...
 
void write (const std::vector< Tree * > &trees, std::ostream &out) const
 Write trees to a stream. More...
 

Protected Member Functions

void write_ (const Tree &tree, std::ostream &out) const
 
template<class N >
void write_ (const TreeTemplate< N > &tree, std::ostream &out) const
 
void write_ (const std::vector< Tree * > &trees, std::ostream &out) const
 
template<class N >
void write_ (const std::vector< TreeTemplate< N > * > &trees, std::ostream &out) const
 

Protected Attributes

bool allowComments_
 
bool writeId_
 
bool useBootstrap_
 
std::string bootstrapPropertyName_
 
bool verbose_
 

Detailed Description

The so-called 'newick' parenthetic format.

Branch lengths and bootstraps are supported:

ex: ((A:0.1, B:0.15)90:0.2, C:0.27);

Code example:

#include <Phyl/Newick.h>
#include <Phyl/Tree.h>
Newick * newickReader = new Newick(false); //No comment allowed!
try {
Tree * tree = newickReader->read("MyTestTree.dnd"); // Tree in file MyTestTree.dnd
cout << "Tree has " << tree->getNumberOfLeaves() << " leaves." << endl;
} catch (Exception e) {
cout << "Error when reading tree." << endl;
}
delete tree;
delete newickReader;

Bootstrap values are stored as node properties, as Number<double> objects and with the tag TreeTools::BOOTSTRAP.

This is also possible to read a "tagged" tree, where additional info is provided in place of bootstrap values: ((A,B)N2,(C,D)N3)N1; This is achieved by calling the enableExtendedBootstrapProperty method, and providing a property name to use. The additional information will be stored at each node as a property, in a String object. The disableExtendedBootstrapProperty method restores the default behavior.

Definition at line 83 of file Newick.h.

Constructor & Destructor Documentation

bpp::Newick::Newick ( bool  allowComments = false,
bool  writeId = false,
bool  verbose = false 
)
inline

Build a new Newick reader/writer.

Some newick format allow comments between hooks ('[' ']').

Parameters
allowCommentsTell if comments between [] are allowed in file.
writeIdIf true, nodes ids will be written in place of bootstrap values.
verboseIf some info should be displayed, such as progress bar etc.

Definition at line 107 of file Newick.h.

virtual bpp::Newick::~Newick ( )
inlinevirtual

Definition at line 114 of file Newick.h.

Member Function Documentation

void bpp::Newick::disableExtendedBootstrapProperty ( )
inline

Definition at line 123 of file Newick.h.

References bpp::TreeTools::BOOTSTRAP, getFormatDescription(), and getFormatName().

void bpp::Newick::enableExtendedBootstrapProperty ( const std::string &  propertyName)
inline

Definition at line 118 of file Newick.h.

virtual const std::string bpp::IOTree::getDataType ( ) const
inlinevirtualinherited

Implements bpp::IOFormat.

Definition at line 68 of file IoTree.h.

const string Newick::getFormatDescription ( ) const
virtual

Implements bpp::IOFormat.

Definition at line 61 of file Newick.cpp.

Referenced by disableExtendedBootstrapProperty().

const string Newick::getFormatName ( ) const
virtual

Implements bpp::IOFormat.

Definition at line 57 of file Newick.cpp.

Referenced by disableExtendedBootstrapProperty().

TreeTemplate<Node>* bpp::Newick::read ( const std::string &  path) const
inlinevirtual

Read a tree from a file.

Parameters
pathThe file path.
Returns
A new tree object.
Exceptions
ExceptionIf an error occured.

Reimplemented from bpp::AbstractITree.

Definition at line 143 of file Newick.h.

References bpp::AbstractITree::read().

Referenced by read().

TreeTemplate< Node > * Newick::read ( std::istream &  in) const
virtual

Read a tree from a stream.

Parameters
inThe input stream.
Returns
A new tree object.
Exceptions
ExceptionIf an error occured.

Implements bpp::AbstractITree.

Definition at line 69 of file Newick.cpp.

References bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::parenthesisToTree(), and bpp::TextTools::removeSubstrings().

void bpp::Newick::read ( const std::string &  path,
std::vector< Tree * > &  trees 
) const
inlinevirtual

Read trees from a file.

Parameters
pathThe file path.
treesThe output trees container.
Exceptions
ExceptionIf an error occured.

Reimplemented from bpp::AbstractIMultiTree.

Definition at line 172 of file Newick.h.

References read(), and bpp::AbstractIMultiTree::read().

void Newick::read ( std::istream &  in,
std::vector< Tree * > &  trees 
) const
virtual

Read trees from a stream.

Parameters
inThe input stream.
treesThe output trees container.
Exceptions
ExceptionIf an error occured.

Implements bpp::AbstractIMultiTree.

Definition at line 129 of file Newick.cpp.

References bpp::TreeTemplateTools::parenthesisToTree(), and bpp::TextTools::removeSubstrings().

void bpp::Newick::write ( const Tree tree,
const std::string &  path,
bool  overwrite = true 
) const
inlinevirtual

Write a tree to a file.

Parameters
treeA tree object.
pathThe file path.
overwriteTell if existing file must be overwritten. Otherwise append to the file.
Exceptions
ExceptionIf an error occured.

Reimplemented from bpp::AbstractOTree.

Definition at line 156 of file Newick.h.

References bpp::AbstractOTree::write().

void bpp::Newick::write ( const Tree tree,
std::ostream &  out 
) const
inlinevirtual

Write a tree to a stream.

Parameters
treeA tree object.
outThe output stream.
Exceptions
ExceptionIf an error occured.

Implements bpp::AbstractOTree.

Definition at line 161 of file Newick.h.

References write_().

void bpp::Newick::write ( const std::vector< Tree * > &  trees,
const std::string &  path,
bool  overwrite = true 
) const
inlinevirtual

Write trees to a file.

Parameters
treesA vector of tree objects.
pathThe file path.
overwriteTell if existing file must be overwritten. Otherwise append to the file.
Exceptions
ExceptionIf an error occured.

Reimplemented from bpp::AbstractOMultiTree.

Definition at line 184 of file Newick.h.

References bpp::AbstractOMultiTree::write().

void bpp::Newick::write ( const std::vector< Tree * > &  trees,
std::ostream &  out 
) const
inlinevirtual

Write trees to a stream.

Parameters
treesA vector of tree objects.
outThe output stream.
Exceptions
ExceptionIf an error occured.

Implements bpp::AbstractOMultiTree.

Definition at line 188 of file Newick.h.

References write_().

void Newick::write_ ( const Tree tree,
std::ostream &  out 
) const
protected

Definition at line 96 of file Newick.cpp.

References bpp::TreeTools::treeToParenthesis().

Referenced by write().

template<class N >
void Newick::write_ ( const TreeTemplate< N > &  tree,
std::ostream &  out 
) const
protected

Definition at line 113 of file Newick.cpp.

References bpp::TreeTemplateTools::treeToParenthesis().

void Newick::write_ ( const std::vector< Tree * > &  trees,
std::ostream &  out 
) const
protected

Definition at line 155 of file Newick.cpp.

References bpp::TreeTools::treeToParenthesis().

template<class N >
void Newick::write_ ( const std::vector< TreeTemplate< N > * > &  trees,
std::ostream &  out 
) const
protected

Definition at line 175 of file Newick.cpp.

References bpp::TreeTemplateTools::treeToParenthesis().

Member Data Documentation

bool bpp::Newick::allowComments_
protected

Definition at line 90 of file Newick.h.

std::string bpp::Newick::bootstrapPropertyName_
protected

Definition at line 93 of file Newick.h.

bool bpp::Newick::useBootstrap_
protected

Definition at line 92 of file Newick.h.

bool bpp::Newick::verbose_
protected

Definition at line 94 of file Newick.h.

bool bpp::Newick::writeId_
protected

Definition at line 91 of file Newick.h.


The documentation for this class was generated from the following files: