bpp-phyl3
3.0.0
|
The so-called 'newick' parenthetic format. More...
#include <Bpp/Phyl/Io/Newick.h>
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 () |
std::unique_ptr< Tree > | readTree (std::istream &in) const override |
Read a tree from a stream. More... | |
std::unique_ptr< Tree > | readTree (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 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< PhyloTree > | readPhyloTree (const std::string &path) const override |
Read a tree from a file. More... | |
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 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 |
IOTree::Element | getElement (const std::string &elt) const override |
std::string | nodeToParenthesis (const PhyloTree &tree, std::shared_ptr< PhyloNode > node, bool writeId=false) const |
Get the Newick description of a subtree. More... | |
std::string | nodeToParenthesis (const PhyloTree &tree, std::shared_ptr< PhyloNode > node, bool bootstrap, const std::string &propertyName) const |
std::string | treeToParenthesis (const PhyloTree &tree, bool writeId=false) const |
Get the parenthesis description of a tree. More... | |
std::string | treeToParenthesis (const PhyloTree &tree, bool bootstrap, const std::string &propertyName) const |
Get the parenthesis description of a tree. More... | |
Protected Attributes | |
bool | allowComments_ |
bool | writeId_ |
bool | useBootstrap_ |
std::string | bootstrapPropertyName_ |
bool | verbose_ |
The ITree interface | |
std::unique_ptr< TreeTemplate< Node > > | readTreeTemplate (std::istream &in) const override |
std::unique_ptr< PhyloTree > | readPhyloTree (std::istream &in) const override |
Read a tree from a stream. More... | |
std::unique_ptr< PhyloTree > | parenthesisToPhyloTree (const std::string &description, bool bootstrap=false, const std::string &propertyName="", bool withId=false, bool verbose=false) const |
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< PhyloTree > | readPhyloTree (std::istream &in) const override=0 |
std::unique_ptr< PhyloTree > | readPhyloTree (const std::string &path) const override |
std::shared_ptr< PhyloNode > | parenthesisToNode (PhyloTree &tree, std::shared_ptr< PhyloNode > father, const std::string &description, unsigned int &nodeCounter, bool bootstrap, const std::string &propertyName, bool withId, bool verbose) const |
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:
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.
|
inline |
Build a new Newick reader/writer.
Some newick format allow comments between hooks ('[' ']').
allowComments | Tell if comments between [] are allowed in file. |
writeId | If true, nodes ids will be written in place of bootstrap values. |
verbose | If some info should be displayed, such as progress bar etc. |
|
inline |
Definition at line 92 of file Newick.h.
References bootstrapPropertyName_, and useBootstrap_.
|
inline |
Definition at line 86 of file Newick.h.
References bootstrapPropertyName_, and useBootstrap_.
Referenced by bpp::PhylogeneticsApplicationTools::writePhyloTrees().
|
inlinevirtualinherited |
Implements bpp::IOFormat.
|
overrideprotectedvirtual |
Reimplemented from bpp::AbstractITree.
Definition at line 170 of file Newick.cpp.
References element, bpp::TextTools::isEmpty(), and bpp::TextTools::removeSurroundingWhiteSpaces().
|
overridevirtual |
Implements bpp::IOFormat.
Definition at line 34 of file Newick.cpp.
|
overridevirtual |
Implements bpp::IOFormat.
Definition at line 30 of file Newick.cpp.
|
protected |
Definition at line 528 of file Newick.cpp.
References bpp::AssociationTreeGraphImplObserver< class, class, class >::getEdgeToFather(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getNumberOfSons(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getSons(), and bpp::AssociationTreeGraphImplObserver< class, class, class >::hasFather().
|
protected |
Get the Newick description of a subtree.
tree | The tree to convert. |
node | The top of the subtree to convert. |
writeId | Tells if node ids must be printed. This will overwrite bootstrap values if there are ones. Leaves id will be added to the leave names, separated by a '_' character. |
Definition at line 483 of file Newick.cpp.
References bpp::AssociationTreeGraphImplObserver< class, class, class >::getEdgeToFather(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getNodeIndex(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getNumberOfSons(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getSons(), bpp::AssociationTreeGraphImplObserver< class, class, class >::hasFather(), and bpp::AssociationTreeGraphImplObserver< class, class, class >::isLeaf().
|
private |
Definition at line 233 of file Newick.cpp.
References bpp::IOTree::Element::annotation, bpp::IOTree::Element::content, bpp::AssociationTreeGraphImplObserver< class, class, class >::createNode(), bpp::ApplicationTools::displayUnlimitedGauge(), bpp::StringTokenizer::getToken(), bpp::NestedStringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::IOTree::Element::isLeaf, bpp::IOTree::Element::length, bpp::NestedStringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), bpp::TextTools::removeSurroundingWhiteSpaces(), bpp::AssociationTreeGraphImplObserver< class, class, class >::setEdgeIndex(), bpp::AssociationTreeGraphImplObserver< class, class, class >::setNodeIndex(), bpp::TextTools::toDouble(), and bpp::TextTools::toInt().
unique_ptr< PhyloTree > Newick::parenthesisToPhyloTree | ( | const std::string & | description, |
bool | bootstrap = false , |
||
const std::string & | propertyName = "" , |
||
bool | withId = false , |
||
bool | verbose = false |
||
) | const |
Definition at line 336 of file Newick.cpp.
References bpp::ApplicationTools::message.
Referenced by bpp::DistanceEstimation::computeMatrix().
|
inlineoverridevirtualinherited |
Read a tree from a file.
path | The file path. |
Exception | If an error occurred. |
Implements bpp::IPhyloTree.
Definition at line 235 of file IoTree.h.
References bpp::AbstractIPhyloTree::readPhyloTree().
|
inlineoverride |
|
overridevirtual |
Read a tree from a stream.
in | The input stream. |
Exception | If an error occurred. |
Implements bpp::AbstractIPhyloTree.
Definition at line 76 of file Newick.cpp.
References bpp::TextTools::isEmpty(), and bpp::TextTools::removeSubstrings().
Referenced by bpp::NexusIOTree::readPhyloTrees().
|
override |
|
inlineoverridevirtualinherited |
Read trees from a file.
path | The file path. |
trees | The output trees container. |
Exception | If an error occurred. |
Implements bpp::IMultiPhyloTree.
Definition at line 485 of file IoTree.h.
References bpp::AbstractIMultiPhyloTree::readPhyloTrees().
|
inlineoverride |
|
overridevirtual |
Read trees from a stream.
in | The input stream. |
trees | The output trees container. |
Exception | If an error occurred. |
Implements bpp::AbstractIMultiPhyloTree.
Definition at line 139 of file Newick.cpp.
References bpp::TextTools::removeSubstrings().
|
override |
|
inlineoverridevirtualinherited |
Read a tree from a file.
path | The file path. |
Exception | If an error occurred. |
Implements bpp::ITree.
Definition at line 201 of file IoTree.h.
References bpp::AbstractITree::readTree().
|
inlineoverridevirtualinherited |
Read a tree from a stream.
in | The input stream. |
Exception | If an error occurred. |
Implements bpp::ITree.
Definition at line 195 of file IoTree.h.
References bpp::AbstractITree::readTreeTemplate().
Referenced by bpp::AbstractITree::readTree().
|
inlineoverridevirtualinherited |
Read trees from a file.
path | The file path. |
trees | The output trees container. |
Exception | If an error occurred. |
Implements bpp::IMultiTree.
Definition at line 464 of file IoTree.h.
References bpp::AbstractIMultiTree::readTrees().
|
inlineoverride |
|
overridevirtual |
Read trees from a stream.
in | The input stream. |
trees | The output trees container. |
Exception | If an error occurred. |
Implements bpp::AbstractIMultiTree.
Definition at line 108 of file Newick.cpp.
References bpp::TreeTemplateTools::parenthesisToTree(), and bpp::TextTools::removeSubstrings().
|
override |
|
inlinevirtualinherited |
Definition at line 211 of file IoTree.h.
References bpp::AbstractITree::readTreeTemplate().
|
inline |
|
overridevirtual |
Implements bpp::AbstractITree.
Definition at line 44 of file Newick.cpp.
References bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::parenthesisToTree(), and bpp::TextTools::removeSubstrings().
virtual std::unique_ptr<TreeTemplate<Node> > bpp::AbstractITree::readTreeTemplate |
|
protected |
Get the parenthesis description of a tree.
tree | The tree to convert. |
bootstrap | Tell is bootstrap values must be written. If so, the content of the property with name "bootstrap" will be written as bootstrap value. The property should be a Number<double> object. Otherwise, the content of the property with name 'propertyName' will be written. In this later case, the property should be a String object. |
propertyName | The name of the property to use. Only used if bootstrap = false. |
Definition at line 619 of file Newick.cpp.
References bpp::AssociationTreeGraphImplObserver< class, class, class >::getEdgeToFather(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getRoot(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getSons(), bpp::AssociationTreeGraphImplObserver< class, class, class >::hasFather(), and bpp::AssociationTreeGraphImplObserver< class, class, class >::isRooted().
|
protected |
Get the parenthesis description of a tree.
tree | The tree to convert. |
writeId | Tells if node ids must be printed. This will overwrite bootstrap values if there are ones. Leaves id will be added to the leave names, separated by a '_' character. |
Definition at line 576 of file Newick.cpp.
References bpp::AssociationTreeGraphImplObserver< class, class, class >::getEdgeToFather(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getRoot(), bpp::AssociationTreeGraphImplObserver< class, class, class >::getSons(), bpp::AssociationTreeGraphImplObserver< class, class, class >::hasFather(), and bpp::AssociationTreeGraphImplObserver< class, class, class >::isRooted().
|
protected |
Definition at line 376 of file Newick.cpp.
|
protected |
Definition at line 461 of file Newick.cpp.
|
protected |
Definition at line 416 of file Newick.cpp.
References bpp::TreeTools::treeToParenthesis().
|
protected |
Definition at line 439 of file Newick.cpp.
References bpp::TreeTemplateTools::treeToParenthesis().
|
protected |
Definition at line 359 of file Newick.cpp.
References bpp::TreeTools::treeToParenthesis().
Referenced by writePhyloTree(), writePhyloTrees(), writeTree(), and writeTrees().
|
protected |
Definition at line 396 of file Newick.cpp.
References bpp::TreeTemplateTools::treeToParenthesis().
|
inlinevirtualinherited |
Write a tree to a file.
tree | A tree object. |
path | The file path. |
overwrite | Tell if existing file must be overwritten. Otherwise append to the file. |
Exception | If an error occurred. |
Implements bpp::OPhyloTree.
Definition at line 297 of file IoTree.h.
References bpp::IOException::what(), and bpp::AbstractOPhyloTree::writePhyloTree().
|
inline |
|
inlineoverridevirtual |
Write a tree to a stream.
tree | A tree object. |
out | The output stream. |
Exception | If an error occurred. |
Implements bpp::AbstractOPhyloTree.
Definition at line 157 of file Newick.h.
References write_().
Referenced by bpp::NexusIOTree::write_().
virtual void bpp::AbstractOPhyloTree::writePhyloTree |
|
inlinevirtualinherited |
Write trees to a file.
trees | A vector of tree objects. |
path | The file path. |
overwrite | Tell if existing file must be overwritten. Otherwise append to the file. |
Exception | If an error occurred. |
Implements bpp::OMultiPhyloTree.
Definition at line 528 of file IoTree.h.
References bpp::AbstractOMultiPhyloTree::writePhyloTrees().
|
inline |
|
inlineoverridevirtual |
Write trees to a stream.
trees | A vector of tree objects. |
out | The output stream. |
Exception | If an error occurred. |
Implements bpp::AbstractOMultiPhyloTree.
Definition at line 198 of file Newick.h.
References write_().
virtual void bpp::AbstractOMultiPhyloTree::writePhyloTrees |
|
inlinevirtualinherited |
Write a tree to a file.
tree | A tree object. |
path | The file path. |
overwrite | Tell if existing file must be overwritten. Otherwise append to the file. |
Exception | If an error occurred. |
Implements bpp::OTree.
Definition at line 263 of file IoTree.h.
References bpp::IOException::what(), and bpp::AbstractOTree::writeTree().
|
inlineoverridevirtual |
Write a tree to a stream.
tree | A tree object. |
out | The output stream. |
Exception | If an error occurred. |
Implements bpp::AbstractOTree.
Definition at line 150 of file Newick.h.
References write_().
virtual void bpp::AbstractOTree::writeTree |
|
inlinevirtualinherited |
Write trees to a file.
trees | A vector of tree objects. |
path | The file path. |
overwrite | Tell if existing file must be overwritten. Otherwise append to the file. |
Exception | If an error occurred. |
Implements bpp::OMultiTree.
Definition at line 505 of file IoTree.h.
References bpp::AbstractOMultiTree::writeTrees().
|
inlineoverridevirtual |
Write trees to a stream.
trees | A vector of tree objects. |
out | The output stream. |
Exception | If an error occurred. |
Implements bpp::AbstractOMultiTree.
Definition at line 191 of file Newick.h.
References write_().
virtual void bpp::AbstractOMultiTree::writeTrees |
|
protected |
Definition at line 63 of file Newick.h.
Referenced by disableExtendedBootstrapProperty(), and enableExtendedBootstrapProperty().
|
protected |
Definition at line 62 of file Newick.h.
Referenced by disableExtendedBootstrapProperty(), and enableExtendedBootstrapProperty().