bpp-phyl  2.2.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)
 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 throw (Exception)
 Read a tree from a file. More...
 
TreeTemplate< Node > * read (std::istream &in) const throw (Exception)
 Read a tree from a stream. More...
 
The OTree interface
void write (const Tree &tree, const std::string &path, bool overwrite=true) const throw (Exception)
 Write a tree to a file. More...
 
void write (const Tree &tree, std::ostream &out) const throw (Exception)
 Write a tree to a stream. More...
 
The IMultiTree interface
void read (const std::string &path, std::vector< Tree *> &trees) const throw (Exception)
 Read trees from a file. More...
 
void read (std::istream &in, std::vector< Tree *> &trees) const throw (Exception)
 Read trees from a stream. More...
 
The OMultiTree interface
void write (const std::vector< Tree *> &trees, const std::string &path, bool overwrite=true) const throw (Exception)
 Write trees to a file. More...
 
void write (const std::vector< Tree *> &trees, std::ostream &out) const throw (Exception)
 Write trees to a stream. More...
 

Protected Member Functions

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

Protected Attributes

bool allowComments_
 
bool writeId_
 
bool useBootstrap_
 
std::string bootstrapPropertyName_
 

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

◆ Newick()

bpp::Newick::Newick ( bool  allowComments = false,
bool  writeId = 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.

Definition at line 105 of file Newick.h.

◆ ~Newick()

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

Definition at line 111 of file Newick.h.

Member Function Documentation

◆ disableExtendedBootstrapProperty()

void bpp::Newick::disableExtendedBootstrapProperty ( )
inline

Definition at line 120 of file Newick.h.

References bpp::TreeTools::BOOTSTRAP, bootstrapPropertyName_, and useBootstrap_.

◆ enableExtendedBootstrapProperty()

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

Definition at line 115 of file Newick.h.

References bootstrapPropertyName_, and useBootstrap_.

◆ getDataType()

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

Definition at line 68 of file IoTree.h.

◆ getFormatDescription()

const string Newick::getFormatDescription ( ) const

Definition at line 61 of file Newick.cpp.

◆ getFormatName()

const string Newick::getFormatName ( ) const

Definition at line 57 of file Newick.cpp.

◆ read() [1/4]

TreeTemplate<Node>* bpp::Newick::read ( const std::string &  path) const
throw (Exception
)
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 140 of file Newick.h.

References bpp::AbstractITree::read().

◆ read() [2/4]

TreeTemplate< Node > * Newick::read ( std::istream &  in) const
throw (Exception
)
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 74 of file Newick.cpp.

References bpp::TreeTemplateTools::parenthesisToTree().

◆ read() [3/4]

void bpp::Newick::read ( const std::string &  path,
std::vector< Tree *> &  trees 
) const
throw (Exception
)
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 169 of file Newick.h.

References bpp::AbstractIMultiTree::read().

◆ read() [4/4]

void Newick::read ( std::istream &  in,
std::vector< Tree *> &  trees 
) const
throw (Exception
)
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 134 of file Newick.cpp.

References bpp::TreeTemplateTools::parenthesisToTree().

◆ write() [1/4]

void bpp::Newick::write ( const Tree tree,
const std::string &  path,
bool  overwrite = true 
) const
throw (Exception
)
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 153 of file Newick.h.

References bpp::AbstractOTree::write().

◆ write() [2/4]

void bpp::Newick::write ( const Tree tree,
std::ostream &  out 
) const
throw (Exception
)
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 158 of file Newick.h.

References write_().

◆ write() [3/4]

void bpp::Newick::write ( const std::vector< Tree *> &  trees,
const std::string &  path,
bool  overwrite = true 
) const
throw (Exception
)
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 181 of file Newick.h.

References bpp::AbstractOMultiTree::write().

◆ write() [4/4]

void bpp::Newick::write ( const std::vector< Tree *> &  trees,
std::ostream &  out 
) const
throw (Exception
)
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 185 of file Newick.h.

References write_().

◆ write_() [1/4]

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

Definition at line 101 of file Newick.cpp.

References bpp::TreeTools::treeToParenthesis().

Referenced by write().

◆ write_() [2/4]

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

Definition at line 118 of file Newick.cpp.

References bpp::TreeTemplateTools::treeToParenthesis().

◆ write_() [3/4]

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

Definition at line 160 of file Newick.cpp.

References bpp::TreeTools::treeToParenthesis().

◆ write_() [4/4]

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

Definition at line 180 of file Newick.cpp.

References bpp::TreeTemplateTools::treeToParenthesis().

Member Data Documentation

◆ allowComments_

bool bpp::Newick::allowComments_
protected

Definition at line 90 of file Newick.h.

◆ bootstrapPropertyName_

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

Definition at line 93 of file Newick.h.

Referenced by disableExtendedBootstrapProperty(), and enableExtendedBootstrapProperty().

◆ useBootstrap_

bool bpp::Newick::useBootstrap_
protected

Definition at line 92 of file Newick.h.

Referenced by disableExtendedBootstrapProperty(), and enableExtendedBootstrapProperty().

◆ writeId_

bool bpp::Newick::writeId_
protected

Definition at line 91 of file Newick.h.


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