A library for working with phylogenetic and population genetic data.
v0.32.0
NewickReader Class Reference

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

Inherited by PlacementTreeNewickReader, CommonTreeNewickReader, IndexedAttributeTreeNewickReader, KeyedAttributeTreeNewickReader, and SimpleNewickTreeNewickReader.

Detailed Description

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

Public Member Functions

 NewickReader ()=default
 
 NewickReader (NewickReader &&)=default
 
 NewickReader (NewickReader const &)=default
 
virtual ~NewickReader ()=default
 
Tree broker_to_tree (NewickBroker const &broker) const
 Build a Tree from a NewickBroker. More...
 
Tree broker_to_tree_destructive (NewickBroker &broker) const
 Build a Tree from a NewickBroker. More...
 
bool enable_tags () const
 Return whether currently Newick tags are enabled. More...
 
NewickReaderenable_tags (bool value)
 Set whether Newick tags are enabled for reading. More...
 
NewickReaderoperator= (NewickReader &&)=default
 
NewickReaderoperator= (NewickReader const &)=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_after_semicolon(), stop after the semicolon or continue until the end of the input, checking if there are only comments. More...
 
Tree read (std::shared_ptr< utils::BaseInputSource > source) const
 Read a single Tree from an input source containing a Newick tree. More...
 
void read (std::shared_ptr< utils::BaseInputSource > source, TreeSet &target, std::string const &default_name="") const
 Add Trees to a TreeSet from an input source containing a list of Newick trees. More...
 
TreeSet read (std::vector< std::shared_ptr< utils::BaseInputSource >> sources, std::string const &default_name="") const
 Return a TreeSet from a list of input sources containing Newick trees. More...
 
void read (std::vector< std::shared_ptr< utils::BaseInputSource >> sources, TreeSet &target, std::string const &default_name="") const
 Fill a TreeSet from a list of input sources containing Newick trees. More...
 
bool stop_after_semicolon () const
 Return whether currently reading stops after the semicolon that finishes a Newick tree. More...
 
NewickReaderstop_after_semicolon (bool value)
 Set whether reading a single tree 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(Tree &tree) >
 Function type that allows to do some finalizing work with the 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_functionelement_to_edge_plugins
 
std::vector< element_to_node_functionelement_to_node_plugins
 
std::vector< finish_reading_functionfinish_reading_plugins
 
std::vector< prepare_reading_functionprepare_reading_plugins
 

Constructor & Destructor Documentation

◆ NewickReader() [1/3]

NewickReader ( )
default

◆ ~NewickReader()

virtual ~NewickReader ( )
virtualdefault

◆ NewickReader() [2/3]

NewickReader ( NewickReader const &  )
default

◆ NewickReader() [3/3]

NewickReader ( NewickReader &&  )
default

Member Function Documentation

◆ broker_to_tree()

Tree broker_to_tree ( NewickBroker const &  broker) const

Build a Tree from a NewickBroker.

This is mainly an internal function, but can be used by other functions that have a NewickBroker and want to convert it into an actual Tree object.

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

◆ broker_to_tree_destructive()

Tree broker_to_tree_destructive ( NewickBroker broker) const

Build a Tree from a NewickBroker.

Same as broker_to_tree(), but destroys the NewickBroker while building the Tree. This saves memory (~50%), and is mainly intended as an internal function for reading.

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

◆ enable_tags() [1/2]

bool enable_tags ( ) const

Return whether currently Newick tags are enabled.

See enable_tags( bool ) for details.

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

◆ enable_tags() [2/2]

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 833 of file tree/formats/newick/reader.cpp.

◆ operator=() [1/2]

NewickReader& operator= ( NewickReader &&  )
default

◆ operator=() [2/2]

NewickReader& operator= ( NewickReader const &  )
default

◆ parse_multiple_trees()

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 120 of file tree/formats/newick/reader.cpp.

◆ parse_named_tree()

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 153 of file tree/formats/newick/reader.cpp.

◆ parse_single_tree()

Tree parse_single_tree ( utils::InputStream input_stream) const

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

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

◆ read() [1/4]

Tree read ( std::shared_ptr< utils::BaseInputSource source) const

Read a single Tree from an input source containing a Newick tree.

Use functions such as utils::from_file() and utils::from_string() to conveniently get an input source that can be used here.

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

◆ read() [2/4]

void read ( std::shared_ptr< utils::BaseInputSource source,
TreeSet target,
std::string const &  default_name = "" 
) const

Add Trees to a TreeSet from an input source 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 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.

Use functions such as utils::from_file() and utils::from_string() to conveniently get an input source that can be used here.

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

◆ read() [3/4]

TreeSet read ( std::vector< std::shared_ptr< utils::BaseInputSource >>  sources,
std::string const &  default_name = "" 
) const

Return a TreeSet from a list of input sources containing Newick trees.

See read() for details.

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

◆ read() [4/4]

void read ( std::vector< std::shared_ptr< utils::BaseInputSource >>  sources,
TreeSet target,
std::string const &  default_name = "" 
) const

Fill a TreeSet from a list of input sources containing Newick trees.

See read() for details.

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

◆ stop_after_semicolon() [1/2]

bool stop_after_semicolon ( ) const

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

See stop_after_semicolon( bool ) for details.

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

◆ stop_after_semicolon() [2/2]

NewickReader & stop_after_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 844 of file tree/formats/newick/reader.cpp.

Member Typedef Documentation

◆ create_edge_data_function

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 CommonEdgeData for such a data type, and CommonTreeNewickReaderPlugin for a class that uses a fitting function to create this data type.

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

◆ create_node_data_function

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 CommonNodeData for such a data type, and CommonTreeNewickReaderPlugin for a class that uses a fitting function to create this data type.

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

◆ element_to_edge_function

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 136 of file tree/formats/newick/reader.hpp.

◆ element_to_node_function

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 126 of file tree/formats/newick/reader.hpp.

◆ finish_reading_function

using finish_reading_function = std::function< void( Tree& tree ) >

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

This can for example be used for some cleanup.

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

◆ prepare_reading_function

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 84 of file tree/formats/newick/reader.hpp.

Member Data Documentation

◆ create_edge_data_plugin

create_edge_data_function create_edge_data_plugin

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

◆ create_node_data_plugin

create_node_data_function create_node_data_plugin

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

◆ element_to_edge_plugins

std::vector<element_to_edge_function> element_to_edge_plugins

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

◆ element_to_node_plugins

std::vector<element_to_node_function> element_to_node_plugins

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

◆ finish_reading_plugins

std::vector<finish_reading_function> finish_reading_plugins

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

◆ prepare_reading_plugins

std::vector<prepare_reading_function> prepare_reading_plugins

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


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