bpp-phyl3  3.0.0
bpp::ExtendedNewick Class Reference

The so-called 'ExtendedNewick' parenthetic format for phylogenetic networks, where hybridization nodes are mandatory tagged and appear several times. More...

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

+ Inheritance diagram for bpp::ExtendedNewick:
+ Collaboration diagram for bpp::ExtendedNewick:

Public Member Functions

 ExtendedNewick (bool allowComments=false, bool writeId=false, bool verbose=false)
 Build a new ExtendedNewick reader/writer. More...
 
virtual ~ExtendedNewick ()
 
void writePhyloDAGs (const std::vector< const PhyloDAG * > &dags, std::ostream &out) const override
 Write dags to a stream. More...
 
virtual void writePhyloDAGs (const std::vector< const PhyloDAG * > &dags, std::ostream &out) const=0
 
virtual void writePhyloDAGs (const std::vector< const PhyloDAG * > &dags, const std::string &path, bool overwrite) const
 
std::unique_ptr< PhyloDAG > readPhyloDAG (const std::string &path) const override
 Read a DAG from a file. More...
 
virtual const std::string getDataType () const
 
virtual void writePhyloDAG (const PhyloDAG &dag, const std::string &path, bool overwrite) const
 Write a DAG to a file. More...
 
virtual void readPhyloDAGs (const std::string &path, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override
 Read dags from a file. More...
 
virtual void writePhyloDAGs (const std::vector< const PhyloDAG * > &dags, const std::string &path, bool overwrite) const
 Write dags to a file. More...
 
The IODAGraph interface
const std::string getFormatName () const override
 
const std::string getFormatDescription () const override
 
The ODAGraph interface
void writePhyloDAG (const PhyloDAG &dag, std::ostream &out) const override
 Write a PhyloDAG to a stream. More...
 
virtual void writePhyloDAG (const PhyloDAG &dag, std::ostream &out) const=0
 
virtual void writePhyloDAG (const PhyloDAG &dag, const std::string &path, bool overwrite) const
 
The IMultiDAGraph interface
void readPhyloDAGs (std::istream &in, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override
 Read dags from a stream. More...
 
virtual void readPhyloDAGs (std::istream &in, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override=0
 
virtual void readPhyloDAGs (const std::string &path, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override
 

Protected Member Functions

void write_ (const PhyloDAG &tree, std::ostream &out) const
 
void write_ (const std::vector< const PhyloDAG * > &dags, std::ostream &out) const
 
Element getElement (const std::string &elt) const override
 
std::string nodeToParenthesis (const PhyloDAG &dag, std::shared_ptr< PhyloNode > node, bool writeId=false) const
 Get the ExtendedNewick description of a subdag. More...
 
std::string dagToParenthesis (const PhyloDAG &dag, bool writeId=false) const
 Get the parenthesis description of a tree. More...
 
std::string dagToParenthesis (const PhyloDAG &dag) const
 Get the parenthesis description of a tree. More...
 

Protected Attributes

bool allowComments_
 
bool writeId_
 
bool verbose_
 

The IDAGraph interface

std::unique_ptr< PhyloDAG > readPhyloDAG (std::istream &in) const override
 Read a DAG from a stream. More...
 
std::unique_ptr< PhyloDAG > parenthesisToPhyloDAG (const std::string &description, bool withId, bool verbose=false) const
 
std::unique_ptr< PhyloDAG > readPhyloDAG (std::istream &in) const override=0
 
std::unique_ptr< PhyloDAG > readPhyloDAG (const std::string &path) const override
 
std::shared_ptr< PhyloNodeparenthesisToNode (PhyloDAG &dag, std::shared_ptr< PhyloNode > father, const std::string &description, unsigned int &nodeCounter, unsigned int &branchCounter, map< str::string, shared_ptr< PhyloNode > > &mapEvent, bool withId, bool verbose) const
 

Detailed Description

The so-called 'ExtendedNewick' parenthetic format for phylogenetic networks, where hybridization nodes are mandatory tagged and appear several times.

Branch values are supported:

ex: ((A:0.1, ((B:0.2, (C:0.3, (D:0.2)Y::H1:0.2):0.1):0.2, (((Y::H1:0.1, E:0.4)h, 6)f)X::H2)c)a, ((X::H2, 7)d, 8)b)r;

Those values can be lengths, or probabilities for hybridization branches, depending on the biological meaning of the network.

Reference : Cardona, G, รณ, F, Valiente, G (2008). Extended Newick: it is time for a standard representation of phylogenetic networks. BMC Bioinformatics, 9:532.

Definition at line 36 of file ExtendedNewick.h.

Constructor & Destructor Documentation

◆ ExtendedNewick()

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

Build a new ExtendedNewick reader/writer.

Some extendednewick 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 57 of file ExtendedNewick.h.

◆ ~ExtendedNewick()

virtual bpp::ExtendedNewick::~ExtendedNewick ( )
inlinevirtual

Definition at line 63 of file ExtendedNewick.h.

Member Function Documentation

◆ dagToParenthesis() [1/2]

string ExtendedNewick::dagToParenthesis ( const PhyloDAG &  dag) const
protected

Get the parenthesis description of a tree.

Parameters
dagThe dag to convert.
Returns
A string in the parenthesis format.

Definition at line 417 of file ExtendedNewick.cpp.

References nodeToParenthesis().

◆ dagToParenthesis() [2/2]

string ExtendedNewick::dagToParenthesis ( const PhyloDAG &  dag,
bool  writeId = false 
) const
protected

Get the parenthesis description of a tree.

Parameters
dagThe dag to convert.
writeIdTells if node ids must be printed. Leaves id will be added to the leave names, separated by a '_' character.
Returns
A string in the parenthesis format.

Definition at line 374 of file ExtendedNewick.cpp.

References nodeToParenthesis().

Referenced by write_().

◆ getDataType()

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

Implements bpp::IOFormat.

Definition at line 48 of file IoDAG.h.

◆ getElement()

IODAG::Element ExtendedNewick::getElement ( const std::string &  elt) const
overrideprotectedvirtual

◆ getFormatDescription()

const string ExtendedNewick::getFormatDescription ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 30 of file ExtendedNewick.cpp.

◆ getFormatName()

const string ExtendedNewick::getFormatName ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 26 of file ExtendedNewick.cpp.

◆ nodeToParenthesis()

string ExtendedNewick::nodeToParenthesis ( const PhyloDAG &  dag,
std::shared_ptr< PhyloNode node,
bool  writeId = false 
) const
protected

Get the ExtendedNewick description of a subdag.

Parameters
dagThe dag to convert.
nodeThe top of the subdag to convert.
writeIdTells if node ids must be printed. Leaves id will be added to the leave names, separated by a '_' character.
Returns
A string in the parenthesis format.

Definition at line 334 of file ExtendedNewick.cpp.

Referenced by dagToParenthesis().

◆ parenthesisToNode()

shared_ptr< PhyloNode > ExtendedNewick::parenthesisToNode ( PhyloDAG &  dag,
std::shared_ptr< PhyloNode father,
const std::string &  description,
unsigned int &  nodeCounter,
unsigned int &  branchCounter,
map< str::string, shared_ptr< PhyloNode > > &  mapEvent,
bool  withId,
bool  verbose 
) const
private

◆ parenthesisToPhyloDAG()

unique_ptr< PhyloDAG > ExtendedNewick::parenthesisToPhyloDAG ( const std::string &  description,
bool  withId,
bool  verbose = false 
) const

Definition at line 281 of file ExtendedNewick.cpp.

References bpp::ApplicationTools::message, and parenthesisToNode().

◆ readPhyloDAG() [1/4]

std::unique_ptr<PhyloDAG> bpp::AbstractIPhyloDAG::readPhyloDAG
inlineoverride

Definition at line 130 of file IoDAG.h.

◆ readPhyloDAG() [2/4]

std::unique_ptr<PhyloDAG> bpp::AbstractIPhyloDAG::readPhyloDAG ( const std::string &  path) const
inlineoverridevirtualinherited

Read a DAG from a file.

Parameters
pathThe file path.
Returns
a new PhyloDAG object.

Implements bpp::IPhyloDAG.

Definition at line 130 of file IoDAG.h.

References bpp::AbstractIPhyloDAG::readPhyloDAG().

◆ readPhyloDAG() [3/4]

unique_ptr< PhyloDAG > ExtendedNewick::readPhyloDAG ( std::istream &  in) const
overridevirtual

Read a DAG from a stream.

Parameters
inThe input stream.
Returns
A new PhyloDAG object.

Implements bpp::AbstractIPhyloDAG.

Definition at line 40 of file ExtendedNewick.cpp.

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

◆ readPhyloDAG() [4/4]

std::unique_ptr<PhyloDAG> bpp::AbstractIPhyloDAG::readPhyloDAG
override

◆ readPhyloDAGs() [1/4]

virtual void bpp::AbstractIMultiPhyloDAG::readPhyloDAGs
inlineoverride

Definition at line 260 of file IoDAG.h.

◆ readPhyloDAGs() [2/4]

virtual void bpp::AbstractIMultiPhyloDAG::readPhyloDAGs ( const std::string &  path,
std::vector< std::unique_ptr< PhyloDAG >> &  dags 
) const
inlineoverridevirtualinherited

Read dags from a file.

Parameters
pathThe file path.
dagsThe output dags vector.
Exceptions
ExceptionIf an error occurred.

Implements bpp::IMultiPhyloDAG.

Definition at line 260 of file IoDAG.h.

References bpp::AbstractIMultiPhyloDAG::readPhyloDAGs().

◆ readPhyloDAGs() [3/4]

void ExtendedNewick::readPhyloDAGs ( std::istream &  in,
std::vector< std::unique_ptr< PhyloDAG >> &  dags 
) const
overridevirtual

Read dags from a stream.

Parameters
inThe input stream.
dagsThe output dags container.
Exceptions
ExceptionIf an error occurred.

Implements bpp::AbstractIMultiPhyloDAG.

Definition at line 73 of file ExtendedNewick.cpp.

References bpp::TextTools::removeSubstrings().

◆ readPhyloDAGs() [4/4]

virtual void bpp::AbstractIMultiPhyloDAG::readPhyloDAGs
override

◆ write_() [1/2]

void ExtendedNewick::write_ ( const PhyloDAG &  tree,
std::ostream &  out 
) const
protected

Definition at line 307 of file ExtendedNewick.cpp.

References dagToParenthesis(), and writeId_.

Referenced by writePhyloDAG(), and writePhyloDAGs().

◆ write_() [2/2]

void ExtendedNewick::write_ ( const std::vector< const PhyloDAG * > &  dags,
std::ostream &  out 
) const
protected

Definition at line 320 of file ExtendedNewick.cpp.

References dagToParenthesis(), and writeId_.

◆ writePhyloDAG() [1/4]

virtual void bpp::AbstractOPhyloDAG::writePhyloDAG
inline

Definition at line 158 of file IoDAG.h.

◆ writePhyloDAG() [2/4]

virtual void bpp::AbstractOPhyloDAG::writePhyloDAG ( const PhyloDAG &  dag,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

Write a DAG to a file.

Parameters
daga PhyloDAG object.
pathThe file path.
overwriteTell if existing file must be overwritten. Otherwise append to the file.
Exceptions
ExceptionIf an error occurred.

Implements bpp::OPhyloDAG.

Definition at line 158 of file IoDAG.h.

References bpp::IOException::what(), and bpp::AbstractOPhyloDAG::writePhyloDAG().

◆ writePhyloDAG() [3/4]

void bpp::ExtendedNewick::writePhyloDAG ( const PhyloDAG &  dag,
std::ostream &  out 
) const
inlineoverridevirtual

Write a PhyloDAG to a stream.

Parameters
dagA PhyloDAG object.
outThe output stream.
Exceptions
ExceptionIf an error occurred.

Implements bpp::AbstractOPhyloDAG.

Definition at line 113 of file ExtendedNewick.h.

References write_().

◆ writePhyloDAG() [4/4]

virtual void bpp::AbstractOPhyloDAG::writePhyloDAG

◆ writePhyloDAGs() [1/4]

virtual void bpp::AbstractOMultiPhyloDAG::writePhyloDAGs
inline

Definition at line 281 of file IoDAG.h.

◆ writePhyloDAGs() [2/4]

virtual void bpp::AbstractOMultiPhyloDAG::writePhyloDAGs ( const std::vector< const PhyloDAG * > &  dags,
const std::string &  path,
bool  overwrite 
) const
inlinevirtualinherited

Write dags to a file.

Parameters
dagsA vector of dag objects.
pathThe file path.
overwriteTell if existing file must be overwritten. Otherwise append to the file.

Implements bpp::OMultiPhyloDAG.

Definition at line 281 of file IoDAG.h.

References bpp::AbstractOMultiPhyloDAG::writePhyloDAGs().

◆ writePhyloDAGs() [3/4]

void bpp::ExtendedNewick::writePhyloDAGs ( const std::vector< const PhyloDAG * > &  dags,
std::ostream &  out 
) const
inlineoverridevirtual

Write dags to a stream.

Parameters
dagsA vector of dag objects.
outThe output stream.
Exceptions
ExceptionIf an error occurred.

Implements bpp::AbstractOMultiPhyloDAG.

Definition at line 135 of file ExtendedNewick.h.

References write_().

◆ writePhyloDAGs() [4/4]

virtual void bpp::AbstractOMultiPhyloDAG::writePhyloDAGs

Member Data Documentation

◆ allowComments_

bool bpp::ExtendedNewick::allowComments_
protected

Definition at line 43 of file ExtendedNewick.h.

◆ verbose_

bool bpp::ExtendedNewick::verbose_
protected

Definition at line 45 of file ExtendedNewick.h.

◆ writeId_

bool bpp::ExtendedNewick::writeId_
protected

Definition at line 44 of file ExtendedNewick.h.

Referenced by write_().


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