blib/lib/Bio/Tree/Draw/Cladogram.pm

filter: Statementstmt 11.6% 29 / 248 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 8.9% 34 / 379 CC 78 SCAR 76.8
CC
78
Cov
8%
new
2970.0
print
650.0
BEGIN
1.0
CRAP 2154.1
↑ Summary
1 #
2 # BioPerl module for Cladogram
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Gabriel Valiente <valiente@lsi.upc.edu>
7 #
8 # Copyright Gabriel Valiente
9 #
10 # You may distribute this module under the same terms as Perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Tree::Draw::Cladogram - Drawing phylogenetic trees in
17 Encapsulated PostScript (EPS) format.
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tree::Draw::Cladogram;
22 use Bio::TreeIO;
23 my $treeio = Bio::TreeIO->new('-format' => 'newick',
24 '-file' => 'input.nwk');
25 my $t1 = $treeio->next_tree;
26 my $t2 = $treeio->next_tree;
27  
28 my $obj1 = Bio::Tree::Draw::Cladogram->new(-tree => $t1);
29 $obj1->print(-file => 'cladogram.eps');
30  
31 if ($t2) {
32 my $obj2 = Bio::Tree::Draw::Cladogram->new(-tree => $t1, -second => $t2);
33 $obj2->print(-file => 'tanglegram.eps');
34 }
35  
36 =head1 DESCRIPTION
37  
38 Bio::Tree::Draw::Cladogram is a Perl tool for drawing Bio::Tree::Tree
39 objects in Encapsulated PostScript (EPS) format. It can be utilized
40 both for displaying a single phylogenetic tree (a cladogram) and for
41 the comparative display of two phylogenetic trees (a tanglegram) such
42 as a gene tree and a species tree, a host tree and a parasite tree,
43 two alternative trees for the same set of taxa, or two alternative
44 trees for overlapping sets of taxa.
45  
46 Phylogenetic trees are drawn as rectangular cladograms, with
47 horizontal orientation and ancestral nodes centered over their
48 descendents. The font used for taxa is Courier at 10 pt. A single
49 Bio::Tree::Tree object is drawn with ancestors to the left and taxa
50 flushed to the right. Two Bio::Tree::Tree objects are drawn with the
51 first tree oriented left-to-right and the second tree oriented
52 right-to-left, and with corresponding taxa connected by straight lines
53 in a shade of gray. Each correspondence between a $taxon1 of the first
54 tree and a $taxon2 of the second tree is established by setting
55 $taxon1-E<gt>add_tag_value('connection',$taxon2). Thus, a taxon of the
56 first tree can be connected to more than one taxon of the second tree,
57 and vice versa.
58  
59 The branch from the parent to a child $node, as well as the child
60 label, can be colored by setting $node-E<gt>add_tag_value('Rcolor',$r),
61 $node-E<gt>add_tag_value('Gcolor',$g), and
62 $node-E<gt>add_tag_value('Bcolor',$b), where $r, $g, and $b are the
63 desired values for red, green, and blue (zero for lowest, one for
64 highest intensity).
65  
66 This is a preliminary release of Bio::Tree::Draw::Cladogram. Future
67 improvements include an option to output phylograms instead of
68 cladograms. Beware that cladograms are automatically scaled according
69 to branch lengths, but the current release has only been tested with
70 trees having unit branch lengths.
71  
72 The print method could be extended to output graphic formats other
73 than EPS, although there are many graphics conversion programs around
74 that accept EPS input. For instance, most Linux distributions include
75 epstopdf, a Perl script that together with Ghostscript, converts EPS
76 to PDF.
77  
78 =head1 FEEDBACK
79  
80 =head2 Mailing Lists
81  
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to
84 the Bioperl mailing list. Your participation is much appreciated.
85  
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
88  
89 =head2 Support
90  
91 Please direct usage questions or support issues to the mailing list:
92  
93 I<bioperl-l@bioperl.org>
94  
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
99  
100 =head2 Reporting Bugs
101  
102 Report bugs to the Bioperl bug tracking system to help us keep track
103 of the bugs and their resolution. Bug reports can be submitted via
104 the web:
105  
106 https://github.com/bioperl/bioperl-live/issues
107  
108 =head1 AUTHOR - Gabriel Valiente
109  
110 Email valiente@lsi.upc.edu
111  
112 Code for coloring branches contributed by Georgii A Bazykin
113 (gbazykin@princeton.edu).
114  
115 =head1 APPENDIX
116  
117 The rest of the documentation details each of the object methods.
118 Internal methods are usually preceded with a _
119  
120 =cut
121  
122 package Bio::Tree::Draw::Cladogram;
123 1 $Bio::Tree::Draw::Cladogram::VERSION = '1.7.3';
124 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 1 ▶use PostScript::TextBlock;
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 1 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 # The following private package variables are set by the new method
131 # and used by the print method.
132  
133 1 my %xx; # horizontal coordinate for each node
134 my %yy; # vertical coordinate for each node
135 1 my $t1; # first Bio::Tree::Tree object
136 1 my $t2; # second Bio::Tree::Tree object
137 1 my $font; # font name
138 1 my $size; # font size
139 1 my $width; # total drawing width
140 1 my $height; # total drawing height
141 1 my $xstep; # branch length in drawing
142 1 my $tip; # extra space between tip and label
143 1 my $tipwidth1; # width of longest label among $t1 taxa
144 1 my $tipwidth2; # width of longest label among $t2 taxa
145 1 my $compact; # whether or not to ignore branch lengths
146 1 my $ratio; # horizontal to vertical ratio
147 1 my $colors; # use colors to color edges
148 1 my %Rcolor; # red color for each node
149 1 my %Gcolor; # green color for each node
150 1 my %Bcolor; # blue color for each node
151 1 my $bootstrap; # Draw Bootstrap boolean
152  
153 =head2 new
154  
155 Title : new
156 Usage : my $obj = Bio::Tree::Draw::Cladogram->new();
157 Function: Builds a new Bio::Tree::Draw::Cladogram object
158 Returns : Bio::Tree::Draw::Cladogram
159 Args : -tree => Bio::Tree::Tree object
160 -second => Bio::Tree::Tree object (optional)
161 -font => font name [string] (optional)
162 -size => font size [integer] (optional)
163 -top => top margin [integer] (optional)
164 -bottom => bottom margin [integer] (optional)
165 -left => left margin [integer] (optional)
166 -right => right margin [integer] (optional)
167 -tip => extra tip space [integer] (optional)
168 -column => extra space between cladograms [integer] (optional)
169 -compact => ignore branch lengths [boolean] (optional)
170 -ratio => horizontal to vertical ratio [integer] (optional)
171 -colors => use colors to color edges [boolean] (optional)
172 -bootstrap => draw bootstrap or internal ids [boolean]
173  
174 =cut
175  
176 0 ▶sub new {
Subroutine new: not called CC=54 SCAR=80.0
Pod documented
177 0 my($class,@args) = @_;
178  
179 0 my $self = $class->SUPER::new(@args);
180 0 ($t1, $t2, $font, $size, my $top, my $bottom, my $left, my $right,
181 $tip, my $column, $compact, $ratio, $colors,$bootstrap) =
182 $self->_rearrange([qw(TREE SECOND FONT SIZE TOP BOTTOM LEFT RIGHT
183 TIP COLUMN COMPACT RATIO COLORS BOOTSTRAP)],
184 @args);
185 0 ▶ $font ||= "Helvetica-Narrow";
Condition0%0/2
$font ||= "Helvetica-Narrow"
l!l
00
MC/DC0%0/1
$font ||= "Helvetica-Narrow"
$font
Truth table0%0/2
A
A= $font
Aresult
11
00
186 0 ▶ $size ||= 12;
Condition0%0/2
$size ||= 12
l!l
00
MC/DC0%0/1
$size ||= 12
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
187 0 ▶ $top ||= 10;
Condition0%0/2
$top ||= 10
l!l
00
MC/DC0%0/1
$top ||= 10
$top
Truth table0%0/2
A
A= $top
Aresult
11
00
188 0 ▶ $bottom ||= 10;
Condition0%0/2
$bottom ||= 10
l!l
00
MC/DC0%0/1
$bottom ||= 10
$bottom
Truth table0%0/2
A
A= $bottom
Aresult
11
00
189 0 ▶ $left ||= 10;
Condition0%0/2
$left ||= 10
l!l
00
MC/DC0%0/1
$left ||= 10
$left
Truth table0%0/2
A
A= $left
Aresult
11
00
190 0 ▶ $right ||= 10;
Condition0%0/2
$right ||= 10
l!l
00
MC/DC0%0/1
$right ||= 10
$right
Truth table0%0/2
A
A= $right
Aresult
11
00
191 0 ▶ $tip ||= 5;
Condition0%0/2
$tip ||= 5
l!l
00
MC/DC0%0/1
$tip ||= 5
$tip
Truth table0%0/2
A
A= $tip
Aresult
11
00
192 0 ▶ $column ||= 60;
Condition0%0/2
$column ||= 60
l!l
00
MC/DC0%0/1
$column ||= 60
$column
Truth table0%0/2
A
A= $column
Aresult
11
00
193 0 ▶ $compact ||= 0;
Condition0%0/2
$compact ||= 0
l!l
00
MC/DC0%0/1
$compact ||= 0
$compact
Truth table0%0/2
A
A= $compact
Aresult
11
00
194 0 ▶ $ratio ||= 1 / 1.6180339887;
Condition0%0/2
$ratio ||= "0.618033988768953"
l!l
00
MC/DC0%0/1
$ratio ||= "0.618033988768953"
$ratio
Truth table0%0/2
A
A= $ratio
Aresult
11
00
195 0 ▶ $colors ||= 0;
Condition0%0/2
$colors ||= 0
l!l
00
MC/DC0%0/1
$colors ||= 0
$colors
Truth table0%0/2
A
A= $colors
Aresult
11
00
196 0 ▶ $bootstrap ||= 0;
Condition0%0/2
$bootstrap ||= 0
l!l
00
MC/DC0%0/1
$bootstrap ||= 0
$bootstrap
Truth table0%0/2
A
A= $bootstrap
Aresult
11
00
197  
198 # Roughly, a cladogram is set according to the following parameters.
199  
200 #################################
201 # # T # $top (T, top margin)
202 # +---------+ XXX # # $bottom (B, bottom margin)
203 # | # # $left (L, left margin)
204 # | # # $right (R, right margin)
205 # +----+ # # $tip (X, extra tip space)
206 # | +----+ XXXX # # $width (total drawing width)
207 # | | # # $height (total drawing height)
208 # +----+ # Y # $xstep (S, stem length)
209 # | # # $ystep (Y, space between taxa)
210 # +----+ XX # # $tiplen (string length of longest name)
211 # # B # $tipwidth (N, size of longest name)
212 #################################
213 # L S X N R #
214 #############################
215  
216 # A tanglegram is roughly set as follows. The only additional
217 # parameter is $column (C, length of connection lines between taxa
218 # of the two trees), but $tip occurs four times, and $tiplen and
219 # $tipwidth differ for the first and the second tree.
220  
221 ###########################################################
222 # #
223 # +---------+ XXX ----- XXXXXX +----+ #
224 # | | #
225 # | +----+ #
226 # +----+ | | #
227 # | +----+ XXXX ----- XXX +----+ | #
228 # | | +----+ #
229 # +----+ | #
230 # | | #
231 # +----+ XX ----- XXXX +---------+ #
232 # #
233 ###########################################################
234 # L X X C X X R #
235 ###########################################################
236  
237 # An alternative would be to let the user set $width and $height in
238 # points and to scale down everything to fit the desired
239 # dimensions. However, the final EPS can later be scaled down to any
240 # desired size anyway.
241  
242 0 my @taxa1 = $t1->get_leaf_nodes;
243 0 my $root1 = $t1->get_root_node;
244  
245 0 $tipwidth1 = 0;
246 0 foreach my $taxon (@taxa1) {
247 0 my $w = PostScript::Metrics::stringwidth($taxon->id,$font,$size);
248 0 ▶ if ($w > $tipwidth1) { $tipwidth1 = $w; }
Branch: 1 branch
BranchTrueFalseTotal
if ($w > $tipwidth1) 0 0 0
249 }
250  
251 0 my @taxa2;
252 my $root2;
253  
254 0 my $ystep = 20;
255  
256 0 ▶ if ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
257 0 @taxa2 = $t2->get_leaf_nodes;
258 0 $root2 = $t2->get_root_node;
259 0 $tipwidth2 = 0;
260 0 foreach my $taxon (@taxa2) {
261 0 my $w = PostScript::Metrics::stringwidth($taxon->id,$font,$size);
262 0 ▶ if ($w > $tipwidth2) { $tipwidth2 = $w; }
Branch: 1 branch
BranchTrueFalseTotal
if ($w > $tipwidth2) 0 0 0
263 }
264 }
265  
266 0 my $stems = $root1->height + 1;
267 0 ▶ if ($t2) { $stems += $root2->height + 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
268 0 my $labels = $tipwidth1;
269 0 ▶ if ($t2) { $labels += $tipwidth2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
270 0 $xstep = 20;
271 0 $width = $left + $stems * $xstep + $tip + $labels + $right;
272 0 ▶ if ($t2) { $width += $tip + $column + $tip + $tip; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
273 0 $height = $bottom + $ystep * (@taxa1 - 1) + $top;
274 0 ▶ if ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
275 0 ▶ if ( scalar(@taxa2) > scalar(@taxa1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @taxa2 > scalar @taxa1) 0 0 0
276 0 $height = $bottom + $ystep * (@taxa2 - 1) + $top;
277 }
278 }
279 0 my $ystep1 = $height / scalar(@taxa1);
280 0 my $ystep2;
281 0 ▶ if ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
282 0 $ystep2 = $height / scalar(@taxa2);
283 }
284  
285 0 my $x = $left + $xstep * ($root1->height + 1) + $tip;
286 0 my $y = $bottom;
287  
288 0 for my $taxon (reverse @taxa1) {
289 0 $xx{$taxon} = $x - $tip;
290 0 $yy{$taxon} = $y;
291 0 $y += $ystep1;
292 }
293 0 $x -= $xstep;
294  
295 0 my @stack;
296 my @queue; # postorder traversal
297 0 push @stack, $t1->get_root_node;
298 0 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
299 0 my $node = pop @stack;
300 0 push @queue, $node;
301 0 foreach my $child ($node->each_Descendent(-sortby => 'internal_id')) {
302 0 push @stack, $child;
303 }
304 }
305 0 @queue = reverse @queue;
306  
307 0 for my $node (@queue) {
308 0 ▶ if (!$node->is_Leaf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->is_Leaf) 0 0 0
309 0 my @children = $node->each_Descendent;
310 0 my $child = shift @children;
311 0 my $xmin = $xx{$child};
312 0 my $ymin = my $ymax = $yy{$child};
313 0 foreach $child (@children) {
314 0 ▶ $xmin = $xx{$child} if $xx{$child} < $xmin;
Branch: 1 branch
BranchTrueFalseTotal
if $xx{$child} < $xmin 0 0 0
315 0 ▶ $ymax = $yy{$child} if $yy{$child} > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} > $ymax 0 0 0
316 0 ▶ $ymin = $yy{$child} if $yy{$child} < $ymin;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} < $ymin 0 0 0
317 }
318 0 $xx{$node} = $xmin - $xstep;
319 0 $yy{$node} = ($ymin + $ymax)/2;
320 }
321 }
322  
323 0 $xx{$t1->get_root_node} = $left + $xstep;
324  
325 0 my @preorder = $t1->get_nodes(-order => 'depth');
326  
327 0 for my $node (@preorder) {
328 #print "\n$node";
329 0 ▶ if ($colors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colors) 0 0 0
330 0 ▶ if ($node->has_tag('Rcolor')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->has_tag('Rcolor')) { } 0 0 0
331 0 $Rcolor{$node} = $node->get_tag_values('Rcolor')
332 } else {
333 0 $Rcolor{$node} = 0
334 }
335 0 ▶ if ($node->has_tag('Gcolor')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->has_tag('Gcolor')) { } 0 0 0
336 0 $Gcolor{$node} = $node->get_tag_values('Gcolor')
337 } else {
338 0 $Gcolor{$node} = 0
339 }
340 0 ▶ if ($node->has_tag('Bcolor')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->has_tag('Bcolor')) { } 0 0 0
341 0 $Bcolor{$node} = $node->get_tag_values('Bcolor')
342 } else {
343 0 $Bcolor{$node} = 0
344 }
345 #print "\t$Rcolor{$node}\t$Gcolor{$node}\t$Bcolor{$node}";
346 }
347 }
348  
349 0 ▶ if ($compact) { # ragged right, ignoring branch lengths
Branch: 1 branch
BranchTrueFalseTotal
if ($compact) { } 0 0 0
350  
351 0 $width = 0;
352 0 shift @preorder; # skip root
353 0 for my $node (@preorder) {
354 0 $xx{$node} = $xx{$node->ancestor} + $xstep;
355 0 ▶ $width = $xx{$node} if $xx{$node} > $width;
Branch: 1 branch
BranchTrueFalseTotal
if $xx{$node} > $width 0 0 0
356 }
357 0 $width += $tip + $tipwidth1 + $right;
358  
359 } else { # set to aspect ratio and use branch lengths if available
360  
361 0 my $total_height = (scalar($t1->get_leaf_nodes) - 1) * $ystep;
362 0 my $scale_factor = $total_height * $ratio / $t1->get_root_node->height;
363  
364 0 $width = $t1->get_root_node->height * $scale_factor;
365 0 $width += $left + $xstep;
366 0 $width += $tip + $tipwidth1 + $right;
367  
368 0 shift @preorder; # skip root
369 0 for my $node (@preorder) {
370 0 my $bl = $node->branch_length;
371 0 ▶ $bl = 1 unless (defined $bl && $bl =~ /^\-?\d+(\.\d+)?$/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bl and $bl =~ /^\-?\d+(\.\d+)?$/ 0 0 0
Condition0%0/3
defined $bl and $bl =~ /^\-?\d+(\.\d+)?$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bl and $bl =~ /^\-?\d+(\.\d+)?$/
defined $bl $bl =~ /^\-?\d+(\.\d+)?$/
Truth table0%0/3
A and B
A= defined $blB= $bl =~ /^\-?\d+(\.\d+)?$/
ABresult
0X0
100
111
372 0 $xx{$node} = $xx{$node->ancestor} + $bl * $scale_factor;
373 }
374  
375 }
376  
377 0 ▶ if ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
378  
379 0 $x = $left + $xstep * ($root1->height + 1) + $tip;
380 0 $x += $tipwidth1 + $tip + $column + $tip;
381 0 my $y = $bottom;
382  
383 0 for my $taxon (reverse @taxa2) {
384 0 $xx{$taxon} = $x + $tipwidth2 + $tip;
385 0 $yy{$taxon} = $y;
386 0 $y += $ystep2;
387 }
388 0 $x += $xstep;
389  
390 0 my @stack;
391 my @queue; # postorder traversal
392 0 push @stack, $t2->get_root_node;
393 0 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 0 0 0
394 0 my $node = pop @stack;
395 0 push @queue, $node;
396 0 foreach my $child ($node->each_Descendent(-sortby => 'internal_id')) {
397 0 push @stack, $child;
398 }
399 }
400 0 @queue = reverse @queue;
401  
402 0 for my $node (@queue) {
403 0 ▶ if (!$node->is_Leaf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->is_Leaf) 0 0 0
404 0 my @children = $node->each_Descendent;
405 0 my $child = shift @children;
406 0 my $xmax = $xx{$child};
407 0 my $ymin = my $ymax = $yy{$child};
408 0 foreach $child (@children) {
409 0 ▶ $xmax = $xx{$child} if $xx{$child} > $xmax;
Branch: 1 branch
BranchTrueFalseTotal
if $xx{$child} > $xmax 0 0 0
410 0 ▶ $ymax = $yy{$child} if $yy{$child} > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} > $ymax 0 0 0
411 0 ▶ $ymin = $yy{$child} if $yy{$child} < $ymin;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} < $ymin 0 0 0
412 }
413 0 $xx{$node} = $xmax + $xstep;
414 0 $yy{$node} = ($ymin + $ymax)/2;
415 }
416 }
417  
418 }
419  
420 0 return $self;
421 }
422  
423 =head2 print
424  
425 Title : print
426 Usage : $obj->print();
427 Function: Outputs $obj in Encapsulated PostScript (EPS) format
428 Returns :
429 Args : -file => filename (optional)
430  
431 =cut
432  
433 0 ▶sub print {
Subroutine print: not called CC=25 SCAR=64.8
Pod documented
434 0 my($self,@args) = @_;
435  
436 0 my ($file) = $self->_rearrange([qw(FILE)], @args);
437 0 ▶ $file ||= "output.eps"; # stdout
Condition0%0/2
$file ||= "output.eps"
l!l
00
MC/DC0%0/1
$file ||= "output.eps"
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
438  
439 0 ▶ open my $INFO, '>', $file or $self->throw("Could not write file '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $INFO, ">", $file or $self->throw("Could not write file '${file}': $!") 0 0 0
440 0 print $INFO "%!PS-Adobe-\n";
441 0 print $INFO "%%BoundingBox: 0 0 ", $width, " ", $height, "\n";
442 0 print $INFO "1 setlinewidth\n";
443 0 print $INFO "/$font findfont\n";
444 0 print $INFO "$size scalefont\n";
445 0 print $INFO "setfont\n";
446  
447 # taxa labels are centered to 1/3 the font size
448  
449 0 for my $taxon (reverse $t1->get_leaf_nodes) {
450 0 ▶ if ($colors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colors) 0 0 0
451 0 print $INFO $Rcolor{$taxon}, " ", $Gcolor{$taxon}, " ", $Bcolor{$taxon}, " setrgbcolor\n";
452 }
453 0 print $INFO $xx{$taxon} + $tip, " ", $yy{$taxon} - $size / 3, " moveto\n";
454 0 print $INFO "(", $taxon->id, ") show\n";
455 }
456  
457 0 my $root1 = $t1->get_root_node;
458 0 for my $node ($t1->get_nodes) {
459 0 ▶ if ($node->ancestor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->ancestor) 0 0 0
460 # print $xx{$node->ancestor}, " ", $yy{$node->ancestor}, " moveto\n";
461 # print $xx{$node}, " ", $yy{$node}, " lineto\n";
462 0 ▶ if ($colors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colors) 0 0 0
463 0 print $INFO "stroke\n";
464 print $INFO $Rcolor{$node}, " ", $Gcolor{$node}, " ",
465 0 $Bcolor{$node}, " setrgbcolor\n";
466 }
467 0 print $INFO $xx{$node}, " ", $yy{$node}, " moveto\n";
468 0 print $INFO $xx{$node->ancestor}, " ", $yy{$node}, " lineto\n";
469 0 ▶ if( $bootstrap ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bootstrap) 0 0 0
470 0 print $INFO $xx{$node->ancestor}+ $size/10, " ", $yy{$node->ancestor} - ($size / 3), " moveto\n";
471 0 print $INFO "(", $node->ancestor->id, ") show\n";
472 0 print $INFO $xx{$node->ancestor}, " ", $yy{$node}, " moveto\n";
473 }
474 0 print $INFO $xx{$node->ancestor}, " ", $yy{$node->ancestor}, " lineto\n";
475  
476  
477 }
478 }
479 0 my $ymin = $yy{$root1};
480 0 my $ymax = $yy{$root1};
481 0 foreach my $child ($root1->each_Descendent) {
482 0 ▶ $ymax = $yy{$child} if $yy{$child} > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} > $ymax 0 0 0
483 0 ▶ $ymin = $yy{$child} if $yy{$child} < $ymin;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child} < $ymin 0 0 0
484 }
485 0 my $zz = ($ymin + $ymax)/2;
486 0 ▶ if ($colors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colors) 0 0 0
487 0 print $INFO "stroke\n";
488 0 print $INFO $Rcolor{$root1}, " ", $Gcolor{$root1}, " ", $Bcolor{$root1}, " setrgbcolor\n";
489 }
490 0 print $INFO $xx{$root1}, " ", $zz, " moveto\n";
491 0 print $INFO $xx{$root1} - $xstep, " ", $zz, " lineto\n";
492  
493 0 ▶ if ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t2) 0 0 0
494  
495 0 for my $taxon (reverse $t2->get_leaf_nodes) {
496 0 my $tiplen2 = PostScript::Metrics::stringwidth($taxon->id,$font,$size);
497 print $INFO $xx{$taxon} - $tiplen2 - $tip, " ",
498 0 $yy{$taxon} - $size / 3, " moveto\n";
499 0 printf $INFO "(%s) show\n", $taxon->id;
500 }
501  
502 0 for my $node ($t2->get_nodes) {
503 0 ▶ if ($node->ancestor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->ancestor) 0 0 0
504 0 print $INFO $xx{$node}, " ", $yy{$node}, " moveto\n";
505 0 print $INFO $xx{$node->ancestor}, " ", $yy{$node}, " lineto\n";
506 print $INFO $xx{$node->ancestor}, " ",
507 0 $yy{$node->ancestor}, " lineto\n";
508 }
509 }
510  
511 0 my $root2 = $t2->get_root_node;
512 0 my $ymin = $yy{$root2};
513 0 my $ymax = $yy{$root2};
514 0 foreach my $child2 ($root2->each_Descendent) {
515 0 ▶ $ymax = $yy{$child2} if $yy{$child2} > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child2} > $ymax 0 0 0
516 0 ▶ $ymin = $yy{$child2} if $yy{$child2} < $ymin;
Branch: 1 branch
BranchTrueFalseTotal
if $yy{$child2} < $ymin 0 0 0
517 }
518 0 my $zz = ($ymin + $ymax)/2;
519 0 print $INFO $xx{$root2}, " ", $zz, " moveto\n";
520 0 print $INFO $xx{$root2} + $xstep, " ", $zz, " lineto\n";
521  
522 0 my @taxa1 = $t1->get_leaf_nodes;
523 0 my @taxa2 = $t2->get_leaf_nodes;
524  
525 # set default connection between $t1 and $t2 taxa, unless
526 # overridden by the user (the latter not implemented yet)
527  
528 0 foreach my $taxon1 (@taxa1) {
529 0 foreach my $taxon2 (@taxa2) {
530 0 ▶ if ($taxon1->id eq $taxon2->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taxon1->id eq $taxon2->id) 0 0 0
531 0 $taxon1->add_tag_value('connection',$taxon2);
532 0 last;
533 }
534 }
535 }
536  
537 # draw connection lines between $t1 and $t2 taxa
538  
539 0 print $INFO "stroke\n";
540 0 print $INFO "0.5 setgray\n";
541  
542 0 foreach my $taxon1 (@taxa1) {
543 0 my @match = $taxon1->get_tag_values('connection');
544 0 foreach my $taxon2 (@match) {
545 0 my $x0 = $xx{$taxon1} + $tip
546 + PostScript::Metrics::stringwidth($taxon1->id,$font,$size) + $tip;
547 0 my $x1 = $xx{$taxon1} + $tip + $tipwidth1 + $tip;
548 0 my $y1 = $yy{$taxon1};
549 0 my $x2 = $xx{$taxon2} - $tip - $tipwidth2 - $tip;
550 0 my $x3 = $xx{$taxon2} - $tip
551 - PostScript::Metrics::stringwidth($taxon2->id,$font,$size) - $tip;
552 0 my $y2 = $yy{$taxon2};
553 0 print $INFO $x0, " ", $y1, " moveto\n";
554 0 print $INFO $x1, " ", $y1, " lineto\n";
555 0 print $INFO $x2, " ", $y2, " lineto\n";
556 0 print $INFO $x3, " ", $y2, " lineto\n";
557 }
558 }
559  
560 }
561  
562 0 print $INFO "stroke\n";
563 0 print $INFO "showpage\n";
564 }
565  
566 1 1;
↑ Summary