3 CXGN::Phylo::OrgnanismTree - an object to handle SGN organism trees
7 my $tree = CXGN::Phylo::OrganismTree->new();
8 my $root = $tree->get_root();
9 my $node = $root->add_child();
10 $node->set_name("I'm a child node");
11 $node->set_link("http://solgenomics.net/");
12 my $child_node = $node->add_child();
13 $child_node->set_name("I'm a grand-child node");
14 print $tree->generate_newick();
18 This is a subcass of L<CXGN::Phylo::Tree>
24 Naama Menda (nm249@cornell.edu)
33 #use CXGN::Page::FormattingHelpers qw/tooltipped_text/;
34 use CXGN
::DB
::DBICFactory
;
35 use CXGN
::Chado
::Organism
;
36 use CXGN
::Tools
::WebImageCache
;
37 use CXGN
::Phylo
::Node
;
39 package CXGN
::Phylo
::OrganismTree
;
41 use base qw
/ CXGN::Phylo::Tree / ;
45 Synopsis: my $t = CXGN::Phylo::OrganismTree->new($schema)
46 Arguments: $schema object
47 Returns: an instance of a Tree object.
48 Side effects: creates the object and initializes some parameters.
55 my $schema = shift || die "NO SCHEMA OBJECT PROVIDED!!\n";
57 my $self = $class->SUPER::new
();
59 $self->set_schema($schema);
69 =head2 recursive_children
71 Usage: $self->recursive_children($nodes_hashref, $organism, $node, $is_root)
72 Desc: recursively add child nodes starting from root.
74 Args: $nodes_hashref (organism_id => CXGN::Chado::Organism), $organism object for your root, $node object for your root, 1 (boolean)
75 Side Effects: sets name, label, link, tooltip for nodes, highlites leaf nodes.
81 sub recursive_children
{
84 my $o= shift; #CXGN::Chado::Organism object
85 my $n = shift; # CXGN::Phylo::Node object
86 my $species_cache=shift;
89 $n->set_name($o->get_species());
90 my $orgkey ="".$o->get_organism_id()."";
91 $n->get_label()->set_link("/chado/organism.pl?organism_id=" . $o->get_organism_id());
92 my $content=$species_cache->get($orgkey);
93 $content=~ s/\?/<br\/>/g
;
94 $n->set_tooltip($n->get_name());
95 $n->set_onmouseover("javascript:showPopUp('popup','".$content."','<b>".$o->get_species()."</b>')");
96 $n->set_onmouseout("javascript:hidePopUp('popup');");
97 $n->get_label()->set_name(" ".$o->get_species());
98 $n->get_label()->set_onmouseover("javascript:showPopUp('popup','".$content."','<b>".$o->get_species()."</b>')");
99 $n->get_label()->set_onmouseout("javascript:hidePopUp('popup');");
100 $n->set_species($n->get_name());
101 $n->set_hide_label(0);
102 $n->get_label()->set_hidden(0);
104 my @cl=$n->get_children();
107 my @children = $o->get_direct_children;
108 foreach my $child (@children) {
110 if ( exists( $nodes->{$child->get_organism_id() } ) && defined( $nodes->{$child->get_organism_id()} ) ) {
112 my $new_node=$n->add_child();
113 $self->recursive_children($nodes, $child, $new_node,$species_cache);
116 if ($n->is_leaf() ) { $n->set_hilited(1) ; }
120 =head2 find_recursive_parent
122 Usage: $self->find_recursive_parent($organism, $nodes_hashref)
123 Desc: populate $nodes_hashref (organism_id=> CXGN::Chado::organism) with recursive parent organisms
125 Args: $organism object, $nodes_hashref
133 sub find_recursive_parent
{
136 my $nodes= shift; # hash ref
138 my $parent = $organism->get_parent;
140 my $id = $parent->get_organism_id();
142 if (!$nodes->{$id} ) {
143 $nodes->{$id} = $parent ;
144 $self->find_recursive_parent($parent, $nodes);
154 Usage: $self->build_tree($root_species_name, $species_hashref,$speciesinfo_cache)
155 Desc: builds an organism tree starting from $root with a list of species
156 Ret: a newick representation of the tree
157 Args: $root_species_name, $species_hashref
158 Side Effects: sets tree nodes names and lables, and renders the tree (see L<CXGN::Phylo::Renderer> )
159 calls $tree->generate_newick($root_node, 1)
167 my $root= shift; #'Solanaceae';
169 my $species_hash= shift;
170 my $species_cache= shift;
172 my $schema = $self->get_schema();
173 my $root_o = CXGN
::Chado
::Organism
->new_with_species($schema, $root);
174 my $root_o_id = $root_o->get_organism_id();
175 my $organism_link = "/chado/organism.pl?organism_id=";
180 my $root_node = $self->get_root();#CXGN::Phylo::Node->new();
183 foreach my $s (keys %$species_hash ) {
185 my $o = CXGN
::Chado
::Organism
->new_with_species($schema, $s);
187 my $organism_id = $o->get_organism_id();
188 #if ($organism_id != $species_hash->{$s} ) {
191 $nodes->{$organism_id}=$o;
192 $nodes = $self->find_recursive_parent($o, $nodes);
194 $self->d( "NO ORGANISM FOUND FOR SPECIES $s !!!!!!!!!!!\n\n");
198 $self->recursive_children( $nodes, $nodes->{$root_o_id}, $root_node , $species_cache,1) ;
200 $self->set_show_labels(1);
203 $root_node->set_name($root_o->get_species());
204 $root_node->set_link($organism_link . $root_o_id);
205 $self->set_root($root_node);
207 $self->d( "FOUND organism " . $nodes->{$root_o_id} . " root node: " . $root_node->get_name() . "\n\n");
209 my $newick= $self->generate_newick($root_node, 1);
212 $self->standard_layout();
214 my $renderer = CXGN
::Phylo
::PNG_tree_renderer
->new($self);
216 my $leaf_count= $self->get_leaf_count();
217 my $image_height = $leaf_count*20 > 120 ?
$leaf_count*20 : 120 ;
219 $self->get_layout->set_image_height($image_height);
220 $self->get_layout->set_image_width(800);
221 $self->get_layout->set_top_margin(20);
222 $self->set_renderer($renderer);
223 #$tree->get_layout->layout();
224 $self->get_renderer->render();