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

#include <genesis/tree/formats/newick/reader.hpp>

Inherited by PlacementTreeNewickReader, DefaultTreeNewickReader, IndexedAttributeTreeNewickReader, and KeyedAttributeTreeNewickReader.

Detailed Description

Definition at line 64 of file tree/formats/newick/reader.hpp.

Public Member Functions

 NewickReader ()=default
 
 NewickReader (NewickReader const &)=default
 
 NewickReader (NewickReader &&)=default
 
virtual ~NewickReader ()=default
 
NewickReaderenable_tags (bool value)
 Set whether Newick tags are enabled for reading. More...
 
bool enable_tags () const
 Return whether currently Newick tags are enabled. More...
 
Tree from_file (std::string const &filename) const
 Read a Tree from a file containing a Newick tree. More...
 
void from_file (std::string const &filename, TreeSet &tree_set, std::string const &default_name="") const
 Add Trees to a TreeSet from a file containing a list of Newick trees. More...
 
void from_files (std::vector< std::string > const &filenames, TreeSet &tree_set) const
 Fill a TreeSet from a list of files containing Newick trees. More...
 
Tree from_stream (std::istream &input_stream) const
 Read a Tree from an input stream containing a Newick tree. More...
 
void from_stream (std::istream &input_stream, TreeSet &tree_set, std::string const &default_name="") const
 Add Trees to a TreeSet from an input stream containing a list of Newick trees. More...
 
Tree from_string (std::string const &tree_string) const
 Read a Tree from a string containing a Newick tree. More...
 
void from_string (std::string const &tree_string, TreeSet &tree_set, std::string const &default_name="") const
 Add Trees to a TreeSet from a string containing a list of Newick trees. More...
 
void from_strings (std::vector< std::string > const &tree_strings, TreeSet &tree_set, std::string const &default_name="") const
 Fill a TreeSet from a list of strings containing Newick trees. More...
 
NewickReaderoperator= (NewickReader const &)=default
 
NewickReaderoperator= (NewickReader &&)=default
 
void parse_multiple_trees (utils::InputStream &input_stream, TreeSet &tree_set, std::string const &default_name) const
 Parse until the end of the stream and add all Trees to the TreeSet. More...
 
std::pair< std::string, Treeparse_named_tree (utils::InputStream &input_stream) const
 Parse one named tree, i.e., a tree as described here. More...
 
Tree parse_single_tree (utils::InputStream &input_stream) const
 Parse a single tree. Depending on stop_at_semicolon(), stop after the semicolon or continue until the end of the input, checking if there are only comments. More...
 
NewickReaderstop_at_semicolon (bool value)
 Set whether reading a single tree stops after the semicolon that finishes a Newick tree. More...
 
bool stop_at_semicolon () const
 Return whether currently reading stops after the semicolon that finishes a Newick tree. More...
 

Public Types

using create_edge_data_function = std::function< void(TreeEdge &edge) >
 Function type used to create the data pointer for each TreeEdge. More...
 
using create_node_data_function = std::function< void(TreeNode &node) >
 Function type used to create the data pointer for each TreeNode. More...
 
using element_to_edge_function = std::function< void(NewickBrokerElement const &element, TreeEdge &edge) >
 Function type that translates from a NewickBrokerElement to a TreeEdge. More...
 
using element_to_node_function = std::function< void(NewickBrokerElement const &element, TreeNode &node) >
 Function type that translates from a NewickBrokerElement to a TreeNode. More...
 
using finish_reading_function = std::function< void(NewickBroker const &broker, Tree &tree) >
 Function type that allows to do some finalizing work with the NewickBroker and Tree after the actual tree reading finished. More...
 
using prepare_reading_function = std::function< void(NewickBroker const &broker, Tree &tree) >
 Function type that allows to do some preparatory work with the NewickBroker and Tree before the actual tree reading begins. More...
 

Public Attributes

create_edge_data_function create_edge_data_plugin
 
create_node_data_function create_node_data_plugin
 
std::vector
< element_to_edge_function
element_to_edge_plugins
 
std::vector
< element_to_node_function
element_to_node_plugins
 
std::vector
< finish_reading_function
finish_reading_plugins
 
