1 package CXGN
::Phylo
::TreePlus
;
3 use base qw
/ CXGN::Phylo::Tree /;
11 This is a subclass of Tree that has more advanced
12 functionality, such as a BayesTraits method
16 use CXGN
::Tools
::Cluster
::BayesTraits
;
20 my $self = bless {}, $class;
21 my $tree = CXGN
::Phylo
::Tree
->new(@_);
22 while(my ($k, $v) = each %$tree){
28 =head2 function calculate_bayes_traits()
30 Args: List of trait names, numerically valued attributes of leaf nodes
32 Effect: Runs a BayesTraits Cluster process on all nodes, determining
33 ancestral characteristics and setting attributes at each node
37 sub calculate_bayes_traits
{
41 my @leaves = $self->get_leaf_list();
45 foreach my $l (@leaves){
46 my $id = $l->get_name();
48 foreach my $tn (@trait_names){
49 my $v = $l->get_attribute($tn);
53 $data->{$id} = $traits;
56 my $binary_tree = $self->copy();
57 $binary_tree->make_binary();
59 my $proc = CXGN
::Tools
::Cluster
::BayesTraits
->new({
62 model
=> "continuous",
67 $proc->add_command("delta", "lambda", "kappa");
72 my $results = $proc->results();
74 while(my ($node_key, $value_hash) = each %$results){
75 my $node = $self->get_node($node_key);
76 foreach my $tn (@trait_names){
77 $node->set_attribute($tn, $value_hash->{$tn});
78 $node->set_attribute($tn . "_var", $value_hash->{$tn . "_var"});
79 $node->set_attribute("bayes_lh", $value_hash->{likelihood
});