45 #include <unordered_set> 53 auto& tree = sample.
tree();
56 throw std::invalid_argument{
"Cannot root a PlacementTree that is already rooted." };
59 throw std::invalid_argument{
"The given edge does not belong to the tree." };
68 assert( &new_node.primary_link() == &target_edge.
primary_link() );
69 assert(
degree( new_node ) == 2 );
81 assert( new_edge.has_data() && new_edge.data<
PlacementEdgeData>().branch_length == 0.0 );
93 assert( ! path.empty() &&
is_root( *path.back() ));
97 std::unordered_set<PlacementTreeEdge*> edges_to_adjust;
98 for(
auto link_ptr : path ) {
99 edges_to_adjust.insert( const_cast<PlacementTreeEdge*>( &link_ptr->edge() ) );
103 for(
auto& pq : sample ) {
104 for(
auto& p : pq.placements() ) {
105 auto place_edge_ptr = &( p.edge() );
108 if ( place_edge_ptr == &target_edge ) {
109 p.reset_edge( new_edge );
114 assert( edges_to_adjust.count( place_edge_ptr ) > 0 );
115 place_edge_ptr = &( p.edge() );
116 assert( edges_to_adjust.count( place_edge_ptr ) == 0 );
120 assert( place_edge_ptr != &target_edge );
123 if( edges_to_adjust.count( place_edge_ptr ) > 0 ) {
125 p.proximal_length = full_length - p.proximal_length;
TreeEdge & edge()
Return the TreeEdge of this TreeLink.
bool is_rooted(Tree const &tree)
Return whether the Tree is rooted, that is, whether the root node has two neighbors.
Data class for PlacementTreeEdges. Stores the branch length of the edge, and the edge_num, as defined in the jplace standard.
PlacementTree & tree()
Get the PlacementTree of this Sample.
bool is_root(TreeLink const &link)
Return whether the link belongs to the root node of its Tree.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
TreeLink & next()
Return the next TreeLink within the TreeNode of this link.
std::vector< TreeLink const *> path_to_root(TreeNode const &node)
Helper function that finds all TreeLinks between a given TreeNode and the root of the Tree...
utils::Range< IteratorPath< true > > path(ElementType const &start, ElementType const &finish)
void reset_edge_nums(PlacementTree &tree)
Reset all edge nums of a PlacementTree.
void make_rooted(Sample &sample, PlacementTreeEdge &target_edge)
Root the underlying PlacementTree of a Sample at a specified TreeEdge.
bool belongs_to(Tree const &tree, TreeNode const &node)
Return whether the TreeNode belongs to the Tree, i.e., whether it is owned by the Tree...
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
TreeNode & root_node()
Return the TreeNode at the current root of the Tree.
TreeLink & primary_link()
Return the TreeLink of this TreeEdge that points towards the root.
size_t degree(TreeLink const &link)
Return the degree of the node for a given TreeLink, i.e. how many neighbouring nodes it has...
Header of PqueryPlacement class.