std::vector
< prepare_reading_function
prepare_reading_plugins
 

Constructor & Destructor Documentation

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

Member Function Documentation

NewickReader & enable_tags ( bool  value)

Set whether Newick tags are enabled for reading.

Newick tags are an inofficial extension to the Newick format. They consist of values in curly braces, for example {value} and can occur where node labels are allowed in Newick.

For example:

(( A{0}, B{1} )D{3}, C{4} )R{5};

Thus, they are used similarly to the way Newick comments are often (mis-)used to annotate a tree with additional information about the nodes and edges.

They are for example used in the jplace format, see placement::JplaceReader for details.

If this option is set to true, such tags are stored in NewickBrokerElement::tags. If it is false (default), any string that has the form of Newick tags will simply be treated as part of the node name.

Definition at line 818 of file tree/formats/newick/reader.cpp.

bool enable_tags ( ) const

Return whether currently Newick tags are enabled.

See enable_tags( bool ) for details.

Definition at line 824 of file tree/formats/newick/reader.cpp.

Tree from_file ( std::string const &  filename) const

Read a Tree from a file containing a Newick tree.

Definition at line 66 of file tree/formats/newick/reader.cpp.

void from_file ( std::string const &  filename,
TreeSet tree_set,
std::string const &  default_name = "" 
) const

Add Trees to a TreeSet from a file containing a list of Newick trees.

See from_string() for more information.

Definition at line 91 of file tree/formats/newick/reader.cpp.

void from_files ( std::vector< std::string > const &  filenames,
TreeSet tree_set 
) const

Fill a TreeSet from a list of files containing Newick trees.

This function can for example be used with the output of utils::dir_list_files().

Definition at line 113 of file tree/formats/newick/reader.cpp.

Tree from_stream ( std::istream &  input_stream) const

Read a Tree from an input stream containing a Newick tree.

Definition at line 60 of file tree/formats/newick/reader.cpp.

void from_stream ( std::istream &  input_stream,
TreeSet tree_set,
std::string const &  default_name = "" 
) const

Add Trees to a TreeSet from an input stream containing a list of Newick trees.

See from_string() for more information.

Definition at line 82 of file tree/formats/newick/reader.cpp.

Tree from_string ( std::string const &  tree_string) const

Read a Tree from a string containing a Newick tree.

Definition at line 72 of file tree/formats/newick/reader.cpp.

void from_string ( std::string const &  tree_string,
TreeSet tree_set,
std::string const &  default_name = "" 
) const

Add Trees to a TreeSet from a string containing a list of Newick trees.

These trees can either be named or unnamed, using this syntax:

Tree_A = (...);
'Tree B'=(...);
(...);

where the first two lines are named trees and the third line is an unnamed tree. The trees do not have to be on distinct lines of the input, as whitespaces are completely stripped anyway. However, they are required to end with a semicolon ;.

In case of unnamed trees, a default_name can be provided, which will be appended by a counter that counts up all unnamed trees. For example, default_name == "tree_" results in trees named "tree_0", "tree_1" etc. If no default name is given, the trees will simply be named using the counter itself.

The Trees are simply added to the TreeSet. That means, Trees that already exist in the TreeSet are kept. Thus, this function can be used to add additional Trees to the set.

Definition at line 100 of file tree/formats/newick/reader.cpp.

void from_strings ( std::vector< std::string > const &  tree_strings,
TreeSet tree_set,
std::string const &  default_name = "" 
) const

Fill a TreeSet from a list of strings containing Newick trees.

Definition at line 122 of file tree/formats/newick/reader.cpp.

NewickReader& operator= ( NewickReader const &  )
default
NewickReader& operator= ( NewickReader &&  )
default
void parse_multiple_trees ( utils::InputStream input_stream,
TreeSet tree_set,
std::string const &  default_name 
) const

Parse until the end of the stream and add all Trees to the TreeSet.

Definition at line 154 of file tree/formats/newick/reader.cpp.

std::pair< std::string, Tree > parse_named_tree ( utils::InputStream input_stream) const

Parse one named tree, i.e., a tree as described here.

Definition at line 187 of file tree/formats/newick/reader.cpp.

