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

#include <genesis/tree/printer/compact.hpp>

Detailed Description

Print a Tree in a compact form, i.e., each node and edge on one line.

For example, given the Newick tree

(((A:0.2,B:0.3)C:0.3,(D:0.4,E:0.45,F:0.3,G:0.35)H:0.25)I:0.8,J:0.4,K:0.5)L;

and using the print( Tree const& ) function for CommonTrees, the output is

L: 0.8
├── I: 0.8
│   ├── C: 0.3
│   │   ├── A: 0.2
│   │   └── B: 0.3
│   └── H: 0.25
│       ├── D: 0.4
│       ├── E: 0.45
│       ├── F: 0.3
│       └── G: 0.35
├── J: 0.4
└── K: 0.5

Using the print() functions with function parameters, it is also possible to print custom data for each node and edge.

Definition at line 82 of file compact.hpp.

Public Member Functions

 PrinterCompact ()=default
 Default constructor. More...
 
 PrinterCompact (PrinterCompact &&)=default
 Default move constructor. More...
 
 PrinterCompact (PrinterCompact const &)=default
 Default copy constructor. More...
 
 ~PrinterCompact ()=default
 Default destructor. More...
 
long limit () const
 Get the current line limit. More...
 
PrinterCompactlimit (long value)
 Set the line limit. More...
 
PrinterCompactoperator= (PrinterCompact &&)=default
 Default move assignment. More...
 
PrinterCompactoperator= (PrinterCompact const &)=default
 Deault copy assignment. More...
 
void print (std::ostream &out, Tree const &tree, std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const print_line)
 Print a compact representation of a Tree to an output stream, using a given function for output of the Node and Edge data. More...
 
std::string print (Tree const &tree)
 Print a compact representation of a Tree to a std::string, for CommonTrees. More...
 
std::string print (Tree const &tree, std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const print_line)
 Print a compact representation of a Tree to a std::string, using a given function for output of the Node and Edge data. More...
 

Constructor & Destructor Documentation

◆ PrinterCompact() [1/3]

PrinterCompact ( )
default

Default constructor.

◆ ~PrinterCompact()

~PrinterCompact ( )
default

Default destructor.

◆ PrinterCompact() [2/3]

PrinterCompact ( PrinterCompact const &  )
default

Default copy constructor.

◆ PrinterCompact() [3/3]

PrinterCompact ( PrinterCompact &&  )
default

Default move constructor.

Member Function Documentation

◆ limit() [1/2]

long limit ( ) const
inline

Get the current line limit.

See limit( long ) for details.

Definition at line 196 of file compact.hpp.

◆ limit() [2/2]

PrinterCompact& limit ( long  value)
inline

Set the line limit.

If set to a negative value, the full tree is printed. For any value greater than 0, only this many lines are printed, following a preorder traversal of the tree. If the tree contains more nodes than being printed, an additional line with ellipsis is printed, to indicate this fact.

Definition at line 185 of file compact.hpp.

◆ operator=() [1/2]

PrinterCompact& operator= ( PrinterCompact &&  )
default

Default move assignment.

◆ operator=() [2/2]

PrinterCompact& operator= ( PrinterCompact const &  )
default

Deault copy assignment.

◆ print() [1/3]

void print ( std::ostream &  out,
Tree const &  tree,
std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const  print_line 
)

Print a compact representation of a Tree to an output stream, using a given function for output of the Node and Edge data.

The print_line function parameter is used to customize the output per printed line: The function takes the current TreeNode and TreeEdge, and returns the desired string representation for that line. See the implementation of print( Tree const& ) for an example.

Definition at line 50 of file compact.cpp.

◆ print() [2/3]

std::string print ( Tree const &  tree)

Print a compact representation of a Tree to a std::string, for CommonTrees.

The function casts the node and edge data to CommonNodeData and CommonEdgeData, and, if successfull, prints the node name and branch length for each line.

If the data is not actually default data, the nodes are printed without any text, i.e., only the topology of the Tree via lines is shown.

Definition at line 161 of file compact.cpp.

◆ print() [3/3]

std::string print ( Tree const &  tree,
std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const  print_line 
)

Print a compact representation of a Tree to a std::string, using a given function for output of the Node and Edge data.

See print() for details on the print_line function parameter.

Definition at line 149 of file compact.cpp.


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