line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Phylo::Forest::Tree; |
2
|
30
|
|
|
30
|
|
145112
|
use strict; |
|
30
|
|
|
|
|
76
|
|
|
30
|
|
|
|
|
843
|
|
3
|
30
|
|
|
30
|
|
8537
|
use Bio::Phylo::Forest::DrawTreeRole; |
|
30
|
|
|
|
|
82
|
|
|
30
|
|
|
|
|
257
|
|
4
|
30
|
|
|
30
|
|
183
|
use base qw'Bio::Phylo::Forest::DrawTreeRole'; |
|
30
|
|
|
|
|
55
|
|
|
30
|
|
|
|
|
9329
|
|
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<Bio::Phylo::Forest::TreeRole>. |
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
|
11
|
my $self = shift; |
61
|
2
|
|
|
|
|
11
|
$rooted{ $self->get_id } = 1; |
62
|
2
|
|
|
|
|
6
|
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
|
7
|
my $self = shift; |
83
|
1
|
50
|
|
|
|
16
|
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
|
|
|
|
|
6
|
$default{ $self->get_id } = 1; |
89
|
1
|
|
|
|
|
4
|
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
|
272
|
my $self = shift; |
138
|
152
|
|
|
|
|
429
|
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
|
|
|
|
|
10
|
my $id = $self->get_id; |
163
|
3
|
100
|
|
|
|
11
|
if ( defined $rooted{$id} ) { |
164
|
2
|
|
|
|
|
8
|
return ! $rooted{$id}; |
165
|
|
|
|
|
|
|
} |
166
|
1
|
50
|
|
|
|
5
|
if ( my $root = $self->get_root ) { |
167
|
1
|
50
|
|
|
|
4
|
if ( my $children = $root->get_children ) { |
168
|
1
|
|
|
|
|
3
|
return scalar @{$children} <= 2; |
|
1
|
|
|
|
|
4
|
|
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
|
225
|
|
|
225
|
|
404
|
my $self = shift; |
178
|
225
|
50
|
|
|
|
600
|
if ( defined( my $id = $self->get_id ) ) { |
179
|
225
|
|
|
|
|
478
|
for my $field (@fields) { |
180
|
450
|
|
|
|
|
916
|
delete $field->{$id}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
30
|
|
|
30
|
|
221
|
} |
|
30
|
|
|
|
|
61
|
|
|
30
|
|
|
|
|
145
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _set_rooted : Clonable { |
186
|
2
|
|
|
2
|
|
7
|
my ( $self, $r ) = @_; |
187
|
2
|
|
|
|
|
10
|
$rooted{$self->get_id} = $r; |
188
|
2
|
|
|
|
|
8
|
return $self; |
189
|
30
|
|
|
30
|
|
7199
|
} |
|
30
|
|
|
|
|
69
|
|
|
30
|
|
|
|
|
105
|
|
190
|
|
|
|
|
|
|
|
191
|
2
|
|
|
2
|
|
12
|
sub _get_rooted { $rooted{shift->get_id} } |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _set_default : Clonable { |
194
|
2
|
|
|
2
|
|
7
|
my ( $self, $d ) = @_; |
195
|
2
|
|
|
|
|
8
|
$default{$self->get_id} = $d; |
196
|
2
|
|
|
|
|
8
|
return $self; |
197
|
30
|
|
|
30
|
|
6398
|
} |
|
30
|
|
|
|
|
59
|
|
|
30
|
|
|
|
|
107
|
|
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
2
|
|
11
|
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<https://groups.google.com/forum/#!forum/bio-phylo> |
210
|
|
|
|
|
|
|
for any user or developer questions and discussions. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item L<Bio::Phylo::Forest::TreeRole> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
The L<Bio::Phylo::Forest::Tree> package inherits from |
217
|
|
|
|
|
|
|
the L<Bio::Phylo::Forest::TreeRole> package, so the methods defined |
218
|
|
|
|
|
|
|
therein also apply to trees. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item L<Bio::Phylo::Manual> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 CITATION |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
If you use Bio::Phylo in published research, please cite it: |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> |
231
|
|
|
|
|
|
|
and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. |
232
|
|
|
|
|
|
|
I<BMC Bioinformatics> B<12>:63. |
233
|
|
|
|
|
|
|
L<http://dx.doi.org/10.1186/1471-2105-12-63> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
1; |