bpp-phyl3  3.0.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 ()
 
std::unique_ptr< TreereadTree (std::istream &in) const override
 Read a tree from a stream. More...
 
std::unique_ptr< TreereadTree (const std::string &path) const override
 Read a tree from a file. More...
 
virtual std::unique_ptr< TreeTemplate< Node > > readTreeTemplate (const std::string &path) const
 
virtual Element getElement (const std::string &elt) const
 
virtual const std::string getDataType () const
 
virtual void writeTree (const Tree &tree, const std::string &path, bool overwrite) const
 Write a tree to a file. More...
 
virtual void readTrees (const std::string &path, std::vector< std::unique_ptr< Tree >> &trees) const override
 Read trees from a file. More...
 
virtual void writeTrees (const std::vector< const Tree * > &trees, const std::string &path, bool overwrite) const
 Write trees to a file. More...
 
std::unique_ptr< PhyloTreereadPhyloTree (const std::string &path) const override
 Read a tree from a file. More...
 
Element getElement (const std::string &elt) const
 
virtual void writePhyloTree (const PhyloTree &tree, const std::string &path, bool overwrite) const
 Write a tree to a file. More...
 
virtual void readPhyloTrees (const std::string &path, std::vector< std::unique_ptr< PhyloTree >> &trees) const override
 Read trees from a file. More...
 
