bpp-phyl
2.2.0
|
The so-called 'Nhx - New Hampshire eXtended' parenthetic format. More...
#include <Bpp/Phyl/Io/Nhx.h>
Classes | |
struct | Element |
struct | Property |
Public Member Functions | |
Nhx (bool useTagsAsPptNames=true) | |
Build a new Nhx reader/writer. More... | |
virtual | ~Nhx () |
TreeTemplate< Node > * | parenthesisToTree (const std::string &description) const throw (Exception) |
std::string | treeToParenthesis (const TreeTemplate< Node > &tree) const |
void | registerProperty (const Property &property) |
void | changeTagsToNames (Node &node) const |
Convert property names from tag to names. More... | |
void | changeNamesToTags (Node &node) const |
Convert property names from names to tags. More... | |
void | useTagsAsPropertyNames (bool yn) |
bool | useTagsAsPropertyNames () const |
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) |
Element | getElement (const std::string &elt) const throw (IOException) |
Node * | parenthesisToNode (const std::string &description) const |
std::string | propertiesToParenthesis (const Node &node) const |
std::string | nodeToParenthesis (const Node &node) const |
bool | setNodeProperties (Node &node, const std::string properties) const |
Static Protected Member Functions | |
static std::string | propertyToString_ (const Clonable *pptObject, short type) throw (Exception) |
static Clonable * | stringToProperty_ (const std::string &pptDesc, short type) throw (Exception) |
Private Attributes | |
std::set< Property > | supportedProperties_ |
bool | useTagsAsPropertyNames_ |
bool | hasIds_ |
The so-called 'Nhx - New Hampshire eXtended' parenthetic format.
See http://www.phylosoft.org/Nhx/ for details.
Branch lengths and node annotations are supported:
ex: ((A:0.1[&&NHX:S=human], B:0.15[&&NHX:S=chimp]):0.2[&&NHX:B=90:D=N:S=primates], C:0.27[&&NHX:S=mouse]);
Where e.g. "S=human" means that the sequence A comes from species "human", "B=90" stands for a support value, and "D=N" means that there was no duplication at the node. Other tags are allowed, see http://www.phylosoft.org/NHX/. By default, comments between "[" and "]" are removed, unless the opening bracket is followed by "&&NHX".
Code example:
All node annotations are stored as node properties, with type bppString for all properties except for support values, where a Number is used.
Nhx::Nhx | ( | bool | useTagsAsPptNames = true | ) |
Build a new Nhx reader/writer.
Comments between hooks ('[' ']') are ignored.
useTagsAsPptNames | Tells if the NHX tag should be used as a property name in the parsed tree. |
Definition at line 60 of file Nhx.cpp.
References bpp::TreeTools::BOOTSTRAP, and registerProperty().
void Nhx::changeNamesToTags | ( | Node & | node | ) | const |
Convert property names from names to tags.
If a tree has been parsed using useTagsAsPropertyNames=false, this method allows to convert the tree as is it was parsed using the option set to true.
node | The root node of the subtree to convert. |
Definition at line 553 of file Nhx.cpp.
References bpp::Node::deleteBranchProperty(), bpp::Node::deleteNodeProperty(), bpp::Node::getBranchProperty(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasBranchProperty(), bpp::Node::hasNodeProperty(), bpp::Node::setBranchProperty(), bpp::Node::setNodeProperty(), and supportedProperties_.
void Nhx::changeTagsToNames | ( | Node & | node | ) | const |
Convert property names from tag to names.
If a tree has been parsed using useTagsAsPropertyNames=true, this method allows to convert the tree as is it was parsed using the option set to false.
node | The root node of the subtree to convert. |
Definition at line 533 of file Nhx.cpp.
References bpp::Node::deleteBranchProperty(), bpp::Node::deleteNodeProperty(), bpp::Node::getBranchProperty(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasBranchProperty(), bpp::Node::hasNodeProperty(), bpp::Node::setBranchProperty(), bpp::Node::setNodeProperty(), and supportedProperties_.
|
inlinevirtualinherited |
|
protected |
Definition at line 206 of file Nhx.cpp.
References bpp::Nhx::Element::annotation, bpp::Nhx::Element::content, bpp::Nhx::Element::isLeaf, and bpp::Nhx::Element::length.
Referenced by parenthesisToNode().
|
protected |
Definition at line 433 of file Nhx.cpp.
References bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::hasDistanceToFather(), bpp::Node::isLeaf(), and propertiesToParenthesis().
Referenced by treeToParenthesis().
|
protected |
Definition at line 287 of file Nhx.cpp.
References bpp::Node::addSon(), bpp::Nhx::Element::annotation, bpp::Nhx::Element::content, getElement(), hasIds_, bpp::Nhx::Element::isLeaf, bpp::Nhx::Element::length, bpp::Node::setDistanceToFather(), bpp::Node::setName(), and setNodeProperties().
TreeTemplate< Node > * Nhx::parenthesisToTree | ( | const std::string & | description | ) | const |
throw | ( | Exception | |||
) |
Definition at line 334 of file Nhx.cpp.
References bpp::TreeTemplate< N >::resetNodesId(), and bpp::TreeTemplate< N >::setRootNode().
|
protected |
Definition at line 404 of file Nhx.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getId(), bpp::Node::getNodeProperty(), bpp::Node::hasBranchProperty(), bpp::Node::hasNodeProperty(), propertyToString_(), supportedProperties_, and useTagsAsPropertyNames_.
Referenced by nodeToParenthesis(), and treeToParenthesis().
|
staticprotected |
Definition at line 353 of file Nhx.cpp.
Referenced by propertiesToParenthesis().
|
inlinevirtual |
Read a tree from a file.
path | The file path. |
Exception | If an error occured. |
Reimplemented from bpp::AbstractITree.
Definition at line 170 of file Nhx.h.
References bpp::AbstractITree::read().
|
virtual |
Read a tree from a stream.
in | The input stream. |
Exception | If an error occured. |
Implements bpp::AbstractITree.
|
inlinevirtual |
Read trees from a file.
path | The file path. |
trees | The output trees container. |
Exception | If an error occured. |
Reimplemented from bpp::AbstractIMultiTree.
Definition at line 199 of file Nhx.h.
References bpp::AbstractIMultiTree::read().
|
virtual |
Read trees from a stream.
in | The input stream. |
trees | The output trees container. |
Exception | If an error occured. |
Implements bpp::AbstractIMultiTree.
|
inline |
|
protected |
Definition at line 490 of file Nhx.cpp.
References bpp::Node::setBranchProperty(), bpp::Node::setId(), bpp::Node::setNodeProperty(), stringToProperty_(), supportedProperties_, and useTagsAsPropertyNames_.
Referenced by parenthesisToNode().
|
staticprotected |
Definition at line 386 of file Nhx.cpp.
Referenced by setNodeProperties().
string Nhx::treeToParenthesis | ( | const TreeTemplate< Node > & | tree | ) | const |
Definition at line 457 of file Nhx.cpp.
References bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSon(), bpp::Node::hasDistanceToFather(), bpp::Node::isLeaf(), nodeToParenthesis(), and propertiesToParenthesis().
|
inline |
Definition at line 251 of file Nhx.h.
References useTagsAsPropertyNames_.
|
inline |
Definition at line 252 of file Nhx.h.
References useTagsAsPropertyNames_.
|
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 occured. |
Reimplemented from bpp::AbstractOTree.
Definition at line 183 of file Nhx.h.
References bpp::AbstractOTree::write().
|
inlinevirtual |
Write a tree to a stream.
tree | A tree object. |
out | The output stream. |
Exception | If an error occured. |
Implements bpp::AbstractOTree.
Definition at line 188 of file Nhx.h.
References write_().
|
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 occured. |
Reimplemented from bpp::AbstractOMultiTree.
Definition at line 211 of file Nhx.h.
References bpp::AbstractOMultiTree::write().
|
inlinevirtual |
Write trees to a stream.
trees | A vector of tree objects. |
out | The output stream. |
Exception | If an error occured. |
Implements bpp::AbstractOMultiTree.
Definition at line 215 of file Nhx.h.
References write_().
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprivate |
Definition at line 140 of file Nhx.h.
Referenced by parenthesisToNode().
|
private |
Definition at line 138 of file Nhx.h.
Referenced by changeNamesToTags(), changeTagsToNames(), propertiesToParenthesis(), registerProperty(), and setNodeProperties().
|
private |
Definition at line 139 of file Nhx.h.
Referenced by propertiesToParenthesis(), setNodeProperties(), and useTagsAsPropertyNames().