Phylo/Forest/DrawNodeRole.pm

filter: Statementstmt 84.6% 44 / 52 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 80.7% 63 / 78 CC 8 SCAR 11.6
CC
8
Cov
79%
get_children
6.0
AUTOLOAD
5.1
get_first_daughter
2.1
CRAP 3.2
« Phylo/Util/CONSTANT.pm ↑ Summary Phylo/Treedrawer/Gif.pm »
1 package Bio::Phylo::Forest::DrawNodeRole;
2 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use Bio::Phylo::Forest::NodeRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use base 'Bio::Phylo::Forest::NodeRole';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 {
8  
9 34 our $AUTOLOAD;
10 34 my @properties = qw(x y radius tip_radius node_color node_outline_color
11 node_shape node_image branch_color branch_shape branch_width branch_style
12 collapsed collapsed_clade_width font_face font_size font_style font_color
13 font_weight text_horiz_offset text_vert_offset rotation clade_label
14 clade_label_font);
15  
16 =head1 NAME
17  
18 Bio::Phylo::Forest::DrawNodeRole - Tree node with extra methods for tree drawing
19  
20 =head1 SYNOPSIS
21  
22 # see Bio::Phylo::Forest::Node
23  
24 =head1 DESCRIPTION
25  
26 This module defines a node object and its methods. The node is fairly
27 syntactically rich in terms of navigation, and additional getters are provided to
28 further ease navigation from node to node. Typical first daughter -> next sister
29 traversal and recursion is possible, but there are also shrinkwrapped methods
30 that return for example all terminal descendants of the focal node, or all
31 internals, etc.
32  
33 Node objects are inserted into tree objects, although technically the tree
34 object is only a container holding all the nodes together. Unless there are
35 orphans all nodes can be reached without recourse to the tree object.
36  
37 In addition, this subclass of the default node object L<Bio::Phylo::Forest::Node>
38 has getters and setters for drawing trees and nodes, e.g. X/Y coordinates, font
39 and text attributes, etc.
40  
41 =head1 METHODS
42  
43 =head2 MUTATORS
44  
45 =over
46  
47 =item set_collapsed()
48  
49 Type : Mutator
50 Title : set_collapsed
51 Usage : $node->set_collapsed(1);
52 Function: Sets whether the node's descendants are shown as collapsed into a triangle
53 Returns : $self
54 Args : true or false value
55  
56 =item set_collapsed_clade_width()
57  
58 Sets collapsed clade width.
59  
60 Type : Mutator
61 Title : set_collapsed_clade_width
62 Usage : $node->set_collapsed_clade_width(6);
63 Function: sets the width of collapsed clade triangles relative to uncollapsed tips
64 Returns :
65 Args : Positive number
66  
67 =item set_x()
68  
69 Type : Mutator
70 Title : set_x
71 Usage : $node->set_x($x);
72 Function: Sets x
73 Returns : $self
74 Args : x
75  
76 =item set_y()
77  
78 Type : Mutator
79 Title : set_y
80 Usage : $node->set_y($y);
81 Function: Sets y
82 Returns : $self
83 Args : y
84  
85 =item set_radius()
86  
87 Type : Mutator
88 Title : set_radius
89 Usage : $node->set_radius($radius);
90 Function: Sets radius
91 Returns : $self
92 Args : radius
93  
94 =cut
95  
96 34 *set_node_radius = \&set_radius;
97 34 *get_node_radius = \&get_radius;
98  
99 =item set_tip_radius()
100  
101 Type : Mutator
102 Title : set_tip_node_radius
103 Usage : $tree->set_tip_radius($node_radius);
104 Function: Sets tip radius
105 Returns : $self
106 Args : tip radius
107  
108 =item set_node_color()
109  
110 Type : Mutator
111 Title : set_node_color
112 Usage : $node->set_node_color($node_color);
113 Function: Sets node_color
114 Returns : $self
115 Args : node_color
116  
117 =item set_node_outline_color()
118  
119 Type : Mutator
120 Title : set_node_outline_color
121 Usage : $node->set_node_outline_color($node_outline_color);
122 Function: Sets node outline color
123 Returns : $self
124 Args : node_color
125  
126 =item set_node_shape()
127  
128 Type : Mutator
129 Title : set_node_shape
130 Usage : $node->set_node_shape($node_shape);
131 Function: Sets node_shape
132 Returns : $self
133 Args : node_shape
134  
135 =item set_node_image()
136  
137 Type : Mutator
138 Title : set_node_image
139 Usage : $node->set_node_image($node_image);
140 Function: Sets node_image
141 Returns : $self
142 Args : node_image
143  
144 =item set_branch_color()
145  
146 Type : Mutator
147 Title : set_branch_color
148 Usage : $node->set_branch_color($branch_color);
149 Function: Sets branch_color
150 Returns : $self
151 Args : branch_color
152  
153 =item set_branch_shape()
154  
155 Type : Mutator
156 Title : set_branch_shape
157 Usage : $node->set_branch_shape($branch_shape);
158 Function: Sets branch_shape
159 Returns : $self
160 Args : branch_shape
161  
162 =item set_branch_width()
163  
164 Type : Mutator
165 Title : set_branch_width
166 Usage : $node->set_branch_width($branch_width);
167 Function: Sets branch width
168 Returns : $self
169 Args : branch_width
170  
171 =item set_branch_style()
172  
173 Type : Mutator
174 Title : set_branch_style
175 Usage : $node->set_branch_style($branch_style);
176 Function: Sets branch style
177 Returns : $self
178 Args : branch_style
179  
180 =item set_font_face()
181  
182 Type : Mutator
183 Title : set_font_face
184 Usage : $node->set_font_face($font_face);
185 Function: Sets font_face
186 Returns : $self
187 Args : font_face
188  
189 =item set_font_size()
190  
191 Type : Mutator
192 Title : set_font_size
193 Usage : $node->set_font_size($font_size);
194 Function: Sets font_size
195 Returns : $self
196 Args : font_size
197  
198 =item set_font_style()
199  
200 Type : Mutator
201 Title : set_font_style
202 Usage : $node->set_font_style($font_style);
203 Function: Sets font_style
204 Returns : $self
205 Args : font_style
206  
207 =item set_font_weight()
208  
209 Type : Mutator
210 Title : set_font_weight
211 Usage : $node->set_font_weight($font_weight);
212 Function: Sets font_weight
213 Returns : $self
214 Args : font_weight
215  
216 =item set_font_color()
217  
218 Type : Mutator
219 Title : set_font_color
220 Usage : $node->set_font_color($color);
221 Function: Sets font_color
222 Returns : font_color
223 Args : A color, which, depending on the underlying tree drawer, can either
224 be expressed as a word ('red'), a hex code ('#00CC00') or an rgb
225 statement ('rgb(0,255,0)')
226  
227 =item set_text_horiz_offset()
228  
229 Type : Mutator
230 Title : set_text_horiz_offset
231 Usage : $node->set_text_horiz_offset($text_horiz_offset);
232 Function: Sets text_horiz_offset
233 Returns : $self
234 Args : text_horiz_offset
235  
236 =item set_text_vert_offset()
237  
238 Type : Mutator
239 Title : set_text_vert_offset
240 Usage : $node->set_text_vert_offset($text_vert_offset);
241 Function: Sets text_vert_offset
242 Returns : $self
243 Args : text_vert_offset
244  
245 =item set_rotation()
246  
247 Type : Mutator
248 Title : set_rotation
249 Usage : $node->set_rotation($rotation);
250 Function: Sets rotation
251 Returns : $self
252 Args : rotation
253  
254 =item set_clade_label()
255  
256 Type : Mutator
257 Title : set_clade_label
258 Usage : $node->set_clade_label('Mammalia');
259 Function: Sets a label for an entire clade to be visualized outside the tree
260 Returns : $self
261 Args : string
262  
263 =item set_clade_label_font()
264  
265 Type : Mutator
266 Title : set_clade_label_font
267 Usage : $node->set_clade_label_font({ '-face' => 'Verdana' });
268 Function: Sets font properties for the clade label
269 Returns : $self
270 Args : {
271 '-face' => 'Verdana', # Arial, Times, etc.
272 '-weight' => 'bold',
273 '-style' => 'italic',
274 '-colour' => 'red',
275 }
276
277 =back
278  
279 =head2 ACCESSORS
280  
281 =over
282  
283 =item get_collapsed()
284  
285 Type : Mutator
286 Title : get_collapsed
287 Usage : something() if $node->get_collapsed();
288 Function: Gets whether the node's descendants are shown as collapsed into a triangle
289 Returns : true or false value
290 Args : NONE
291  
292 =item get_first_daughter()
293  
294 Gets invocant's first daughter.
295  
296 Type : Accessor
297 Title : get_first_daughter
298 Usage : my $f_daughter = $node->get_first_daughter;
299 Function: Retrieves a node's leftmost daughter.
300 Returns : Bio::Phylo::Forest::Node
301 Args : NONE
302  
303 =cut
304  
305 49039 ▶ sub get_first_daughter {
Subroutine get_first_daughter: called CC=2 SCAR=7.6
Pod documented
306 49039 my $self = shift;
307 49039 ▶ if ( $self->get_collapsed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_collapsed) { } 0 49039 49039
308 0 return;
309 }
310 else {
311 49039 return $self->SUPER::get_first_daughter;
312 }
313 }
314  
315 =item get_last_daughter()
316  
317 Gets invocant's last daughter.
318  
319 Type : Accessor
320 Title : get_last_daughter
321 Usage : my $l_daughter = $node->get_last_daughter;
322 Function: Retrieves a node's rightmost daughter.
323 Returns : Bio::Phylo::Forest::Node
324 Args : NONE
325  
326 =cut
327  
328 22 ▶ sub get_last_daughter {
Subroutine get_last_daughter: called CC=2 SCAR=7.6
Pod documented
329 22 my $self = shift;
330 22 ▶ if ( $self->get_collapsed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_collapsed) { } 0 22 22
331 0 return;
332 }
333 else {
334 22 return $self->SUPER::get_last_daughter;
335 }
336 }
337  
338 =item get_children()
339  
340 Gets invocant's immediate children.
341  
342 Type : Query
343 Title : get_children
344 Usage : my @children = @{ $node->get_children };
345 Function: Returns an array reference of immediate
346 descendants, ordered from left to right.
347 Returns : Array reference of
348 Bio::Phylo::Forest::Node objects.
349 Args : NONE
350  
351 =cut
352  
353 0 ▶ sub get_children {
Subroutine get_children: not called CC=2 SCAR=17.9
Pod documented
354 0 my $self = shift;
355 0 ▶ if ( $self->get_collapsed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_collapsed) { } 0 0 0
356 0 return [];
357 }
358 else {
359 0 return $self->SUPER::get_children;
360 }
361 }
362  
363 =item get_x()
364  
365 Type : Accessor
366 Title : get_x
367 Usage : my $x = $node->get_x();
368 Function: Gets x
369 Returns : x
370 Args : NONE
371  
372 =item get_y()
373  
374 Type : Accessor
375 Title : get_y
376 Usage : my $y = $node->get_y();
377 Function: Gets y
378 Returns : y
379 Args : NONE
380  
381 =item get_radius()
382  
383 Type : Accessor
384 Title : get_radius
385 Usage : my $radius = $node->get_radius();
386 Function: Gets radius
387 Returns : radius
388 Args : NONE
389  
390 =item get_node_color()
391  
392 Type : Accessor
393 Title : get_node_color
394 Usage : my $node_color = $node->get_node_color();
395 Function: Gets node_color
396 Returns : node_color
397 Args : NONE
398  
399 =item get_node_outline_color()
400  
401 Type : Accessor
402 Title : get_node_outline_color
403 Usage : my $node_outline_color = $node->get_node_outline_color();
404 Function: Gets node outline color
405 Returns : node_color
406 Args : NONE
407  
408 =item get_node_shape()
409  
410 Type : Accessor
411 Title : get_node_shape
412 Usage : my $node_shape = $node->get_node_shape();
413 Function: Gets node_shape
414 Returns : node_shape
415 Args : NONE
416  
417 =item get_node_image()
418  
419 Type : Accessor
420 Title : get_node_image
421 Usage : my $node_image = $node->get_node_image();
422 Function: Gets node_image
423 Returns : node_image
424 Args : NONE
425  
426 =item get_collapsed_clade_width()
427  
428 Gets collapsed clade width.
429  
430 Type : Mutator
431 Title : get_collapsed_clade_width
432 Usage : $w = $node->get_collapsed_clade_width();
433 Function: gets the width of collapsed clade triangles relative to uncollapsed tips
434 Returns : Positive number
435 Args : None
436  
437 =item get_branch_color()
438  
439 Type : Accessor
440 Title : get_branch_color
441 Usage : my $branch_color = $node->get_branch_color();
442 Function: Gets branch_color
443 Returns : branch_color
444 Args : NONE
445  
446 =item get_branch_shape()
447  
448 Type : Accessor
449 Title : get_branch_shape
450 Usage : my $branch_shape = $node->get_branch_shape();
451 Function: Gets branch_shape
452 Returns : branch_shape
453 Args : NONE
454  
455 =item get_branch_width()
456  
457 Type : Accessor
458 Title : get_branch_width
459 Usage : my $branch_width = $node->get_branch_width();
460 Function: Gets branch_width
461 Returns : branch_width
462 Args : NONE
463  
464 =item get_branch_style()
465  
466 Type : Accessor
467 Title : get_branch_style
468 Usage : my $branch_style = $node->get_branch_style();
469 Function: Gets branch_style
470 Returns : branch_style
471 Args : NONE
472  
473 =item get_font_face()
474  
475 Type : Accessor
476 Title : get_font_face
477 Usage : my $font_face = $node->get_font_face();
478 Function: Gets font_face
479 Returns : font_face
480 Args : NONE
481  
482 =item get_font_size()
483  
484 Type : Accessor
485 Title : get_font_size
486 Usage : my $font_size = $node->get_font_size();
487 Function: Gets font_size
488 Returns : font_size
489 Args : NONE
490  
491 =item get_font_style()
492  
493 Type : Accessor
494 Title : get_font_style
495 Usage : my $font_style = $node->get_font_style();
496 Function: Gets font_style
497 Returns : font_style
498 Args : NONE
499
500 =item get_font_weight()
501  
502 Type : Mutator
503 Title : get_font_weight
504 Usage : my $font_weight = $node->get_font_weight();
505 Function: Gets font_weight
506 Returns : font_weight
507 Args : NONE
508  
509 =item get_font_color()
510  
511 Type : Accessor
512 Title : get_font_color
513 Usage : my $color = $node->get_font_color();
514 Function: Gets font_color
515 Returns : font_color
516 Args : NONE
517  
518 =item get_text_horiz_offset()
519  
520 Type : Accessor
521 Title : get_text_horiz_offset
522 Usage : my $text_horiz_offset = $node->get_text_horiz_offset();
523 Function: Gets text_horiz_offset
524 Returns : text_horiz_offset
525 Args : NONE
526  
527 =item get_text_vert_offset()
528  
529 Type : Accessor
530 Title : get_text_vert_offset
531 Usage : my $text_vert_offset = $node->get_text_vert_offset();
532 Function: Gets text_vert_offset
533 Returns : text_vert_offset
534 Args : NONE
535  
536 =item get_rotation()
537  
538 Type : Accessor
539 Title : get_rotation
540 Usage : my $rotation = $node->get_rotation();
541 Function: Gets rotation
542 Returns : rotation
543 Args : NONE
544  
545 =item get_clade_label()
546  
547 Type : Accessor
548 Title : get_clade_label
549 Usage : my $l = $node->get_clade_label();
550 Function: Gets a label for an entire clade to be visualized outside the tree
551 Returns : string
552 Args : NONE
553  
554 =item get_clade_label_font()
555  
556 Type : Accessor
557 Title : get_clade_label_font
558 Usage : my %h = %{ $node->get_clade_label_font() };
559 Function: gets font properties for the clade label
560 Returns : undef or hashref
561 Args : NONE
562
563 =back
564  
565 =cut
566  
567 49630 ▶ sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=5 SCAR=16.3
568 49630 my $self = shift;
569 49630 my $method = $AUTOLOAD;
570 49630 $method =~ s/.+://; # strip package name
571 49630 $method =~ s/colour/color/; # map British/Canadian to American :)
572
573 # if the user calls some non-existant method, try to do the
574 # usual way, with this message, from perspective of caller
575 49630 my $template = 'Can\'t locate object method "%s" via package "%s"';
576
577 49630 ▶ if ( $method =~ /^set_(.+)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($method =~ /^set_(.+)$/) { } 126 49504 49630
elsif ($method =~ /^get_(.+)$/) { } 49503 1 49504
578 126 my $prop = $1;
579 126 ▶ if ( grep { /^\Q$prop\E$/ } @properties ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/^\Q$prop\E$/;} @properties) { } 126 0 126
580 126 my $value = shift;
581 126 return $self->set_meta_object( "map:$prop" => $value );
582 }
583 else {
584 0 croak sprintf $template, $method, __PACKAGE__;
585 }
586 }
587 elsif ( $method =~ /^get_(.+)$/ ) {
588 49503 my $prop = $1;
589 49503 ▶ if ( grep { /^\Q$prop\E$/ } @properties ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/^\Q$prop\E$/;} @properties) { } 49503 0 49503
590 49503 my $value = shift;
591 49503 return $self->get_meta_object( "map:$prop" );
592 }
593 else {
594 0 croak sprintf $template, $method, __PACKAGE__;
595 }
596 }
597 else {
598 1 croak sprintf $template, $method, __PACKAGE__;
599 }
600 }
601  
602  
603 # podinherit_insert_token
604  
605 =head1 SEE ALSO
606  
607 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
608 for any user or developer questions and discussions.
609  
610 =over
611  
612 =item L<Bio::Phylo::Forest::Node>
613  
614 This object inherits from L<Bio::Phylo::Forest::Node>, so methods
615 defined there are also applicable here.
616  
617 =item L<Bio::Phylo::Manual>
618  
619 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
620  
621 =back
622  
623 =head1 CITATION
624  
625 If you use Bio::Phylo in published research, please cite it:
626  
627 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
628 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
629 I<BMC Bioinformatics> B<12>:63.
630 L<http://dx.doi.org/10.1186/1471-2105-12-63>
631  
632 =cut
633  
634 }
635 34 1;
« Phylo/Util/CONSTANT.pm ↑ Summary Phylo/Treedrawer/Gif.pm »