Exemplo n.º 1
0
void Func_simTree::simulateBalancedTree( size_t n, std::vector<RevBayesCore::TopologyNode*> &nodes )
{
    
    // check if the number of taxa is divideable by two
    size_t half = n / 2;
    if ( (half+half) != n )
    {
        throw RbException("Bad number of taxa.");
    }
    
    std::vector<RevBayesCore::TopologyNode*> children;
    for (size_t i = 0; i < nodes.size(); ++i)
    {
        RevBayesCore::TopologyNode *parent = nodes[i];
        
        // add a left child
        RevBayesCore::TopologyNode* leftChild = new RevBayesCore::TopologyNode(0);
        parent->addChild(leftChild);
        leftChild->setParent(parent);
        children.push_back(leftChild);
        
        // add a right child
        RevBayesCore::TopologyNode* rightChild = new RevBayesCore::TopologyNode(0);
        parent->addChild(rightChild);
        rightChild->setParent(parent);
        children.push_back(rightChild);
        
    }
    
    if ( half == 1 )
    {
        // we are done with the recursion
        for (size_t i = 0; i < children.size(); ++i)
        {
            RevBayesCore::TopologyNode *node = children[i];
            std::string name = "Taxon_" + StringUtilities::to_string(i+1);
            node->setName(name);
        }
        
    }
    else
    {
        simulateBalancedTree(half, children);
    }
    
}
Exemplo n.º 2
0
void BranchLengthTree::reverseParentChild(RevBayesCore::TopologyNode &n)
{
    
    if ( !n.isRoot() )
    {
        TopologyNode &p = n.getParent();
        reverseParentChild( p );
        p.removeChild( &n );
        p.setParent( &n );
        n.addChild( &p );
		
		// swap branch lengths
		double parent_branch_length = branchLengths[p.getIndex()];
		double child_branch_length = branchLengths[n.getIndex()];
		branchLengths[p.getIndex()] = child_branch_length;
		branchLengths[n.getIndex()] = parent_branch_length;
    }

}