|
bpp-phyl3 3.0.0
|
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, 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 const std::string | getDataType () const |
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 |
| Write a tree to a stream. More... | |
| virtual void | writeTree (const Tree &tree, const std::string &path, bool overwrite) const |
| Write a tree to a file. More... | |
| virtual void | writePhyloTree (const PhyloTree &tree, std::ostream &out) const=0 |
| Write a tree to a stream. More... | |
| virtual void | writePhyloTree (const PhyloTree &tree, const std::string &path, bool overwrite) const |
| Write a tree to a file. More... | |
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 |
| Read trees from a stream. 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 | readPhyloTrees (std::istream &in, std::vector< std::unique_ptr< PhyloTree > > &trees) const override=0 |
| Read trees from a stream. More... | |
| virtual void | readPhyloTrees (const std::string &path, std::vector< std::unique_ptr< PhyloTree > > &trees) const override |
| Read trees from a file. More... | |
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 |
| Write trees to a stream. More... | |
| virtual void | writeTrees (const std::vector< const Tree * > &trees, const std::string &path, bool overwrite) const |
| Write trees to a file. More... | |
| virtual void | writePhyloTrees (const std::vector< const PhyloTree * > &trees, std::ostream &out) const=0 |
| Write trees to a stream. More... | |
| virtual void | writePhyloTrees (const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const |
| Write trees to a file. More... | |
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 |
| Read a tree from a stream. More... | |
| std::unique_ptr< PhyloTree > | readPhyloTree (const std::string &path) const override |
| Read a tree from a file. More... | |
| 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 bpp::IOTree::Element::annotation, bpp::IOTree::Element::content, bpp::TextTools::isEmpty(), bpp::IOTree::Element::isLeaf, bpp::IOTree::Element::length, and bpp::TextTools::removeSurroundingWhiteSpaces().
Referenced by parenthesisToNode().
|
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(), bpp::AssociationTreeGraphImplObserver< class, class, class >::hasFather(), and nodeToParenthesis().
|
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(), bpp::AssociationTreeGraphImplObserver< class, class, class >::isLeaf(), and nodeToParenthesis().
Referenced by nodeToParenthesis(), and treeToParenthesis().
|
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(), getElement(), bpp::StringTokenizer::getToken(), bpp::NestedStringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::IOTree::Element::isLeaf, bpp::IOTree::Element::length, bpp::NestedStringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), parenthesisToNode(), bpp::TextTools::removeSurroundingWhiteSpaces(), bpp::AssociationTreeGraphImplObserver< class, class, class >::setEdgeIndex(), bpp::AssociationTreeGraphImplObserver< class, class, class >::setNodeIndex(), bpp::TextTools::toDouble(), and bpp::TextTools::toInt().
Referenced by parenthesisToNode(), and parenthesisToPhyloTree().
| 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, and parenthesisToNode().
Referenced by bpp::DistanceEstimation::computeMatrix(), readPhyloTree(), and readPhyloTrees().
|
inlineoverridevirtual |
Read a tree from a file.
| path | The file path. |
| Exception | If an error occurred. |
Reimplemented from bpp::AbstractIPhyloTree.
|
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 allowComments_, bootstrapPropertyName_, bpp::TextTools::isEmpty(), parenthesisToPhyloTree(), bpp::TextTools::removeSubstrings(), useBootstrap_, and verbose_.
Referenced by bpp::NexusIOTree::readPhyloTrees().
|
overridevirtual |
Read a tree from a stream.
| in | The input stream. |
| Exception | If an error occurred. |
Implements bpp::AbstractIPhyloTree.
|
inlineoverridevirtual |
Read trees from a file.
| path | The file path. |
| trees | The output trees container. |
| Exception | If an error occurred. |
Reimplemented from bpp::AbstractIMultiPhyloTree.
|
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 allowComments_, bootstrapPropertyName_, parenthesisToPhyloTree(), bpp::TextTools::removeSubstrings(), useBootstrap_, and verbose_.
|
overridevirtual |
Read trees from a stream.
| in | The input stream. |
| trees | The output trees container. |
| Exception | If an error occurred. |
Implements bpp::AbstractIMultiPhyloTree.
|
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().
|
inlineoverridevirtual |
Read trees from a file.
| path | The file path. |
| trees | The output trees container. |
| Exception | If an error occurred. |
Reimplemented from bpp::AbstractIMultiTree.
|
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 allowComments_, bootstrapPropertyName_, bpp::TreeTemplateTools::parenthesisToTree(), bpp::TextTools::removeSubstrings(), useBootstrap_, and verbose_.
|
overridevirtual |
Read trees from a stream.
| in | The input stream. |
| trees | The output trees container. |
| Exception | If an error occurred. |
Implements bpp::AbstractIMultiTree.
|
inlinevirtual |
Reimplemented from bpp::AbstractITree.
|
overridevirtual |
Implements bpp::AbstractITree.
Definition at line 44 of file Newick.cpp.
References allowComments_, bootstrapPropertyName_, bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::parenthesisToTree(), bpp::TextTools::removeSubstrings(), useBootstrap_, and verbose_.
|
virtual |
Implements bpp::AbstractITree.
|
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(), bpp::AssociationTreeGraphImplObserver< class, class, class >::isRooted(), and nodeToParenthesis().
|
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(), bpp::AssociationTreeGraphImplObserver< class, class, class >::isRooted(), and nodeToParenthesis().
Referenced by write_().
|
protected |
Definition at line 376 of file Newick.cpp.
References bootstrapPropertyName_, treeToParenthesis(), useBootstrap_, and writeId_.
|
protected |
Definition at line 461 of file Newick.cpp.
References bootstrapPropertyName_, treeToParenthesis(), useBootstrap_, and writeId_.
|
protected |
Definition at line 416 of file Newick.cpp.
References bootstrapPropertyName_, bpp::TreeTools::treeToParenthesis(), useBootstrap_, and writeId_.
|
protected |
Definition at line 439 of file Newick.cpp.
References bootstrapPropertyName_, bpp::TreeTemplateTools::treeToParenthesis(), useBootstrap_, and writeId_.
|
protected |
Definition at line 359 of file Newick.cpp.
References bootstrapPropertyName_, bpp::TreeTools::treeToParenthesis(), useBootstrap_, and writeId_.
Referenced by writePhyloTree(), writePhyloTrees(), writeTree(), and writeTrees().
|
protected |
Definition at line 396 of file Newick.cpp.
References bootstrapPropertyName_, bpp::TreeTemplateTools::treeToParenthesis(), useBootstrap_, and writeId_.
|
inlinevirtual |
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. |
Reimplemented from bpp::AbstractOPhyloTree.
|
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 |
Write a tree to a stream.
| tree | A tree object. |
| out | The output stream. |
| Exception | If an error occurred. |
Implements bpp::AbstractOPhyloTree.
|
inlinevirtual |
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. |
Reimplemented from bpp::AbstractOMultiPhyloTree.
|
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 |
Write trees to a stream.
| trees | A vector of tree objects. |
| out | The output stream. |
| Exception | If an error occurred. |
Implements bpp::AbstractOMultiPhyloTree.
|
inlinevirtual |
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. |
Reimplemented from bpp::AbstractOTree.
|
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 |
Write a tree to a stream.
| tree | A tree object. |
| out | The output stream. |
| Exception | If an error occurred. |
Implements bpp::AbstractOTree.
|
inlinevirtual |
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. |
Reimplemented from bpp::AbstractOMultiTree.
|
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 |
Write trees to a stream.
| trees | A vector of tree objects. |
| out | The output stream. |
| Exception | If an error occurred. |
Implements bpp::AbstractOMultiTree.
|
protected |
Definition at line 60 of file Newick.h.
Referenced by readPhyloTree(), readPhyloTrees(), readTrees(), and readTreeTemplate().
|
protected |
Definition at line 63 of file Newick.h.
Referenced by disableExtendedBootstrapProperty(), enableExtendedBootstrapProperty(), readPhyloTree(), readPhyloTrees(), readTrees(), readTreeTemplate(), and write_().
|
protected |
Definition at line 62 of file Newick.h.
Referenced by disableExtendedBootstrapProperty(), enableExtendedBootstrapProperty(), readPhyloTree(), readPhyloTrees(), readTrees(), readTreeTemplate(), and write_().
|
protected |
Definition at line 64 of file Newick.h.
Referenced by readPhyloTree(), readPhyloTrees(), readTrees(), and readTreeTemplate().
|
protected |