CompactTree
|
Classes | |
class | children_iterator |
class | leaves_iterator |
class | levelorder_iterator |
class | postorder_iterator |
class | preorder_iterator |
Public Member Functions | |
compact_tree (const char *const input, bool is_fn=true, bool store_labels=true, bool store_lengths=true, size_t reserve=0) | |
compact_tree (const std::string &input, bool is_fn=true, bool store_labels=true, bool store_lengths=true, size_t reserve=0) | |
compact_tree (const compact_tree &o) | |
CT_NODE_T | add_child (const CT_NODE_T parent_node, const std::string &new_label=EMPTY_STRING, CT_LENGTH_T new_length=ZERO_LENGTH) |
void | print_newick (std::ostream &out, CT_NODE_T node=ROOT_NODE, bool include_semicolon=true) |
std::string | get_newick (CT_NODE_T node=ROOT_NODE, bool include_semicolon=true) |
size_t | get_num_nodes () const |
size_t | get_num_leaves () |
size_t | get_num_internal () |
CT_NODE_T | get_root () const |
bool | is_root (CT_NODE_T node) const |
bool | is_leaf (CT_NODE_T node) const |
CT_NODE_T | get_parent (CT_NODE_T node) const |
const std::vector< CT_NODE_T > & | get_children (CT_NODE_T node) const |
bool | has_edge_lengths () const |
void | clear_edge_lengths (bool shrink=true) |
CT_LENGTH_T | get_edge_length (CT_NODE_T node) const |
const std::vector< CT_LENGTH_T > & | get_edge_lengths () const |
void | set_edge_length (CT_NODE_T node, CT_LENGTH_T new_length) |
bool | has_labels () const |
void | clear_labels (bool shrink=true) |
const std::string & | get_label (CT_NODE_T node) const |
void | set_label (CT_NODE_T node, const std::string &new_label) |
const std::vector< std::string > & | get_labels () const |
void | replace_labels (const std::unordered_map< std::string, std::string > &label_map, bool include_internal=true) |
std::tuple< const std::string *, CT_LENGTH_T, CT_NODE_T, const std::vector< CT_NODE_T > * > | operator[] (CT_NODE_T i) const |
preorder_iterator | preorder_begin () |
preorder_iterator | preorder_end () |
postorder_iterator | postorder_begin () |
postorder_iterator | postorder_end () |
levelorder_iterator | levelorder_begin () |
levelorder_iterator | levelorder_end () |
leaves_iterator | leaves_begin () |
leaves_iterator | leaves_end () |
children_iterator | children_begin (CT_NODE_T node) |
children_iterator | children_end (CT_NODE_T node) |
CT_NODE_T | find_mrca (const std::unordered_set< CT_NODE_T > &nodes) const |
compact_tree | extract_subtree (CT_NODE_T node) |
double | calc_total_bl (bool include_internal=true, bool include_leaves=true) const |
double | calc_avg_bl (bool include_internal=true, bool include_leaves=true) const |
double | calc_dist (CT_NODE_T u, CT_NODE_T v) const |
std::vector< std::pair< std::pair< CT_NODE_T, CT_NODE_T >, double > > | calc_distance_matrix () |
compact_tree::compact_tree | ( | const char *const | input, |
bool | is_fn = true , |
||
bool | store_labels = true , |
||
bool | store_lengths = true , |
||
size_t | reserve = 0 |
||
) |
Load a tree from a Newick file or C string
input | The filename or C string of the tree to load |
is_fn | true if input is a filename (default), otherwise false if input is the Newick tree as a C string |
store_labels | true to store node labels (default), otherwise false (saves memory) |
store_lengths | true to store edge lengths (default), otherwise false (saves memory) |
reserve | How many nodes to reserve memory for up-front to avoid std::vector resizes. It's fine if the true number of nodes in the tree exceeds this value (the std::vector will resize automatically), but get as close as possible for speed. |
|
inline |
Load a tree from a Newick file or std::string
input | The filename or std::string of the tree to load |
is_fn | true if input is a filename (default), otherwise false if input is the Newick tree as an std::string |
store_labels | true to store node labels (default), otherwise false (saves memory) |
store_lengths | true to store edge lengths (default), otherwise false (saves memory) |
reserve | How many nodes to reserve memory for up-front to avoid std::vector resizes. It's fine if the true number of nodes in the tree exceeds this value (the std::vector will resize automatically), but get as close as possible for speed. |
|
inline |
Copy constructor
o | The other compact_tree to copy |
|
inline |
Add a child to an existing node
parent_node | The parent node |
new_label | The label of the new child node |
new_length | The length of edge incident to the new child node |
|
inline |
Calculate the average branch length of this tree
include_internal | true to include internal nodes, otherwise false |
include_leaves | true to include leaves, otherwise false |
|
inline |
Calculate the (weighted) distance between two nodes
u | The first node |
v | The second node |
u
and v
std::vector< std::pair< std::pair< CT_NODE_T, CT_NODE_T >, double > > compact_tree::calc_distance_matrix | ( | ) |
Calculate the (weighted) distance matrix between all pairs of leaves
vector<pair<pair<node,node>,double>>
containing all pairwise leaf distances as ((u,v), distance)
|
inline |
Calculate the total branch length of this tree
include_internal | true to include internal nodes, otherwise false |
include_leaves | true to include leaves, otherwise false |
|
inline |
Return an iterator referring to the first child of a node
node | The node to iterate over the children of |
node
|
inline |
Return an iterator referring to just past the last child of a node
node | The node to iterate over the children of |
node
|
inline |
Clear all edge lengths in this tree
shrink | true to deallocate the memory that was allocated to store the edge lengths, otherwise false |
|
inline |
Clear all labels in this tree
shrink | true to deallocate the memory that was allocated to store the labels, otherwise false |
compact_tree compact_tree::extract_subtree | ( | CT_NODE_T | node | ) |
Extract the subtree rooted at a given node
node | The node that is the root of the desired subtree |
node
CT_NODE_T compact_tree::find_mrca | ( | const std::unordered_set< CT_NODE_T > & | nodes | ) | const |
Find and return the Most Recent Common Ancestor (MRCA) of a collection of nodes
nodes | The nodes to find the MRCA of |
nodes
|
inline |
Get the children of a node
node | The node to get the children of |
node
|
inline |
Get the incident edge length of a node
node | The node to get the incident edge length of |
node
|
inline |
Get all edge lengths (return by reference)
|
inline |
Get the label of a node
node | The node to get the label of |
node
|
inline |
Get all labels (return by reference)
vector<string>
where the i
-th value is the label of node i
|
inline |
Return the Newick string of the subtree rooted at a specific node (defaults to the root = entire tree)
node | The root of the subtree to print the Newick string of |
include_semicolon | true to print a semicolon at the end of the Newick string (to end the tree), otherwise false (e.g. subtree) |
|
inline |
Get the total number of internal nodes in the tree. First time is O(n) scan; subsequent times are O(1) lookup
|
inline |
Get the total number of leaves in the tree. First time is O(n) scan; subsequent times are O(1) lookup
|
inline |
Get the total number of nodes in the tree using a O(1) lookup
|
inline |
Get the parent of a node
node | The node to get the parent of |
node
|
inline |
Get the root of this tree (should always be 0)
|
inline |
Check if this tree is storing edge lengths
true
if this tree is storing edge lengths, otherwise false
|
inline |
Check if this tree is storing labels
true
if this tree is storing labels, otherwise false
|
inline |
Check if a node is a leaf
node | The node to check |
true
if node
is a leaf, otherwise false
|
inline |
Check if a node is the root
node | The node to check |
true
if node
is the root, otherwise false
|
inline |
Return an iterator referring to the first node of a leaf iteration
|
inline |
Return an iterator referring to just past the last node of a leaf iteration
|
inline |
Return an iterator referring to the first node of a level-order traversal
|
inline |
Return an iterator referring just past the last node of a level-order traversal
|
inline |
Return the data associated with a given node
i | The node whose data to return |
tuple<const string*, CT_LENGTH_T, CT_NODE_T, const vector<CT_NODE_T>*>
containing (1) a pointer to the label, (2) the incident edge length, (3) the parent, and (4) a pointer to the collection of children of node i
|
inline |
Return an iterator referring to the first node of a post-order traversal
|
inline |
Return an iterator referring just past the last node of a post-order traversal
|
inline |
Return an iterator referring to the first node of a pre-order traversal
|
inline |
Return an iterator referring just past the last node of a pre-order traversal
void compact_tree::print_newick | ( | std::ostream & | out, |
CT_NODE_T | node = ROOT_NODE , |
||
bool | include_semicolon = true |
||
) |
Print the Newick string of the subtree rooted at a specific node (defaults to the root = entire tree)
out | The output stream to print the Newick string to |
node | The root of the subtree to print the Newick string of |
include_semicolon | true to print a semicolon at the end of the Newick string (to end the tree), otherwise false (e.g. subtree) |
|
inline |
Replace all labels that match a user-provided mapping
label_map | A mapping where keys are old labels and values are new labels (i.e., replace all occurrences of label s with label_map[s] ) |
include_internal | true to include internal nodes in the label replacement, otherwise false to only replace leaf labels |
|
inline |
Set the incident edge length of a node
node | The node to set the incident edge length of |
new_length | The new edge length to set |
|
inline |
Set the label of a node
node | The node to set the label of |
new_label | The new label to set |