bpp-phyl  2.2.0
bpp::NexusIOTree Class Reference

a simple parser for reading trees from a Nexus file. More...

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

+ Inheritance diagram for bpp::NexusIOTree:
+ Collaboration diagram for bpp::NexusIOTree:

Public Member Functions

 NexusIOTree ()
 Build a new Nexus tree parser. More...
 
virtual ~NexusIOTree ()
 
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)
 

Detailed Description

a simple parser for reading trees from a Nexus file.

This reader is not supposed to be a full parser of the Nexus files, but only extract the tree data. Only a basic subset of the options are and will be supported.

This format is described in the following paper: Maddison D, Swofford D, and Maddison W (1997), Syst Biol 46(4):590-621

Author
Julien Dutheil

Definition at line 61 of file NexusIoTree.h.

Constructor & Destructor Documentation

◆ NexusIOTree()

bpp::NexusIOTree::NexusIOTree ( )
inline

Build a new Nexus tree parser.

Definition at line 72 of file NexusIoTree.h.

◆ ~NexusIOTree()

virtual bpp::NexusIOTree::~NexusIOTree ( )
inlinevirtual

Definition at line 74 of file NexusIoTree.h.

Member Function Documentation

◆ getDataType()

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

Definition at line 68 of file IoTree.h.

◆ getFormatDescription()

const string NexusIOTree::getFormatDescription ( ) const

Definition at line 68 of file NexusIoTree.cpp.

◆ getFormatName()

const string NexusIOTree::getFormatName ( ) const

Definition at line 64 of file NexusIoTree.cpp.

◆ read() [1/4]

TreeTemplate<Node>* bpp::NexusIOTree::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 98 of file NexusIoTree.h.

References bpp::AbstractITree::read().

◆ read() [2/4]

TreeTemplate< Node > * NexusIOTree::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 80 of file NexusIoTree.cpp.

◆ read() [3/4]

void bpp::NexusIOTree::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 132 of file NexusIoTree.h.

References bpp::AbstractIMultiTree::read().

◆ read() [4/4]

void NexusIOTree::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 93 of file NexusIoTree.cpp.

References bpp::TreeTemplate< N >::getLeaves(), and bpp::TreeTemplateTools::parenthesisToTree().

◆ write() [1/4]

void bpp::NexusIOTree::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 117 of file NexusIoTree.h.

References bpp::AbstractOTree::write().

◆ write() [2/4]

void bpp::NexusIOTree::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 121 of file NexusIoTree.h.

References write_().

◆ write() [3/4]

void bpp::NexusIOTree::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 144 of file NexusIoTree.h.

References bpp::AbstractOMultiTree::write().

◆ write() [4/4]

void bpp::NexusIOTree::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 148 of file NexusIoTree.h.

References write_().

◆ write_() [1/4]

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

Definition at line 172 of file NexusIoTree.cpp.

Referenced by write().

◆ write_() [2/4]

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

Definition at line 182 of file NexusIoTree.cpp.

◆ write_() [3/4]

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

◆ write_() [4/4]

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

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