|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
67 std::shared_ptr<utils::BaseOutputTarget> target,
70 auto& os = target->ostream();
78 bool need_qmarks = force_quot_marks_;
79 need_qmarks |= ( std::string::npos != name.find_first_of(
" :;()[],=" ));
80 need_qmarks |= ( write_tags_ && std::string::npos != name.find_first_of(
"{}" ));
83 os << quotation_mark_ << name << quotation_mark_;
96 std::ostringstream oss;
109 prepare_plugin( tree, broker );
120 bn.
depth = depth[ it.node().index() ];
123 node_plugin( it.node(), bn );
128 if( !it.is_last_iteration() ) {
130 edge_plugin( it.edge(), bn );
139 finish_plugin( tree, broker );
146 auto& os = target->ostream();
153 size_t prev_depth = 0;
154 size_t cur_length = 0;
155 for(
size_t pos_rev = 0; pos_rev < broker.
size(); ++pos_rev ) {
156 auto const pos = (broker.
size() - 1) - pos_rev;
157 auto const& elem = broker[pos];
158 if( elem.depth < 0 ) {
159 throw std::runtime_error(
"Invalid NewickBroker: Depth < 0." );
165 assert( elem.depth >= 0 );
166 for(
size_t i = prev_depth; i < static_cast<size_t>( elem.depth ); ++i ) {
173 cur_length += write_( broker[pos], os );
183 if( broker[ pos - 1 ].depth == elem.depth - 1 ) {
191 prev_depth = elem.depth;
194 if( line_length_ > 0 && cur_length >= line_length_ ) {
207 if( trailing_new_line_ ) {
228 bool need_qmarks = force_quot_marks_;
229 need_qmarks |= ( std::string::npos != bn.
name.find_first_of(
" :;()[]," ));
230 need_qmarks |= ( write_tags_ && std::string::npos != bn.
name.find_first_of(
"{}" ));
233 for(
auto const& c : bn.
name ) {
235 throw std::runtime_error(
237 "found in Newick node label."
243 os << quotation_mark_ << bn.
name << quotation_mark_;
252 if( write_values_ ) {
253 for( std::string
const& v : bn.
values ) {
260 if( write_comments_ ) {
261 for( std::string
const& c : bn.
comments ) {
262 os <<
"[" << c <<
"]";
269 for( std::string
const& t : bn.
tags ) {
270 os <<
"{" << t <<
"}";
NewickBroker tree_to_broker(Tree const &tree) const
Transform the information of the tree into a NewickBroker object.
std::string name
Name of the node.
Provides functions for accessing the file system.
std::vector< std::string > comments
Arbitrary strings that can be attached to a node, e.g. in Newick format via "[]".
std::vector< finish_writing_function > finish_writing_plugins
Collect all functions to be called after finishing the actual tree writing.
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
void clear()
Deletes all nodes from the broker.
std::vector< prepare_writing_function > prepare_writing_plugins
Collect all functions to be called before starting the actual tree writing.
tree::TreeSet tree_set(SampleSet const &sample_set)
Return a TreeSet containing all the trees of the SampleSet.
double length(Tree const &tree)
Get the length of the tree, i.e., the sum of all branch lengths.
void write(Tree const &tree, std::shared_ptr< utils::BaseOutputTarget > target) const
Write a Tree to an output target, using the Newick format.
std::string const & name_at(size_t index) const
Provides some valuable additions to STD.
void push_top(NewickBrokerElement const &node)
std::vector< std::string > values
Numerical values associated with the node, i.e. branch lengths.
Class for representing phylogenetic trees.
Provides easy and fast logging functionality.
constexpr bool is_print(char c) noexcept
Return whether a char is a printable character, according to isprint of the cctype header,...
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 Newick representat...
std::vector< std::string > tags
Arbitrary strings that can be attached to a node, e.g. in Newick format via "{}".
std::string to_string(Tree const &tree) const
Shorthand to write a Tree to Newick format and return it is a string.
std::shared_ptr< BaseOutputTarget > to_stream(std::ostream &target_stream, GzipCompressionLevel compression_level=GzipCompressionLevel::kNoCompression)
Obtain an output target for writing to a stream.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Stores a Newick tree in an intermediate format that can be further processed into a Tree.
void assign_ranks() const
Iterate over the tree and assign ranks (= number of immediate children) to all nodes.
long depth
Depth of the node in the tree, i.e. its distance from the root.
std::string char_to_hex(char c, bool full)
Return the name and hex representation of a char.
Store the information for one element of a Newick tree.
Header of Tree distance methods.
std::vector< size_t > node_path_length_vector(Tree const &tree, TreeNode const &node)
Return a vector containing the depth of all nodes with respect to the given start node.
size_t size() const
Returns the size of the stack, i.e. the number of nodes stored in the broker.
utils::Range< IteratorPostorder< true > > postorder(ElementType const &element)
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 Newick representat...