Bio/Tree/TreeI.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 50.0% 2 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 23.5% 4 / 17 Podpod 100% 15 / 15 totaltotal 51.2% 40 / 78 CC 4 SCAR 8.8
CC
4
Cov
45%
height
6.0
number_nodes
3.0
get_nodes
2.0
CRAP 2.4
« Bio/Search/Result/ResultFactory.pm ↑ Summary Bio/OntologyIO.pm »
1 #
2 # BioPerl module for Bio::Tree::TreeI
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
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::TreeI - A Tree object suitable for lots of things, designed
17 originally for Phylogenetic Trees.
18  
19 =head1 SYNOPSIS
20  
21 # get a Bio::Tree::TreeI somehow
22 # like from a TreeIO
23 my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'treefile.dnd');
24 my $tree = $treeio->next_tree;
25 my @nodes = $tree->get_nodes;
26 my @leaves = $tree->get_leaf_nodes;
27 my $root = $tree->get_root_node;
28  
29 =head1 DESCRIPTION
30  
31 This object holds a pointer to the Root of a Tree which is a
32 Bio::Tree::NodeI.
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 of the bugs and their resolution. Bug reports can be submitted via
60 the web:
61  
62 https://github.com/bioperl/bioperl-live/issues
63  
64 =head1 AUTHOR - Jason Stajich
65  
66 Email jason@bioperl.org
67  
68 =head1 CONTRIBUTORS
69  
70 Aaron Mackey, amackey@virginia.edu
71 Elia Stupka, elia@fugu-sg.org
72 Sendu Bala, bix@sendu.me.uk
73  
74 =head1 APPENDIX
75  
76 The rest of the documentation details each of the object methods.
77 Internal methods are usually preceded with a _
78  
79 =cut
80  
81  
82 # Let the code begin...
83  
84  
85 package Bio::Tree::TreeI;
86 81 $Bio::Tree::TreeI::VERSION = '1.7.8';
87 81 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 81 ▶use base qw(Bio::Root::RootI);
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 =head2 get_nodes
92  
93 Title : get_nodes
94 Usage : my @nodes = $tree->get_nodes()
95 Function: Return list of Tree::NodeI objects
96 Returns : array of Tree::NodeI objects
97 Args : (named values) hash with one value
98 order => 'b|breadth' first order or 'd|depth' first order
99  
100 =cut
101  
102 0 ▶sub get_nodes{
Subroutine get_nodes: not called CC=1 SCAR=6.9
Pod documented
103 0 my ($self) = @_;
104 0 $self->throw_not_implemented();
105 }
106  
107 =head2 get_root_node
108  
109 Title : get_root_node
110 Usage : my $node = $tree->get_root_node();
111 Function: Get the Top Node in the tree, in this implementation
112 Trees only have one top node.
113 Returns : Bio::Tree::NodeI object
114 Args : none
115  
116 =cut
117  
118 0 ▶sub get_root_node{
Subroutine get_root_node: not called CC=1 SCAR=6.9
Pod documented
119 0 my ($self) = @_;
120 0 $self->throw_not_implemented();
121 }
122  
123 =head2 number_nodes
124  
125 Title : number_nodes
126 Usage : my $size = $tree->number_nodes
127 Function: Find the number of nodes in the tree.
128 Returns : int
129 Args : none
130  
131 =cut
132  
133 12 ▶sub number_nodes{
Subroutine number_nodes: called CC=3 SCAR=11.0
Pod documented
134 12 my ($self) = @_;
135 12 my $root = $self->get_root_node;
136 12 ▶ if( defined $root && $root->isa('Bio::Tree::NodeI')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $root and $root->isa("Bio::Tree::NodeI")) 10 2 12
Condition66%2/3
defined $root and $root->isa("Bio::Tree::NodeI")
!ll&&!rl&&r
2010
MC/DC50%1/2
defined $root and $root->isa("Bio::Tree::NodeI")
defined $root $root->isa("Bio::Tree::NodeI")
Truth table66%2/3
A and B
A= defined $rootB= $root->isa("Bio::Tree::NodeI")
ABresult
0X0
100
111
137 10 return ($root->descendent_count + 1);
138 }
139 2 return 0;
140 }
141  
142 =head2 total_branch_length
143  
144 Title : total_branch_length
145 Usage : my $size = $tree->total_branch_length
146 Function: Returns the sum of the length of all branches
147 Returns : integer
148 Args : none
149  
150 =cut
151  
152 0 ▶sub total_branch_length {
Subroutine total_branch_length: not called CC=1 SCAR=6.9
Pod documented
153 0 my ($self) = @_;
154 0 $self->throw_not_implemented();
155 }
156  
157 =head2 height
158  
159 Title : height
160 Usage : my $height = $tree->height
161 Function: Gets the height of tree - this LOG_2($number_nodes)
162 WARNING: this is only true for strict binary trees. The TreeIO
163 system is capable of building non-binary trees, for which this
164 method will currently return an incorrect value!!
165 Returns : integer
166 Args : none
167  
168 =cut
169  
170 0 ▶sub height{
Subroutine height: not called CC=2 SCAR=17.9
Pod documented
171 0 my ($self) = @_;
172 0 my $nodect = $self->number_nodes;
173 0 ▶ return 0 if( ! $nodect );
Branch: 1 branch
BranchTrueFalseTotal
unless $nodect 0 0 0
174 0 return log($nodect) / log(2);
175 }
176  
177 =head2 id
178  
179 Title : id
180 Usage : my $id = $tree->id();
181 Function: An id value for the tree
182 Returns : scalar
183 Args :
184  
185  
186 =cut
187  
188 0 ▶sub id{
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
189 0 my ($self,@args) = @_;
190 0 $self->throw_not_implemented();
191 }
192  
193 =head2 score
194  
195 Title : score
196 Usage : $obj->score($newval)
197 Function: Sets the associated score with this tree
198 This is a generic slot which is probably best used
199 for log likelihood or other overall tree score
200 Returns : value of score
201 Args : newvalue (optional)
202  
203  
204 =cut
205  
206 0 ▶sub score{
Subroutine score: not called CC=1 SCAR=6.9
Pod documented
207 0 my ($self,$value) = @_;
208 0 $self->throw_not_implemented();
209 }
210  
211 =head2 get_leaf_nodes
212  
213 Title : get_leaf_nodes
214 Usage : my @leaves = $tree->get_leaf_nodes()
215 Function: Returns the leaves (tips) of the tree
216 Returns : Array of Bio::Tree::NodeI objects
217 Args : none
218  
219  
220 =cut
221  
222 22 ▶sub get_leaf_nodes{
Subroutine get_leaf_nodes: called CC=1 SCAR=0.0
Pod documented
223 22 my ($self) = @_;
224 22 return grep { $_->is_Leaf() } $self->get_nodes(-sortby => 'none');
225 }
226  
227  
228 =head2 Methods for associating Tag/Values with a Tree
229  
230 These methods associate tag/value pairs with a Tree
231  
232 =head2 set_tag_value
233  
234 Title : set_tag_value
235 Usage : $tree->set_tag_value($tag,$value)
236 $tree->set_tag_value($tag,@values)
237 Function: Sets a tag value(s) to a tree. Replaces old values.
238 Returns : number of values stored for this tag
239 Args : $tag - tag name
240 $value - value to store for the tag
241  
242 =cut
243  
244 0 ▶sub set_tag_value{
Subroutine set_tag_value: not called CC=1 SCAR=6.9
Pod documented
245 0 shift->throw_not_implemented();
246 }
247  
248 =head2 add_tag_value
249  
250 Title : add_tag_value
251 Usage : $tree->add_tag_value($tag,$value)
252 Function: Adds a tag value to a tree
253 Returns : number of values stored for this tag
254 Args : $tag - tag name
255 $value - value to store for the tag
256  
257  
258 =cut
259  
260 0 ▶sub add_tag_value{
Subroutine add_tag_value: not called CC=1 SCAR=6.9
Pod documented
261 0 shift->throw_not_implemented();
262 }
263  
264 =head2 remove_tag
265  
266 Title : remove_tag
267 Usage : $tree->remove_tag($tag)
268 Function: Remove the tag and all values for this tag
269 Returns : boolean representing success (0 if tag does not exist)
270 Args : $tag - tagname to remove
271  
272  
273 =cut
274  
275 0 ▶sub remove_tag {
Subroutine remove_tag: not called CC=1 SCAR=6.9
Pod documented
276 0 shift->throw_not_implemented();
277 }
278  
279 =head2 remove_all_tags
280  
281 Title : remove_all_tags
282 Usage : $tree->remove_all_tags()
283 Function: Removes all tags
284 Returns : None
285 Args : None
286  
287  
288 =cut
289  
290 0 ▶sub remove_all_tags{
Subroutine remove_all_tags: not called CC=1 SCAR=6.9
Pod documented
291 0 shift->throw_not_implemented();
292 }
293  
294 =head2 get_all_tags
295  
296 Title : get_all_tags
297 Usage : my @tags = $tree->get_all_tags()
298 Function: Gets all the tag names for this Tree
299 Returns : Array of tagnames
300 Args : None
301  
302  
303 =cut
304  
305 0 ▶sub get_all_tags {
Subroutine get_all_tags: not called CC=1 SCAR=6.9
Pod documented
306 0 shift->throw_not_implemented();
307 }
308  
309 =head2 get_tag_values
310  
311 Title : get_tag_values
312 Usage : my @values = $tree->get_tag_values($tag)
313 Function: Gets the values for given tag ($tag)
314 Returns : Array of values or empty list if tag does not exist
315 Args : $tag - tag name
316  
317  
318 =cut
319  
320 0 ▶sub get_tag_values{
Subroutine get_tag_values: not called CC=1 SCAR=6.9
Pod documented
321 0 shift->throw_not_implemented();
322 }
323  
324 =head2 has_tag
325  
326 Title : has_tag
327 Usage : $tree->has_tag($tag)
328 Function: Boolean test if tag exists in the Tree
329 Returns : Boolean
330 Args : $tag - tagname
331  
332  
333 =cut
334  
335 0 ▶sub has_tag{
Subroutine has_tag: not called CC=1 SCAR=6.9
Pod documented
336 0 shift->throw_not_implemented();
337 }
338  
339 81 1;
« Bio/Search/Result/ResultFactory.pm ↑ Summary Bio/OntologyIO.pm »