Exemplo n.º 1
0
/** Execute function */
RevPtr<RevVariable> Func_mapTree::execute( void )
{
    
    // get the x% hpd
    double x = 0.95;
    
    const TraceTree& tt = static_cast<const TraceTree&>( args[0].getVariable()->getRevObject() );
    const std::string& filename = static_cast<const RlString&>( args[1].getVariable()->getRevObject() ).getValue();
    int burnin = static_cast<const Integer &>(args[2].getVariable()->getRevObject()).getValue();
    
    RevBayesCore::TreeSummary summary = RevBayesCore::TreeSummary( tt.getValue() );

    // set the burnin
    summary.setBurnin( burnin );
    
    RevBayesCore::Tree* tree = summary.map( tt.getValue().isClock() );
    
    // get the tree with x% HPD node ages
    summary.annotateHPDAges(*tree, x );
    
    // get the tree with x% HPD node ages
    summary.annotate(*tree);
    
    
    if ( filename != "" )
    {
        
        RevBayesCore::NexusWriter writer(filename);
        writer.openStream();
        
        std::vector<RevBayesCore::Taxon> taxa;
        tree->getRoot().getTaxa(taxa);
        RevBayesCore::Clade c( taxa );
        writer.writeNexusBlock(c);
        
        writer.writeNexusBlock(*tree);
        
        writer.closeStream();
        
    }
    
    return new RevVariable( new Tree( tree ) );
}
Exemplo n.º 2
0
bool Tree::hasSameTopology(const RevBayesCore::Tree &t) const {
    
    return hasSameTopology( t.getTopology() );
}
Exemplo n.º 3
0
/** Execute function */
RevPtr<RevVariable> Func_annotateTree::execute( void )
{
    size_t arg_index = 0;

    // get the input tree
    RevBayesCore::Tree* tree = static_cast<const Tree&>( this->args[arg_index++].getVariable()->getRevObject() ).getValue().clone();

    // get the  tree trace
    TraceTree& tt = static_cast<TraceTree&>( args[arg_index++].getVariable()->getRevObject() );

    // get the filename
    const std::string& filename = static_cast<const RlString&>( args[arg_index++].getVariable()->getRevObject() ).getValue();


    RevBayesCore::AnnotationReport report;

    report.ages      = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();
    report.cc_ages   = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();
    report.ccp       = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();
    report.tree_ages = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();
    report.hpd       = static_cast<const Probability &>(args[arg_index++].getVariable()->getRevObject()).getValue();
    report.mean      = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();
    report.sa        = static_cast<const RlBoolean &>( this->args[arg_index++].getVariable()->getRevObject() ).getValue();

//
//    // get burnin
//    int burnin = static_cast<const Integer &>(args[arg_index++].getVariable()->getRevObject()).getValue();

    // do not make a new tree summary object
    // this way we don't need to resummarize every time we annotate a tree
    // RevBayesCore::TreeSummary summary = RevBayesCore::TreeSummary( tt.getValue() );

    bool verbose = true;
    tt.getValue().annotateTree( *tree, report, verbose );

    // return the tree
    if ( filename != "" )
    {

        RevBayesCore::NexusWriter writer(filename);
        writer.openStream(false);

        std::vector<RevBayesCore::Taxon> taxa;
        tree->getRoot().getTaxa(taxa);
        RevBayesCore::Clade c( taxa );
        writer.writeNexusBlock(c);

        writer.writeNexusBlock(*tree);

        writer.closeStream();

    }

    Tree* t;
    if( tt.getValue().getTreeTrace().isClock() )
    {
        t = new TimeTree( tree );
    }
    else
    {
        t = new BranchLengthTree( tree );
    }

    return new RevVariable( t );
}