A library for working with phylogenetic and population genetic data.
v0.27.0
PhyloxmlWriter Class Reference

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

Inherited by CommonTreePhyloxmlWriter.

Detailed Description

Write a Tree to Phyloxml format.

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

PhyloxmlWriter().write( tree, utils::to_file( "path/to/tree.phyloxml" ));

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 CommonTreePhyloxmlWriterPlugin is a convenience class that provides such plugin functions. It translates from a CommonTree 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 CommonTreePhyloxmlWriter, 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 &&)=default
 
 PhyloxmlWriter (PhyloxmlWriter const &)=default
 
virtual ~PhyloxmlWriter ()=default
 
PhyloxmlWriteroperator= (PhyloxmlWriter &&)=default
 
PhyloxmlWriteroperator= (PhyloxmlWriter const &)=default
 
void to_document (Tree const &tree, utils::XmlDocument &xml) const
 Store the information of the tree into an Phyloxml-formatted XmlDocument. More...
 
void write (Tree const &tree, std::shared_ptr< utils::BaseOutputTarget > target) const
 Write a Tree to an output target, using the Phyloxml format. 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_functionedge_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_functionfinish_writing_plugins
 Collect all functions to be called after finishing the actual tree writing. More...
 
std::vector< node_to_element_functionnode_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_functionprepare_writing_plugins
 Collect all functions to be called before starting the actual tree writing. More...
 

Constructor & Destructor Documentation

◆ PhyloxmlWriter() [1/3]

PhyloxmlWriter ( )
default

◆ ~PhyloxmlWriter()

virtual ~PhyloxmlWriter ( )
virtualdefault

◆ PhyloxmlWriter() [2/3]

PhyloxmlWriter ( PhyloxmlWriter const &  )
default

◆ PhyloxmlWriter() [3/3]

PhyloxmlWriter ( PhyloxmlWriter &&  )
default

Member Function Documentation

◆ operator=() [1/2]

PhyloxmlWriter& operator= ( PhyloxmlWriter &&  )
default

◆ operator=() [2/2]

PhyloxmlWriter& operator= ( PhyloxmlWriter const &  )
default

◆ to_document()

void to_document ( Tree const &  tree,
utils::XmlDocument xml 
) const

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

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

◆ write()

void write ( Tree const &  tree,
std::shared_ptr< utils::BaseOutputTarget target 
) const

Write a Tree to an output target, using the Phyloxml format.

See the output target convenience functions utils::to_file(), utils::to_stream(), and utils::to_string() for examples of how to obtain a suitable output target.

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

Member Typedef Documentation

◆ edge_to_element_function

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.

◆ finish_writing_function

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.

◆ node_to_element_function

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.

◆ prepare_writing_function

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

◆ edge_to_element_plugins

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 206 of file tree/formats/phyloxml/writer.hpp.

◆ finish_writing_plugins

std::vector<finish_writing_function> finish_writing_plugins

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

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

◆ node_to_element_plugins

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 200 of file tree/formats/phyloxml/writer.hpp.

◆ prepare_writing_plugins

std::vector<prepare_writing_function> prepare_writing_plugins

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

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


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