A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PhyloxmlWriter Class Reference

#include <genesis/tree/formats/phyloxml/writer.hpp>

Inherited by DefaultTreePhyloxmlWriter.

Detailed Description

Write a Tree to Phyloxml format.

This class supports to write a Tree into a Phyloxml format representation, using

It understands the Phyloxml format, but is agnostic of the actual data representation of TreeNode and TreeEdge data. This approach allows to store data in any wanted format.

In order to translate data from the Tree into a Phyloxml format representation, a set of plugin functions is used, that need to be set before writing a Tree. Those functions are a form of intermediaries, which take tree data and turn them into the wanted Phyloxml representation. It is possible to use lambdas for this, or any other function that can be stored in a std::function.

The following plugin points are provided:

For example, the DefaultTreePhyloxmlWriterPlugin is a convenience class that provides such plugin functions. It translates from a DefaultTree with TreeNodes that contain names and TreeEdges that contain branch lengths into the standard Phyloxml format. Using plugin classes like this additionally allows to use state for the plugin functions - that is, to use some settings for how to write data.

Furthermore, as we use vectors of plugin functions, it is possible (and often necessary) to register multiple such functions, which are then called one after another. This allows to e.g., first translate a branch length for an edge in one plugin function, and then translating a bootstrap value or edge color in another plugin function.

This whole approach is a bit tedious, but unfortunately the price for the flexibility of this class. In order to keep the standard use cases simple, we also provide classes like DefaultTreePhyloxmlWriter, which hides the whole plugin system and allows simple writing of default trees to standard Phyloxml.

Definition at line 101 of file tree/formats/phyloxml/writer.hpp.

Public Member Functions

 PhyloxmlWriter ()=default
 
 PhyloxmlWriter (PhyloxmlWriter const &)=default
 
 PhyloxmlWriter (PhyloxmlWriter &&)=default
 
virtual ~PhyloxmlWriter ()=default
 
PhyloxmlWriteroperator= (PhyloxmlWriter const &)=default
 
PhyloxmlWriteroperator= (PhyloxmlWriter &&)=default
 
void to_document (const Tree &tree, utils::XmlDocument &xml) const
 Store the information of the tree into an Phyloxml-formatted XmlDocument. More...
 
void to_file (const Tree &tree, const std::string filename) const
 Writes the tree to a file in Phyloxml format. More...
 
void to_string (const Tree &tree, std::string &ts) const
 Gives a Phyloxml string representation of the tree. More...
 
std::string to_string (const Tree &tree) const
 Return a Phyloxml string representation of the tree. More...
 

Public Types

using edge_to_element_function = std::function< void(TreeEdge const &edge, utils::XmlElement &element) >
 Function type that translates from a TreeEdge to an XmlElement. More...
 
using finish_writing_function = std::function< void(Tree const &tree, utils::XmlDocument &xml) >
 Function type that allows to do some finalizing work with the Tree and XmlDocument after the actual tree writing finished. More...
 
using node_to_element_function = std::function< void(TreeNode const &node, utils::XmlElement &element) >
 Function type that translates from a TreeNode to an XmlElement. More...
 
using prepare_writing_function = std::function< void(Tree const &tree, utils::XmlDocument &xml) >
 Function type that allows to do some preparatory work with the Tree and XmlDocument before the actual tree writing begins. More...
 

Public Attributes

std::vector
< edge_to_element_function
edge_to_element_plugins
 Collect all functions to be called for each TreeEdge in order to translate it to a Phyloxml representation. More...
 
std::vector
< finish_writing_function
finish_writing_plugins
 Collect all functions to be called after finishing the actual tree writing. More...
 
std::vector
< node_to_element_function
node_to_element_plugins
 Collect all functions to be called for each TreeNode in order to translate it to a Phyloxml representation. More...
 
std::vector
< prepare_writing_function
prepare_writing_plugins
 Collect all functions to be called before starting the actual tree writing. More...
 

Constructor & Destructor Documentation

PhyloxmlWriter ( )
default
virtual ~PhyloxmlWriter ( )
virtualdefault
PhyloxmlWriter ( PhyloxmlWriter const &  )
default
PhyloxmlWriter ( PhyloxmlWriter &&  )
default

Member Function Documentation

PhyloxmlWriter& operator= ( PhyloxmlWriter const &  )
default
PhyloxmlWriter& operator= ( PhyloxmlWriter &&  )
default
void to_document ( const Tree tree,
utils::XmlDocument xml 
) const

Store the information of the tree into an Phyloxml-formatted XmlDocument.

Definition at line 75 of file tree/formats/phyloxml/writer.cpp.

void to_file ( const Tree tree,
const std::string  filename 
) const

Writes the tree to a file in Phyloxml format.

If the file cannot be written to, the function throws an exception. Also, by default, if the file already exists, an exception is thrown. See Options::allow_file_overwriting() to change this behaviour.

Definition at line 56 of file tree/formats/phyloxml/writer.cpp.

void to_string ( const Tree tree,
std::string &  ts 
) const

Gives a Phyloxml string representation of the tree.

Definition at line 63 of file tree/formats/phyloxml/writer.cpp.

std::string to_string ( const Tree tree) const

Return a Phyloxml string representation of the tree.

Definition at line 68 of file tree/formats/phyloxml/writer.cpp.

Member Typedef Documentation

using edge_to_element_function = std::function< void( TreeEdge const& edge, utils::XmlElement& element ) >

Function type that translates from a TreeEdge to an XmlElement.

This is called for each TreeEdge while writing the Tree to Phyloxml and is used to transfer data from the edge into a suitable representation in the Phyloxml format.

Definition at line 150 of file tree/formats/phyloxml/writer.hpp.

using finish_writing_function = std::function< void( Tree const& tree, utils::XmlDocument& xml ) >

Function type that allows to do some finalizing work with the Tree and XmlDocument after the actual tree writing finished.

This can for example be used for some cleanup.

Definition at line 128 of file tree/formats/phyloxml/writer.hpp.

using node_to_element_function = std::function< void( TreeNode const& node, utils::XmlElement& element ) >

Function type that translates from a TreeNode to an XmlElement.

This is called for each TreeNode while writing the Tree to Phyloxml and is used to transfer data from the node into a suitable representation in the Phyloxml format.

Definition at line 139 of file tree/formats/phyloxml/writer.hpp.

using prepare_writing_function = std::function< void( Tree const& tree, utils::XmlDocument& xml ) >

Function type that allows to do some preparatory work with the Tree and XmlDocument before the actual tree writing begins.

This is for example useful if a certain kind of value for the nodes depends on other nodes. Using this function, such data can be collected and then used when writing the nodes.

Definition at line 118 of file tree/formats/phyloxml/writer.hpp.

Member Data Documentation

std::vector<edge_to_element_function> edge_to_element_plugins

Collect all functions to be called for each TreeEdge in order to translate it to a Phyloxml representation.

Definition at line 218 of file tree/formats/phyloxml/writer.hpp.

std::vector<finish_writing_function> finish_writing_plugins

Collect all functions to be called after finishing the actual tree writing.

Definition at line 206 of file tree/formats/phyloxml/writer.hpp.

std::vector<node_to_element_function> node_to_element_plugins

Collect all functions to be called for each TreeNode in order to translate it to a Phyloxml representation.

Definition at line 212 of file tree/formats/phyloxml/writer.hpp.

std::vector<prepare_writing_function> prepare_writing_plugins

Collect all functions to be called before starting the actual tree writing.

Definition at line 201 of file tree/formats/phyloxml/writer.hpp.


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