Tree parse_single_tree ( utils::InputStream input_stream) const

Parse a single tree. Depending on stop_at_semicolon(), stop after the semicolon or continue until the end of the input, checking if there are only comments.

Definition at line 136 of file tree/formats/newick/reader.cpp.

NewickReader & stop_at_semicolon ( bool  value)

Set whether reading a single tree stops after the semicolon that finishes a Newick tree.

When reading a single Newick tree, it is possible that there is input after the semicolon. If this input is just Newick comments, this is allowed. However, other input might indicate an error in the tree. Using this function, the behaviour of the reading can be controlled.

If set to false (default), reading continues until the end of the input is reached. This is mostly wanted when reading e.g., a complete file. If then input contains invalid data (non-comments) after the semicolon, an execption is thrown.

If set to true, reading stops after the semicolon. This is useful if the Newick tree is part of some other file, e.g., Nexus. In this case, we simply want to stop and continue parsing the rest of the input as Nexus data.

Definition at line 829 of file tree/formats/newick/reader.cpp.

bool stop_at_semicolon ( ) const

Return whether currently reading stops after the semicolon that finishes a Newick tree.

See stop_at_semicolon( bool ) for details.

Definition at line 835 of file tree/formats/newick/reader.cpp.

Member Typedef Documentation

using create_edge_data_function = std::function< void( TreeEdge& edge ) >

Function type used to create the data pointer for each TreeEdge.

This function is called for each TreeEdge in order to create a data pointer. The type of this pointer is usually the most derived data class that is needed to store the data of the tree. For example, see DefaultEdgeData for such a data type, and DefaultTreeNewickReaderPlugin for a class that uses a fitting function to create this data type.

Definition at line 113 of file tree/formats/newick/reader.hpp.

using create_node_data_function = std::function< void( TreeNode& node ) >

Function type used to create the data pointer for each TreeNode.

This function is called for each TreeNode in order to create a data pointer. The type of this pointer is usually the most derived data class that is needed to store the data of the tree. For example, see DefaultNodeData for such a data type, and DefaultTreeNewickReaderPlugin for a class that uses a fitting function to create this data type.

Definition at line 102 of file tree/formats/newick/reader.hpp.

using element_to_edge_function = std::function< void( NewickBrokerElement const& element, TreeEdge& edge ) >

Function type that translates from a NewickBrokerElement to a TreeEdge.

This is called for each TreeEdge while reading the Tree and is used to transfer data from a representation in the Newick format into the TreeEdge.

Definition at line 133 of file tree/formats/newick/reader.hpp.

using element_to_node_function = std::function< void( NewickBrokerElement const& element, TreeNode& node ) >

Function type that translates from a NewickBrokerElement to a TreeNode.

This is called for each TreeNode while reading the Tree and is used to transfer data from a representation in the Newick format into the TreeNode.

Definition at line 123 of file tree/formats/newick/reader.hpp.

using finish_reading_function = std::function< void( NewickBroker const& broker, Tree& tree ) >

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

This can for example be used for some cleanup.

Definition at line 91 of file tree/formats/newick/reader.hpp.

using prepare_reading_function = std::function< void( NewickBroker const& broker, Tree& tree ) >

Function type that allows to do some preparatory work with the NewickBroker and Tree before the actual tree reading 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 filling the nodes with data.

Definition at line 81 of file tree/formats/newick/reader.hpp.

Member Data Documentation

create_edge_data_function create_edge_data_plugin

Definition at line 345 of file tree/formats/newick/reader.hpp.

create_node_data_function create_node_data_plugin

Definition at line 344 of file tree/formats/newick/reader.hpp.

std::vector<element_to_edge_function> element_to_edge_plugins

Definition at line 348 of file tree/formats/newick/reader.hpp.

std::vector<element_to_node_function> element_to_node_plugins

Definition at line 347 of file tree/formats/newick/reader.hpp.

std::vector<finish_reading_function> finish_reading_plugins

Definition at line 342 of file tree/formats/newick/reader.hpp.

std::vector<prepare_reading_function> prepare_reading_plugins

Definition at line 341 of file tree/formats/newick/reader.hpp.


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