|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
56 std::vector<std::string> names;
57 for(
auto const& node : tree.
nodes() ) {
58 if(
is_inner( node ) && leaves_only ) {
65 names.push_back( std::move( name ));
76 std::vector<std::string> names;
78 auto tree_name_set =
node_names( tree, leaves_only );
79 names.insert( names.end(), tree_name_set.begin(), tree_name_set.end() );
86 const std::string& name,
87 bool throw_on_failure,
88 bool replace_underscores
90 auto clean_name = name;
91 if (replace_underscores) {
96 for(
auto const& node : tree.
nodes() ) {
103 if( throw_on_failure ) {
104 throw std::invalid_argument(
"Cannot find node '" + name +
"' in tree." );
111 const std::string& name,
112 bool throw_on_failure,
113 bool replace_underscores
116 auto const& ctree =
static_cast< Tree const&
>( tree );
118 find_node( ctree, name, throw_on_failure, replace_underscores )
125 bool throw_on_failure,
126 bool replace_underscores
129 std::vector<TreeNode const*> node_list;
134 node_list.push_back(
find_node( tree, taxon, throw_on_failure, replace_underscores ));
142 bool throw_on_failure,
143 bool replace_underscores
146 std::vector<TreeNode*> node_list;
151 node_list.push_back(
find_node( tree, taxon, throw_on_failure, replace_underscores ));
163 for(
auto const& edge : tree.
edges() ) {
175 return *std::max_element(dists.begin(), dists.end());
193 auto const max_idx_1 = std::distance(
194 root_dists.begin(), std::max_element( root_dists.begin(), root_dists.end() )
196 assert( root_dists.size() == tree.
node_count() );
203 assert( far_dists.size() == tree.
node_count() );
204 return *std::max_element( far_dists.begin(), far_dists.end() );
216 std::vector<double> result;
218 for(
size_t i = 0; i < tree.
edge_count(); ++i ) {
228 for(
auto& edge : tree.
edges() ) {
237 for(
auto& edge : tree.
edges() ) {
244 if( tset.size() == 0 ) {
249 throw std::runtime_error(
250 "Cannot calculate average branch length tree. Trees do not have the same topology."
255 size_t num_edges = tset.at(0).edge_count();
256 auto avgs = std::vector<double>(num_edges, 0.0);
261 for(
auto& ct : tset ) {
271 if (it.is_first_iteration()) {
282 auto tree = tset.at(0);
290 if (it.is_first_iteration()) {
294 it.edge().data<
CommonEdgeData>().branch_length = avgs[idx] / tset.size();
size_t node_count() const
Return the number of TreeNodes of the Tree.
double height(Tree const &tree)
Get the height of the tree, i.e., the longest distance from the root to a leaf, measured using the br...
std::string replace_all(std::string const &text, std::string const &search, std::string const &replace)
Return a copy of a string, where all occurrences of a search string are replaced by a replace string.
std::vector< double > node_branch_length_distance_vector(Tree const &tree, TreeNode const *node)
Return a vector containing the distance of all nodes with respect to the given start node,...
std::vector< std::string > node_names(Tree const &tree, bool leaves_only)
Returns a list of all TreeNode names of a Tree.
bool is_inner(TreeLink const &link)
Return true iff the node of the given link is an inner node.
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.
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
utils::Range< IteratorPreorder< true > > preorder(ElementType const &element)
bool identical_topology(Tree const &lhs, Tree const &rhs, bool identical_indices)
Return whether both trees have an identical topology.
Provides some commonly used string utility functions.
double diameter(Tree const &tree)
Get the diameter of the tree, i.e., the longest distance between any two nodes, measured using the br...
Header of CommonTree distance methods.
Class for representing phylogenetic trees.
bool empty() const
Return whether the Tree is empty (i.e., has no nodes, edges and links).
double branch_length
Branch length of the edge.
std::string name
Name of the node.
std::vector< double > branch_lengths(Tree const &tree)
Get a vector of all branch lengths of a Tree, index by the edge index.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
std::vector< TreeNode const * > find_nodes(Tree const &tree, std::vector< std::string > const &node_names, bool throw_on_failure, bool replace_underscores)
Find TreeNodes in a Tree, given their name.
utils::Range< IteratorNodes > nodes()
utils::Range< IteratorEdges > edges()
Common class containing the commonly needed data for tree edges.
Tree average_branch_length_tree(std::vector< Tree > const &tset)
Return a Tree where the branch lengths are the average of the Trees in the given vector of Trees or T...
Common class containing the commonly needed data for tree nodes.
bool is_leaf(TreeLink const &link)
Return true iff the node of the given link is a leaf node.
TreeNode const * find_node(Tree const &tree, const std::string &name, bool throw_on_failure, bool replace_underscores)
Finds a Node, given its name.
void scale_all_branch_lengths(Tree &tree, double factor)
Scale all branch lengths of a Tree by a given factor.
void set_all_branch_lengths(Tree &tree, double length)
Set all branch lengths of a Tree to a given value.
size_t edge_count() const
Return the number of TreeEdges of the Tree.