| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bio::Phylo::Forest::Tree; |
|
2
|
30
|
|
|
30
|
|
93031
|
use strict; |
|
|
30
|
|
|
|
|
80
|
|
|
|
30
|
|
|
|
|
909
|
|
|
3
|
30
|
|
|
30
|
|
9254
|
use Bio::Phylo::Forest::DrawTreeRole; |
|
|
30
|
|
|
|
|
120
|
|
|
|
30
|
|
|
|
|
296
|
|
|
4
|
30
|
|
|
30
|
|
195
|
use base qw'Bio::Phylo::Forest::DrawTreeRole'; |
|
|
30
|
|
|
|
|
65
|
|
|
|
30
|
|
|
|
|
10227
|
|
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
my @fields = \( my ( %default, %rooted ) ); |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Bio::Phylo::Forest::Tree - Phylogenetic tree |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# some way to get a tree |
|
15
|
|
|
|
|
|
|
use Bio::Phylo::IO; |
|
16
|
|
|
|
|
|
|
my $string = '((A,B),C);'; |
|
17
|
|
|
|
|
|
|
my $forest = Bio::Phylo::IO->parse( |
|
18
|
|
|
|
|
|
|
-format => 'newick', |
|
19
|
|
|
|
|
|
|
-string => $string |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
my $tree = $forest->first; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# do something: |
|
24
|
|
|
|
|
|
|
print $tree->calc_imbalance; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# prints "1" |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
The package has the getters and setters that alter the |
|
31
|
|
|
|
|
|
|
internal state of a tree object. Additional tree-related |
|
32
|
|
|
|
|
|
|
behaviours (which are available also) are defined in the |
|
33
|
|
|
|
|
|
|
package L. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 MUTATORS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item set_as_unrooted() |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Sets tree to be interpreted as unrooted. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Type : Mutator |
|
46
|
|
|
|
|
|
|
Title : set_as_unrooted |
|
47
|
|
|
|
|
|
|
Usage : $tree->set_as_unrooted; |
|
48
|
|
|
|
|
|
|
Function: Sets tree to be interpreted as unrooted. |
|
49
|
|
|
|
|
|
|
Returns : $tree |
|
50
|
|
|
|
|
|
|
Args : NONE |
|
51
|
|
|
|
|
|
|
Comments: This is a flag to indicate that the invocant |
|
52
|
|
|
|
|
|
|
is interpreted to be unrooted (regardless of |
|
53
|
|
|
|
|
|
|
topology). The object is otherwise unaltered, |
|
54
|
|
|
|
|
|
|
this method is only here to capture things such |
|
55
|
|
|
|
|
|
|
as the [&U] token in nexus files. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_as_unrooted { |
|
60
|
2
|
|
|
2
|
1
|
8
|
my $self = shift; |
|
61
|
2
|
|
|
|
|
7
|
$rooted{ $self->get_id } = 1; |
|
62
|
2
|
|
|
|
|
5
|
return $self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item set_as_default() |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Sets tree to be the default tree in a forest |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Type : Mutator |
|
70
|
|
|
|
|
|
|
Title : set_as_default |
|
71
|
|
|
|
|
|
|
Usage : $tree->set_as_default; |
|
72
|
|
|
|
|
|
|
Function: Sets tree to be default tree in forest |
|
73
|
|
|
|
|
|
|
Returns : $tree |
|
74
|
|
|
|
|
|
|
Args : NONE |
|
75
|
|
|
|
|
|
|
Comments: This is a flag to indicate that the invocant |
|
76
|
|
|
|
|
|
|
is the default tree in a forest, i.e. to |
|
77
|
|
|
|
|
|
|
capture the '*' token in nexus files. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_as_default { |
|
82
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
|
83
|
1
|
50
|
|
|
|
8
|
if ( my $forest = $self->_get_container ) { |
|
84
|
0
|
0
|
|
|
|
0
|
if ( my $tree = $forest->get_default_tree ) { |
|
85
|
0
|
|
|
|
|
0
|
$tree->set_not_default; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
1
|
|
|
|
|
3
|
$default{ $self->get_id } = 1; |
|
89
|
1
|
|
|
|
|
2
|
return $self; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item set_not_default() |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Sets tree to NOT be the default tree in a forest |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Type : Mutator |
|
97
|
|
|
|
|
|
|
Title : set_not_default |
|
98
|
|
|
|
|
|
|
Usage : $tree->set_not_default; |
|
99
|
|
|
|
|
|
|
Function: Sets tree to not be default tree in forest |
|
100
|
|
|
|
|
|
|
Returns : $tree |
|
101
|
|
|
|
|
|
|
Args : NONE |
|
102
|
|
|
|
|
|
|
Comments: This is a flag to indicate that the invocant |
|
103
|
|
|
|
|
|
|
is the default tree in a forest, i.e. to |
|
104
|
|
|
|
|
|
|
capture the '*' token in nexus files. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub set_not_default { |
|
109
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
110
|
0
|
|
|
|
|
0
|
$default{ $self->get_id } = 0; |
|
111
|
0
|
|
|
|
|
0
|
return $self; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 TESTS |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item is_default() |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Test if tree is default tree. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Type : Test |
|
125
|
|
|
|
|
|
|
Title : is_default |
|
126
|
|
|
|
|
|
|
Usage : if ( $tree->is_default ) { |
|
127
|
|
|
|
|
|
|
# do something |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
Function: Tests whether the invocant |
|
130
|
|
|
|
|
|
|
object is the default tree in the forest. |
|
131
|
|
|
|
|
|
|
Returns : BOOLEAN |
|
132
|
|
|
|
|
|
|
Args : NONE |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub is_default { |
|
137
|
152
|
|
|
152
|
1
|
299
|
my $self = shift; |
|
138
|
152
|
|
|
|
|
494
|
return !!$default{ $self->get_id }; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item is_rooted() |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Test if tree is rooted. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Type : Test |
|
146
|
|
|
|
|
|
|
Title : is_rooted |
|
147
|
|
|
|
|
|
|
Usage : if ( $tree->is_rooted ) { |
|
148
|
|
|
|
|
|
|
# do something |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
Function: Tests whether the invocant |
|
151
|
|
|
|
|
|
|
object is rooted. |
|
152
|
|
|
|
|
|
|
Returns : BOOLEAN |
|
153
|
|
|
|
|
|
|
Args : NONE |
|
154
|
|
|
|
|
|
|
Comments: A tree is considered unrooted if: |
|
155
|
|
|
|
|
|
|
- set_as_unrooted has been set, or |
|
156
|
|
|
|
|
|
|
- the basal split is a polytomy |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub is_rooted { |
|
161
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
162
|
3
|
|
|
|
|
11
|
my $id = $self->get_id; |
|
163
|
3
|
100
|
|
|
|
12
|
if ( defined $rooted{$id} ) { |
|
164
|
2
|
|
|
|
|
7
|
return ! $rooted{$id}; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
1
|
50
|
|
|
|
7
|
if ( my $root = $self->get_root ) { |
|
167
|
1
|
50
|
|
|
|
4
|
if ( my $children = $root->get_children ) { |
|
168
|
1
|
|
|
|
|
4
|
return scalar @{$children} <= 2; |
|
|
1
|
|
|
|
|
12
|
|
|
169
|
|
|
|
|
|
|
} |
|
170
|
0
|
|
|
|
|
0
|
return 1; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
0
|
|
|
|
|
0
|
return 0; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# the following methods are purely for internal consumption |
|
176
|
|
|
|
|
|
|
sub _cleanup : Destructor { |
|
177
|
180
|
|
|
180
|
|
404
|
my $self = shift; |
|
178
|
180
|
50
|
|
|
|
627
|
if ( defined( my $id = $self->get_id ) ) { |
|
179
|
180
|
|
|
|
|
462
|
for my $field (@fields) { |
|
180
|
360
|
|
|
|
|
916
|
delete $field->{$id}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
} |
|
183
|
30
|
|
|
30
|
|
236
|
} |
|
|
30
|
|
|
|
|
74
|
|
|
|
30
|
|
|
|
|
187
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _set_rooted : Clonable { |
|
186
|
2
|
|
|
2
|
|
5
|
my ( $self, $r ) = @_; |
|
187
|
2
|
|
|
|
|
4
|
$rooted{$self->get_id} = $r; |
|
188
|
2
|
|
|
|
|
4
|
return $self; |
|
189
|
30
|
|
|
30
|
|
7899
|
} |
|
|
30
|
|
|
|
|
64
|
|
|
|
30
|
|
|
|
|
119
|
|
|
190
|
|
|
|
|
|
|
|
|
191
|
2
|
|
|
2
|
|
5
|
sub _get_rooted { $rooted{shift->get_id} } |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _set_default : Clonable { |
|
194
|
2
|
|
|
2
|
|
4
|
my ( $self, $d ) = @_; |
|
195
|
2
|
|
|
|
|
5
|
$default{$self->get_id} = $d; |
|
196
|
2
|
|
|
|
|
5
|
return $self; |
|
197
|
30
|
|
|
30
|
|
6759
|
} |
|
|
30
|
|
|
|
|
64
|
|
|
|
30
|
|
|
|
|
114
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
2
|
|
|
2
|
|
5
|
sub _get_default { $default{shift->get_id} } |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# podinherit_insert_token |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
There is a mailing list at L |
|
210
|
|
|
|
|
|
|
for any user or developer questions and discussions. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item L |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
The L package inherits from |
|
217
|
|
|
|
|
|
|
the L package, so the methods defined |
|
218
|
|
|
|
|
|
|
therein also apply to trees. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item L |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Also see the manual: L and L. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 CITATION |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
If you use Bio::Phylo in published research, please cite it: |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
B, B, B, B |
|
231
|
|
|
|
|
|
|
and B, 2011. Bio::Phylo - phyloinformatic analysis using Perl. |
|
232
|
|
|
|
|
|
|
I B<12>:63. |
|
233
|
|
|
|
|
|
|
L |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
1; |