|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
53 stack_.push_front(node);
58 stack_.push_front(std::move(node));
63 stack_.push_back(node);
68 stack_.push_back(std::move(node));
90 std::deque<NewickBrokerElement const*> parent_stack;
93 for (
auto n_itr = stack_.cbegin(); n_itr != stack_.cend(); ++n_itr) {
96 assert( n_itr->depth >= 0 );
105 while (!parent_stack.empty() && n_itr->depth <= parent_stack.back()->depth) {
106 parent_stack.pop_back();
112 if (!parent_stack.empty()) {
113 ++(parent_stack.back()->rank_);
118 parent_stack.push_back(&*n_itr);
125 for (
auto const& node : stack_) {
126 if (node.rank_ == -1) {
127 throw std::logic_error(
"NewickBroker::assign_ranks() was not called before.");
129 if (node.rank_ == 0) {
146 return stack_.size();
152 for (
auto const& node : stack_) {
153 if (node.rank_ == -1) {
154 throw std::logic_error(
"NewickBroker::assign_ranks() was not called before.");
159 max = std::max(node.rank_, max);
175 return stack_.empty();
180 return stack_.size();
189 return stack_[index];
194 return stack_[index];
199 if (index >= stack_.size()) {
200 throw std::out_of_range(
"__FUNCTION__: out_of_range");
202 return stack_[index];
207 if (index >= stack_.size()) {
208 throw std::out_of_range(
"__FUNCTION__: out_of_range");
210 return stack_[index];
215 return stack_.front();
220 return stack_.front();
225 return stack_.back();
230 return stack_.back();
239 return stack_.begin();
244 return stack_.begin();
259 return stack_.cbegin();
264 return stack_.cend();
269 return stack_.rbegin();
274 return stack_.rbegin();
279 return stack_.rend();
284 return stack_.rend();
289 return stack_.crbegin();
294 return stack_.crend();
305 for (
auto const& node : stack_) {
306 if (node.depth == -1) {
307 LOG_INFO <<
"Node with depth -1 was found.";
310 if (node.rank_ == -1) {
311 LOG_INFO <<
"NewickBroker::assign_ranks() was not called before.";
314 if (node.rank_ == 1) {
315 LOG_INFO <<
"Node with rank 1 found.";
318 if (node.depth > cur_depth + 1) {
319 LOG_INFO <<
"Node found that increases depth more than 1 compared to parent.";
322 cur_depth = node.depth;
332 for (
auto const& node : stack_) {
334 assert( node.depth != -1 );
335 for (
int i = 0; i < node.depth; ++i) {
343 for (std::string
const& v : node.values) {
348 for (std::string
const& c : node.comments) {
349 out +=
" [" + c +
"]";
353 for (std::string
const& t : node.tags) {
354 out +=
" {" + t +
"}";
358 out += (node.rank_ > 0 ?
" Rank(" +
std::to_string(node.rank_) +
")" :
"");
#define LOG_INFO
Log an info message. See genesis::utils::LoggingLevel.
std::deque< NewickBrokerElement >::iterator iterator
std::deque< NewickBrokerElement >::const_reverse_iterator const_reverse_iterator
double sum(const Histogram &h)
NewickBrokerElement & operator[](std::size_t index)
Provides index based array access to the nodes.
std::deque< NewickBrokerElement >::reverse_iterator reverse_iterator
NewickBrokerElement & top()
Returns a reference to the top node of the tree stack.
void clear()
Deletes all nodes from the broker.
long max_rank() const
Returns the highest rank of the nodes in the tree. assign_ranks() has to be called first.
iterator end()
Returns an iterator to the end of the token list.
bool validate() const
Returns true iff the tree is valid. assign_ranks() has to be called first.
void push_top(NewickBrokerElement const &node)
std::string dump() const
Return a readable string representation of the elements of the NewickBroker.
iterator begin()
Returns an iterator to the top of the stack.
const_iterator cbegin() const
Const version of begin().
const_reverse_iterator crbegin()
Const version of rbegin().
std::string to_string(GenomeLocus const &locus)
reverse_iterator rend()
Reverse version of end().
NewickBrokerElement & at(std::size_t index)
Provides index based array access to the nodes, doing a boundary check first.
size_t inner_count() const
Provides easy and fast logging functionality.
std::deque< NewickBrokerElement >::const_iterator const_iterator
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
void assign_ranks() const
Iterate over the tree and assign ranks (= number of immediate children) to all nodes.
bool empty() const
Returns whether the stack is empty.
const_reverse_iterator crend()
Const version of rend().
reverse_iterator rbegin()
Returns a reverse iterator to the nodes on the stack.
NewickBrokerElement & bottom()
Returns a reference to the bottom node of the tree stack.
void push_bottom(NewickBrokerElement const &node)
Store the information for one element of a Newick tree.
bool is_bifurcating() const
size_t leaf_count() const
Returns the number of leaf nodes in the tree. assign_ranks() has to be called first.
size_t size() const
Returns the size of the stack, i.e. the number of nodes stored in the broker.
const_iterator cend() const
Const version of end().
size_t node_count() const
Alias for size().