virtual void writePhyloTrees (const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const
 Write trees to a file. More...
 
The IOTree interface
const std::string getFormatName () const override
 
const std::string getFormatDescription () const override
 
The ITree interface
std::unique_ptr< TreeTemplate< Node > > readTreeTemplate (std::istream &in) const override
 
std::unique_ptr< PhyloTreereadPhyloTree (std::istream &in) const override
 Read a tree from a stream. More...
 
virtual std::unique_ptr< TreeTemplate< Node > > readTreeTemplate (std::istream &in) const=0
 
virtual std::unique_ptr< TreeTemplate< Node > > readTreeTemplate (const std::string &path) const
 
std::unique_ptr< PhyloTreereadPhyloTree (std::istream &in) const override=0
 
std::unique_ptr< PhyloTreereadPhyloTree (const std::string &path) const override
 
The OTree interface
void writeTree (const Tree &tree, std::ostream &out) const override
 Write a tree to a stream. More...
 
void writePhyloTree (const PhyloTree &tree, std::ostream &out) const override
 Write a tree to a stream. More...
 
virtual void writeTree (const Tree &tree, std::ostream &out) const=0
 
virtual void writeTree (const Tree &tree, const std::string &path, bool overwrite) const
 
virtual void writePhyloTree (const PhyloTree &tree, std::ostream &out) const=0
 
virtual void writePhyloTree (const PhyloTree &tree, const std::string &path, bool overwrite) const
 
The IMultiTree interface
void readTrees (std::istream &in, std::vector< std::unique_ptr< Tree >> &trees) const override
 Read trees from a stream. More...
 
void readPhyloTrees (std::istream &in, std::vector< std::unique_ptr< PhyloTree >> &trees) const override
 Read trees from a stream. More...
 
virtual void readTrees (std::istream &in, std::vector< std::unique_ptr< Tree >> &trees) const override=0
 
virtual void readTrees (const std::string &path, std::vector< std::unique_ptr< Tree >> &trees) const override
 
virtual void readPhyloTrees (std::istream &in, std::vector< std::unique_ptr< PhyloTree >> &trees) const override=0
 
virtual void readPhyloTrees (const std::string &path, std::vector< std::unique_ptr< PhyloTree >> &trees) const override
 
The OMultiTree interface
void writeTrees (const std::vector< const Tree * > &trees, std::ostream &out) const override
 Write trees to a stream. More...
 
void writePhyloTrees (const std::vector< const PhyloTree * > &trees, std::ostream &out) const override
 Write trees to a stream. More...
 
virtual void writeTrees (const std::vector< const Tree * > &trees, std::ostream &out) const=0
 
virtual void writeTrees (const std::vector< const Tree * > &trees, const std::string &path, bool overwrite) const
 
virtual void writePhyloTrees (const std::vector< const PhyloTree * > &trees, std::ostream &out) const=0
 
virtual void writePhyloTrees (const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const
 

Protected Member Functions

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

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 27 of file NexusIoTree.h.

Constructor & Destructor Documentation

◆ NexusIOTree()

bpp::NexusIOTree::NexusIOTree ( )
inline

Build a new Nexus tree parser.

Definition at line 41 of file NexusIoTree.h.

◆ ~NexusIOTree()

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

Definition at line 43 of file NexusIoTree.h.

Member Function Documentation

◆ getDataType()

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

Implements bpp::IOFormat.

Definition at line 51 of file IoTree.h.

◆ getElement() [1/2]

virtual Element bpp::AbstractITree::getElement ( const std::string &  elt) const
inlinevirtualinherited

Reimplemented in bpp::Nhx, and bpp::Newick.

Definition at line 219 of file IoTree.h.

◆ getElement() [2/2]

Element bpp::AbstractIPhyloTree::getElement ( const std::string &  elt) const
inlineinherited

Definition at line 245 of file IoTree.h.

◆ getFormatDescription()

const string NexusIOTree::getFormatDescription ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 36 of file NexusIoTree.cpp.

◆ getFormatName()

const string NexusIOTree::getFormatName ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 32 of file NexusIoTree.cpp.

◆ readPhyloTree() [1/4]

std::unique_ptr<PhyloTree> bpp::AbstractIPhyloTree::readPhyloTree ( const std::string &  path) const
inlineoverridevirtualinherited

Read a tree from a file.

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

Implements bpp::IPhyloTree.

Definition at line 235 of file IoTree.h.

References bpp::AbstractIPhyloTree::readPhyloTree().

◆ readPhyloTree() [2/4]

std::unique_ptr<PhyloTree> bpp::AbstractIPhyloTree::readPhyloTree
inlineoverride

Definition at line 235 of file IoTree.h.

◆ readPhyloTree() [3/4]

unique_ptr< PhyloTree > NexusIOTree::readPhyloTree ( std::istream &  in) const
overridevirtual

Read a tree from a stream.

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

Implements bpp::AbstractIPhyloTree.

Definition at line 140 of file NexusIoTree.cpp.

◆ readPhyloTree() [4/4]

std::unique_ptr<PhyloTree> bpp::AbstractIPhyloTree::readPhyloTree
override

◆ readPhyloTrees() [1/4]

virtual void bpp::AbstractIMultiPhyloTree::readPhyloTrees ( const std::string &  path,
std::vector< std::unique_ptr< PhyloTree >> &  trees 
) const
inlineoverridevirtualinherited

Read trees from a file.

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

Implements bpp::IMultiPhyloTree.

Definition at line 485 of file IoTree.h.

References bpp::AbstractIMultiPhyloTree::readPhyloTrees().

◆ readPhyloTrees() [2/4]

virtual void bpp::AbstractIMultiPhyloTree::readPhyloTrees
inlineoverride

Definition at line 485 of file IoTree.h.

◆ readPhyloTrees() [3/4]

void NexusIOTree::readPhyloTrees ( std::istream &  in,
std::vector< std::unique_ptr< PhyloTree >> &  trees 
) const
overridevirtual

◆ readPhyloTrees() [4/4]

virtual void bpp::AbstractIMultiPhyloTree::readPhyloTrees
override

◆ readTree() [1/2]

std::unique_ptr<Tree> bpp::AbstractITree::readTree ( const std::string &  path) const
inlineoverridevirtualinherited

Read a tree from a file.

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

Implements bpp::ITree.

Definition at line 201 of file IoTree.h.

References bpp::AbstractITree::readTree().

◆ readTree() [2/2]

std::unique_ptr<Tree> bpp::AbstractITree::readTree ( std::istream &  in) const
inlineoverridevirtualinherited

Read a tree from a stream.

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

Implements bpp::ITree.

Definition at line 195 of file IoTree.h.

References bpp::AbstractITree::readTreeTemplate().

Referenced by bpp::AbstractITree::readTree().

◆ readTrees() [1/4]

virtual void bpp::AbstractIMultiTree::readTrees ( const std::string &  path,
std::vector< std::unique_ptr< Tree >> &  trees 
) const
inlineoverridevirtualinherited

Read trees from a file.

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

Implements bpp::IMultiTree.

Definition at line 464 of file IoTree.h.

References bpp::AbstractIMultiTree::readTrees().

◆ readTrees() [2/4]

virtual void bpp::AbstractIMultiTree::readTrees
inlineoverride

Definition at line 464 of file IoTree.h.

◆ readTrees() [3/4]

void NexusIOTree::readTrees ( std::istream &  in,
std::vector< std::unique_ptr< Tree >> &  trees 
) const
overridevirtual

◆ readTrees() [4/4]

virtual void bpp::AbstractIMultiTree::readTrees
override

◆ readTreeTemplate() [1/4]

virtual std::unique_ptr<TreeTemplate<Node> > bpp::AbstractITree::readTreeTemplate ( const std::string &  path) const
inlinevirtualinherited

Definition at line 211 of file IoTree.h.

References bpp::AbstractITree::readTreeTemplate().

◆ readTreeTemplate() [2/4]

virtual std::unique_ptr<TreeTemplate<Node> > bpp::AbstractITree::readTreeTemplate
inline

Definition at line 211 of file IoTree.h.

◆ readTreeTemplate() [3/4]

unique_ptr< TreeTemplate< Node > > NexusIOTree::readTreeTemplate ( std::istream &  in) const
overridevirtual

Implements bpp::AbstractITree.

Definition at line 45 of file NexusIoTree.cpp.

◆ readTreeTemplate() [4/4]

virtual std::unique_ptr<TreeTemplate<Node> > bpp::AbstractITree::readTreeTemplate

◆ write_() [1/6]

void NexusIOTree::write_ ( const PhyloTree tree,
std::ostream &  out 
) const
protected

Definition at line 249 of file NexusIoTree.cpp.

◆ write_() [2/6]

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

◆ write_() [3/6]

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

◆ write_() [4/6]

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

◆ write_() [5/6]

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

Definition at line 240 of file NexusIoTree.cpp.

Referenced by writePhyloTree(), writePhyloTrees(), writeTree(), and writeTrees().

◆ write_() [6/6]

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

Definition at line 259 of file NexusIoTree.cpp.

◆ writePhyloTree() [1/4]

virtual void bpp::AbstractOPhyloTree::writePhyloTree ( const PhyloTree tree,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

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 occurred.

Implements bpp::OPhyloTree.

Definition at line 297 of file IoTree.h.

References bpp::IOException::what(), and bpp::AbstractOPhyloTree::writePhyloTree().

◆ writePhyloTree() [2/4]

virtual void bpp::AbstractOPhyloTree::writePhyloTree
inline

Definition at line 297 of file IoTree.h.

◆ writePhyloTree() [3/4]

void bpp::NexusIOTree::writePhyloTree ( const PhyloTree tree,
std::ostream &  out 
) const
inlineoverridevirtual

Write a tree to a stream.

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

Implements bpp::AbstractOPhyloTree.

Definition at line 84 of file NexusIoTree.h.

References write_().

◆ writePhyloTree() [4/4]

virtual void bpp::AbstractOPhyloTree::writePhyloTree

◆ writePhyloTrees() [1/4]

virtual void bpp::AbstractOMultiPhyloTree::writePhyloTrees ( const std::vector< const PhyloTree * > &  trees,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

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 occurred.

Implements bpp::OMultiPhyloTree.

Definition at line 528 of file IoTree.h.

References bpp::AbstractOMultiPhyloTree::writePhyloTrees().

◆ writePhyloTrees() [2/4]

virtual void bpp::AbstractOMultiPhyloTree::writePhyloTrees
inline

Definition at line 528 of file IoTree.h.

◆ writePhyloTrees() [3/4]

void bpp::NexusIOTree::writePhyloTrees ( const std::vector< const PhyloTree * > &  trees,
std::ostream &  out 
) const
inlineoverridevirtual

Write trees to a stream.

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

Implements bpp::AbstractOMultiPhyloTree.

Definition at line 118 of file NexusIoTree.h.

References write_().

◆ writePhyloTrees() [4/4]

virtual void bpp::AbstractOMultiPhyloTree::writePhyloTrees

◆ writeTree() [1/4]

virtual void bpp::AbstractOTree::writeTree ( const Tree tree,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

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 occurred.

Implements bpp::OTree.

Definition at line 263 of file IoTree.h.

References bpp::IOException::what(), and bpp::AbstractOTree::writeTree().

◆ writeTree() [2/4]

virtual void bpp::AbstractOTree::writeTree
inline

Definition at line 263 of file IoTree.h.

◆ writeTree() [3/4]

void bpp::NexusIOTree::writeTree ( const Tree tree,
std::ostream &  out 
) const
inlineoverridevirtual

Write a tree to a stream.

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

Implements bpp::AbstractOTree.

Definition at line 77 of file NexusIoTree.h.

References write_().

◆ writeTree() [4/4]

virtual void bpp::AbstractOTree::writeTree

◆ writeTrees() [1/4]

virtual void bpp::AbstractOMultiTree::writeTrees ( const std::vector< const Tree * > &  trees,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

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 occurred.

Implements bpp::OMultiTree.

Definition at line 505 of file IoTree.h.

References bpp::AbstractOMultiTree::writeTrees().

◆ writeTrees() [2/4]

virtual void bpp::AbstractOMultiTree::writeTrees
inline

Definition at line 505 of file IoTree.h.

◆ writeTrees() [3/4]

void bpp::NexusIOTree::writeTrees ( const std::vector< const Tree * > &  trees,
std::ostream &  out 
) const
inlineoverridevirtual

Write trees to a stream.

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

Implements bpp::AbstractOMultiTree.

Definition at line 111 of file NexusIoTree.h.

References write_().

◆ writeTrees() [4/4]

virtual void bpp::AbstractOMultiTree::writeTrees

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