Bio/DB/Taxonomy/list.pm

filter: Statementstmt 81.1% 112 / 138 Branchbran 65.7% 46 / 70 Conditioncond 50.0% 20 / 40 MC/DCmcdc 20.0% 5 / 25 Subroutinesub 90.0% 9 / 10 Podpod 100% 7 / 7 totaltotal 68.6% 199 / 290 CC 55 SCAR 30.4
CC
55
Cov
72%
get_taxon
36.3
add_lineage
25.4
ancestor
11.4
CRAP 20.8
« Bio/DB/Query/WebQuery.pm ↑ Summary Bio/Root/Root.pm »
1 #
2 # BioPerl module for Bio::DB::Taxonomy::list
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
7 #
8 # Copyright Sendu Bala
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  
15 =head1 NAME
16  
17 Bio::DB::Taxonomy::list - An implementation of Bio::DB::Taxonomy
18 that accepts lists of words to build a database
19  
20 =head1 SYNOPSIS
21  
22 use Bio::DB::Taxonomy;
23  
24 my $db = Bio::DB::Taxonomy->new( -source => 'list' );
25  
26 my @ranks = ('superkingdom', 'class', 'genus', 'species');
27 my @names = ('Eukaryota', 'Mammalia', 'Homo', 'Homo sapiens');
28 $db->add_lineage(-names => \@names, -ranks => \@ranks);
29  
30 @names = ('Eukaryota', 'Mammalia', 'Mus', 'Mus musculus');
31 $db->add_lineage(-names => \@names, -ranks => \@ranks);
32  
33 =head1 DESCRIPTION
34  
35 This is an implementation which uses supplied lists of words to create a
36 database from which you can extract Bio::Taxon objects.
37  
38 =head1 TODO
39  
40 It is possible this module could do something like store the data it builds
41 up to disc. Would that be useful?
42 At any rate, this is why the module is called 'list' and not 'in_memory' or
43 similar.
44  
45 =head1 FEEDBACK
46  
47 =head2 Mailing Lists
48  
49 User feedback is an integral part of the evolution of this and other
50 Bioperl modules. Send your comments and suggestions preferably to
51 the Bioperl mailing list. Your participation is much appreciated.
52  
53 bioperl-l@bioperl.org - General discussion
54 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55  
56 =head2 Support
57  
58 Please direct usage questions or support issues to the mailing list:
59  
60 I<bioperl-l@bioperl.org>
61  
62 rather than to the module maintainer directly. Many experienced and
63 reponsive experts will be able look at the problem and quickly
64 address it. Please include a thorough description of the problem
65 with code and data examples if at all possible.
66  
67 =head2 Reporting Bugs
68  
69 Report bugs to the Bioperl bug tracking system to help us keep track
70 of the bugs and their resolution. Bug reports can be submitted via
71 the web:
72  
73 https://github.com/bioperl/bioperl-live/issues
74  
75 =head1 AUTHOR - Sendu Bala
76  
77 Email bix@sendu.me.uk
78  
79 =head1 APPENDIX
80  
81 The rest of the documentation details each of the object methods.
82 Internal methods are usually preceded with a _
83  
84 =cut
85  
86 # Let the code begin...
87  
88  
89 package Bio::DB::Taxonomy::list;
90 23 $Bio::DB::Taxonomy::list::VERSION = '1.7.8';
91 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 23 ▶use Bio::Taxon;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 23 ▶use base qw(Bio::DB::Taxonomy);
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 23 our $prefix = 'list';
97  
98  
99 =head2 new
100  
101 Title : new
102 Usage : my $obj = Bio::DB::Taxonomy::list->new();
103 Function: Builds a new Bio::DB::Taxonomy::list object
104 Returns : an instance of Bio::DB::Taxonomy::list
105 Args : optional, as per the add_lineage() method.
106  
107 =cut
108  
109 211 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
110 211 my ($class, @args) = @_;
111 211 my $self = $class->SUPER::new(@args);
112 211 my %args = @args;
113 211 delete $args{'-source'};
114  
115 211 ▶ $self->add_lineage(%args) if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 209 2 211
116
117 211 return $self;
118 }
119  
120  
121 =head2 add_lineage
122  
123 Title : add_lineage
124 Usage : my @names = ('Eukaryota', 'Mammalia', 'Homo', 'Homo sapiens');
125 my @ranks = ('superkingdom', 'class', 'genus', 'species');
126 $db->add_lineage( -names => \@names, -ranks => \@ranks );
127 Function: Add a lineage to the database, where the lineage is described by
128 a list of scientific names in the order root->leaf. The rank of each
129 name can optionally be described by supplying an additional list
130 of rank names in the same order (eg. superkingdom->species).
131 Returns : 1 for success
132 Args : -names => [] : array ref of scientific names, REQUIRED
133 -ranks => [] : array ref of rank names, same order as above, OPTIONAL
134  
135 =cut
136  
137 290 ▶sub add_lineage {
Subroutine add_lineage: called CC=23 SCAR=32.3
Pod documented
138 290 my ($self, @args) = @_;
139 290 my ($names, $ranks) = $self->_rearrange([qw (NAMES RANKS)], @args);
140 290 ▶ $self->throw("-names must be supplied and its value must be an array reference")
Branch: 1 branch
BranchTrueFalseTotal
unless $names and ref $names eq "ARRAY" 0 290 290
Condition33%1/3
$names and ref $names eq "ARRAY"
!ll&&!rl&&r
00290
MC/DC0%0/2
$names and ref $names eq "ARRAY"
$names ref $names eq "ARRAY"
Truth table33%1/3
A and B
A= $namesB= ref $names eq "ARRAY"
ABresult
0X0
100
111
141 unless $names && ref($names) eq 'ARRAY';
142  
143 290 my $names_idx = scalar @$names - 1;
144  
145 290 ▶ if ($ranks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ranks) 39 251 290
146 39 ▶ $self->throw("-ranks must be an array reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ranks eq "ARRAY" 0 39 39
147 unless ref($ranks) eq 'ARRAY';
148 39 ▶ $self->throw("The -names and -ranks lists must be of equal length")
Branch: 1 branch
BranchTrueFalseTotal
unless $names_idx == scalar @$ranks - 1 0 39 39
149 unless $names_idx == scalar @$ranks - 1;
150 }
151
152 # This is non-trivial because names are not guaranteed unique in a taxonomy,
153 # and neither are name&rank combinations. Furthermore, different name&rank
154 # combinations can actually refer to the same taxon, eg. when one time
155 # 'Homo'&'genus' is supplied, while another time 'Homo'&'no rank'.
156 #
157 # name&rank&ancestor could well be unique (or good enough 99.9999% of the
158 # time), but we have the added complication that lineages could sometimes be
159 # supplied with differing numbers of taxa. Ideally we want to realise that
160 # the first of these two lineages shares all its nodes with the second:
161 # ('Mammalia', 'Homo', 'Homo sapiens')
162 # ('Mammalia', 'Hominidae', 'Homo', 'Homo sapiens')
163 #
164 # Clearly with limited information we can't do a perfect job, but we can try
165 # and do a reasonable one. So, let's just do the trivial implementation now
166 # and see how bad it is! (assumes ranks are unique except for 'no rank')
167
168 290 my $ancestors = $self->{ancestors};
169 290 my $node_data = $self->{node_data};
170 290 my $name_to_id = $self->{name_to_id};
171 290 my $children = $self->{children};
172  
173 290 my $my_ancestor_id = '';
174 290 my @node_ids;
175 290 for my $i (0 .. $names_idx) {
176 2783 my $name = $names->[$i];
177 2783 my $rank = $ranks->[$i]; # if undef, this node has 'no rank'
178  
179 # This is a new node with a new id if we haven't seen this name before.
180 # It's also always a new node if this is the first lineage going into
181 # the db.
182 #
183 # We need to handle, however, situations in the future where we try to
184 # merge in a new lineage but we have non-unique names in the lineage
185 # and possible missing classes in some lineages, e.g.
186 # '... Anophelinae, Anopheles, Anopheles, Angusticorn, Anopheles...'
187 # merged with
188 # '... Anophelinae, Anopheles, Angusticorn, Anopheles...'),
189 # but still need the 'tree' to be correct
190  
191 # Look for a node that is consistent with this lineage
192 2783 my $node_id;
193 2783 SAME_NAMED: for my $same_id (@{$name_to_id->{$name}}) {
194  
195 # Taxa are the same if it they have the same ancestor or none
196 557 ▶ my $this_ancestor_id = $ancestors->{$same_id} || '';
Condition100%2/2
$ancestors->{$same_id} || ''
l!l
48176
MC/DC100%1/1
$ancestors->{$same_id} || ''
$ancestors->{$same_id}
Truth table100%2/2
A
A= $ancestors->{$same_id}
Aresult
11
00
197 557 ▶ if ($my_ancestor_id eq $this_ancestor_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_ancestor_id eq $this_ancestor_id) 282 275 557
198 282 $node_id = $same_id;
199 282 last SAME_NAMED;
200 }
201
202 # Compare children
203 275 ▶ next if $i >= $names_idx; # this taxon has no child
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $names_idx 52 223 275
204 223 my $my_child_name = $names->[$i + 1];
205 #while ( my ($this_child_id, undef) = each %{$children->{$same_id}} ) {
206 223 for my $this_child_id (keys %{$children->{$same_id}}) {
207 234 ▶ if ($my_child_name eq $node_data->{$this_child_id}->[0]) { # both children have same name
Branch: 1 branch
BranchTrueFalseTotal
if ($my_child_name eq $node_data->{$this_child_id}[0]) 5 229 234
208 5 ▶ if ($my_ancestor_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_ancestor_id) { } 5 0 5
209 5 my @s_ancestors;
210 5 ▶ while ($this_ancestor_id = $ancestors->{$this_ancestor_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_ancestor_id = $ancestors->{$this_ancestor_id}) 5 5 10
211 5 ▶ if ($my_ancestor_id eq $this_ancestor_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_ancestor_id eq $this_ancestor_id) 0 5 5
212 0 $my_ancestor_id = $ancestors->{$same_id};
213 0 push @node_ids, @s_ancestors, $my_ancestor_id;
214 0 $node_id = $same_id;
215 0 last SAME_NAMED;
216 }
217 5 unshift @s_ancestors, $this_ancestor_id;
218 }
219 } else {
220 # This new lineage (@$names) doesn't start at the
221 # same root as the existing lineages. Assuming
222 # '$name' corresponds to node $same_id");
223 0 $node_id = $same_id;
224 0 last SAME_NAMED;
225 }
226 }
227 }
228 }
229
230 2783 ▶ if (not defined $node_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $node_id) 2501 282 2783
231 # This is a new node. Add it to the database, using the prefix 'list'
232 # for its ID to distinguish it from the IDs from other taxonomies.
233 2501 my $next_num = ++$self->{node_ids};
234 2501 $node_id = $prefix.$next_num;
235 2501 push @{$self->{name_to_id}->{$name}}, $node_id;
236 2501 $self->{node_data}->{$node_id}->[0] = $name;
237 }
238  
239 2783 ▶ if ( (defined $rank) && (not defined $node_data->{$node_id}->[1]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rank and not defined $node_data->{$node_id}[1]) 114 2669 2783
Condition100%3/3
defined $rank and not defined $node_data->{$node_id}[1]
!ll&&!rl&&r
2553116114
MC/DC100%2/2
defined $rank and not defined $node_data->{$node_id}[1]
defined $rank not defined $node_data->{$node_id}[1]
Truth table100%3/3
A and not(B)
A= defined $rankB= not defined $node_data->{$node_id}[1]
ABresult
0X0
100
111
240 # Save rank if node in database has no rank but the current node has one
241 114 $self->{node_data}->{$node_id}->[1] = $rank;
242 }
243  
244 2783 ▶ if ($my_ancestor_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_ancestor_id) 2493 290 2783
245 2493 ▶ if ($self->{ancestors}->{$node_id} && $self->{ancestors}->{$node_id} ne $my_ancestor_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ancestors"}{$node_id} and $self->{"ancestors"}{$node_id} ne $my_ancestor_id) 0 2493 2493
Condition66%2/3
$self->{"ancestors"}{$node_id} and $self->{"ancestors"}{$node_id} ne $my_ancestor_id
!ll&&!rl&&r
22872060
MC/DC0%0/2
$self->{"ancestors"}{$node_id} and $self->{"ancestors"}{$node_id} ne $my_ancestor_id
$self->{"ancestors"}{$node_id} $self->{"ancestors"}{$node_id} ne $my_ancestor_id
Truth table66%2/3
A and B
A= $self->{"ancestors"}{$node_id}B= $self->{"ancestors"}{$node_id} ne $my_ancestor_id
ABresult
0X0
100
111
246 0 $self->throw("The lineage '".join(', ', @$names)."' and a ".
247 "previously stored lineage share a node name but have ".
248 "different ancestries for that node. Can't cope!");
249 }
250 2493 $self->{ancestors}->{$node_id} = $my_ancestor_id;
251 }
252
253 2783 $my_ancestor_id = $node_id;
254 2783 push @node_ids, $node_id;
255 }
256
257 # Go through the lineage in reverse so we can remember the children
258 290 ▶ for (my $i = $names_idx - 1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 2493 290 2783
259 2493 $self->{children}->{$node_ids[$i]}->{$node_ids[$i+1]} = undef;
260 }
261 290 return 1;
262 }
263  
264  
265 =head2 Bio::DB::Taxonomy Interface implementation
266  
267 =head2 get_num_taxa
268  
269 Title : get_num_taxa
270 Usage : my $num = $db->get_num_taxa();
271 Function: Get the number of taxa stored in the database.
272 Returns : A number
273 Args : None
274  
275 =cut
276  
277 0 ▶sub get_num_taxa {
Subroutine get_num_taxa: not called CC=2 SCAR=17.9
Pod documented
278 0 my ($self) = @_;
279 0 ▶ return $self->{node_ids} || 0;
Condition0%0/2
$self->{'node_ids'} || 0
l!l
00
MC/DC0%0/1
$self->{'node_ids'} || 0
$self->{'node_ids'}
Truth table0%0/2
A
A= $self->{'node_ids'}
Aresult
11
00
280 }
281  
282  
283 =head2 get_taxon
284  
285 Title : get_taxon
286 Usage : my $taxon = $db->get_taxon(-taxonid => $taxonid)
287 Function: Get a Bio::Taxon object from the database.
288 Returns : Bio::Taxon object
289 Args : A single value which is the ID of the taxon to retrieve
290 OR named args, as follows:
291 -taxonid => Taxonomy ID (NB: these are not NCBI taxonomy ids but
292 'list' pre-fixed ids unique to the list database).
293 OR
294 -name => String (to query by a taxonomy name). A given taxon name
295 can match different taxonomy objects. When that is the
296 case, a warning is displayed and the first matching taxon
297 is reported. See get_taxonids() to get all matching taxon
298 IDs.
299 OR
300 -names => Array ref of lineage names, like in add_lineage(). To
301 overcome the limitations of -name, you can use -names to
302 provide the full lineage of the taxon you want and get a
303 unique, unambiguous taxon object.
304  
305 =cut
306  
307 6237 ▶sub get_taxon {
Subroutine get_taxon: called CC=15 SCAR=35.9
Pod documented
308 6237 my ($self, @args) = @_;
309  
310 6237 my $taxonid;
311 6237 ▶ if (scalar @args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args == 1) { } 1959 4278 6237
312 # Argument is a taxon ID
313 1959 $taxonid = $args[0];
314 } else {
315 # Got named arguments
316 4278 my ($name, $names);
317 4278 ($taxonid, $name, $names) = $self->_rearrange([qw(TAXONID NAME NAMES)], @args);
318 4278 ▶ if ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 2 4276 4278
319 2 $names = [$name];
320 }
321 4278 ▶ if ($names) {
Branch: 1 branch
BranchTrueFalseTotal
if ($names) 2 4276 4278
322 2 $name = $names->[-1];
323  
324 2 my @taxonids = $self->get_taxonids($name);
325 2 $taxonid = $taxonids[0];
326  
327 # Use provided lineage to find correct ID amongst several matching IDs
328 2 ▶ if ( (scalar @taxonids > 1) && (scalar @$names > 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @taxonids > 1 and scalar @$names > 1) 0 2 2
Condition33%1/3
scalar @taxonids > 1 and scalar @$names > 1
!ll&&!rl&&r
200
MC/DC0%0/2
scalar @taxonids > 1 and scalar @$names > 1
scalar @taxonids > 1 scalar @$names > 1
Truth table33%1/3
A and B
A= scalar @taxonids > 1B= scalar @$names > 1
ABresult
0X0
100
111
329 0 for my $query_taxonid (@taxonids) {
330 0 my $matched = 1;
331 0 my $db_ancestor = $self->get_taxon($query_taxonid);
332 0 ▶ for (my $i = $#$names-1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
333 0 my $query_ancestor_name = $names->[$i];
334 0 $db_ancestor = $db_ancestor->ancestor;
335 0 my $db_ancestor_name = '';
336 0 ▶ if ($db_ancestor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_ancestor) 0 0 0
337 0 $db_ancestor_name = $db_ancestor->node_name;
338 }
339 0 ▶ if (not ($query_ancestor_name eq $db_ancestor_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query_ancestor_name eq $db_ancestor_name) 0 0 0
340 0 $matched = 0;
341 0 last; # done testing this taxonid
342 }
343 }
344 0 ▶ if ($matched == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matched == 1) 0 0 0
345 0 @taxonids = [$query_taxonid];
346 0 $taxonid = $query_taxonid;
347 0 last; # done testing all taxonids
348 }
349 }
350 }
351  
352 # Warn if several taxon IDs matched
353 2 ▶ if (scalar @taxonids > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @taxonids > 1) 0 2 2
354 0 ▶ $self->warn("There were multiple ids (@taxonids) matching '$name',".
Branch: 1 branch
BranchTrueFalseTotal
if scalar @taxonids > 1 0 0 0
355 " using '$taxonid'") if scalar @taxonids > 1;
356 }
357  
358 }
359 }
360
361 # Now that we have the taxon ID, retrieve the corresponding Taxon object
362 6237 my $taxon;
363 6237 my $node = $self->{node_data}->{$taxonid};
364 6237 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 6233 4 6237
365 6233 my ($sci_name, $rank) = @$node;
366 6233 $taxon = Bio::Taxon->new(
367 -name => $sci_name,
368 -object_id => $taxonid, # not an ncbi taxid, simply an object id
369 );
370  
371 6233 ▶ if ($rank) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rank) 53 6180 6233
372 53 $taxon->rank($rank);
373 }
374  
375 # we can't use -dbh or the db_handle() method ourselves or we'll go
376 # infinite on the merge attempt
377 6233 $taxon->{'db_handle'} = $self;
378
379 6233 $self->_handle_internal_id($taxon, 1);
380 }
381  
382 6237 return $taxon;
383 }
384  
385 23 *get_Taxonomy_Node = \&get_taxon;
386  
387  
388 =head2 get_taxonids
389  
390 Title : get_taxonids
391 Usage : my @taxonids = $db->get_taxonids('Homo sapiens');
392 Function: Searches for a taxonid (generated by the list module) based on a
393 query string. Note that multiple taxonids can match to the same
394 supplied name.
395 Returns : array of integer ids in list context, one of these in scalar context
396 Args : string representing taxon's name
397  
398 =cut
399  
400 216 ▶sub get_taxonids {
Subroutine get_taxonids: called CC=3 SCAR=11.1
Pod documented
401 216 my ($self, $name) = @_;
402 216 ▶ return wantarray() ? @{$self->{name_to_id}->{$name} || []} : $self->{name_to_id}->{$name}->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 216 0 216
Condition100%2/2
$self->{'name_to_id'}{$name} || []
l!l
2142
MC/DC100%1/1
$self->{'name_to_id'}{$name} || []
$self->{'name_to_id'}{$name}
Truth table100%2/2
A
A= $self->{'name_to_id'}{$name}
Aresult
11
00
403 }
404  
405 23 *get_taxonid = \&get_taxonids;
406  
407  
408 =head2 ancestor
409  
410 Title : ancestor
411 Usage : my $ancestor_taxon = $db->ancestor($taxon)
412 Function: Retrieve the full ancestor taxon of a supplied Taxon from the
413 database.
414 Returns : Bio::Taxon
415 Args : Bio::Taxon (that was retrieved from this database)
416  
417 =cut
418  
419 4063 ▶sub ancestor {
Subroutine ancestor: called CC=8 SCAR=24.3
Pod documented
420 4063 my ($self, $taxon) = @_;
421 4063 ▶ $taxon || return; # for bug 2092, or something similar to it at least: shouldn't need this!
Branch: 1 branch
BranchTrueFalseTotal
$taxon or return 4063 0 4063
422 4063 ▶ $self->throw("Must supply a Bio::Taxon") unless ref($taxon) && $taxon->isa('Bio::Taxon');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $taxon and $taxon->isa("Bio::Taxon") 0 4063 4063
Condition33%1/3
ref $taxon and $taxon->isa("Bio::Taxon")
!ll&&!rl&&r
004063
MC/DC0%0/2
ref $taxon and $taxon->isa("Bio::Taxon")
ref $taxon $taxon->isa("Bio::Taxon")
Truth table33%1/3
A and B
A= ref $taxonB= $taxon->isa("Bio::Taxon")
ABresult
0X0
100
111
423 4063 ▶ $self->throw("The supplied Taxon must belong to this database")
Branch: 1 branch
BranchTrueFalseTotal
unless $taxon->db_handle and $taxon->db_handle eq $self 0 4063 4063
Condition33%1/3
$taxon->db_handle and $taxon->db_handle eq $self
!ll&&!rl&&r
004063
MC/DC0%0/2
$taxon->db_handle and $taxon->db_handle eq $self
$taxon->db_handle $taxon->db_handle eq $self
Truth table33%1/3
A and B
A= $taxon->db_handleB= $taxon->db_handle eq $self
ABresult
0X0
100
111
424 unless $taxon->db_handle && $taxon->db_handle eq $self;
425 4063 ▶ my $id = $taxon->id || $self->throw("The supplied Taxon is missing its id!");
Condition33%1/3
$taxon->id || $self->throw('The supplied Taxon is missing its id!')
l!l&&r!l&&!r
406300
MC/DC0%0/2
$taxon->id || $self->throw('The supplied Taxon is missing its id!')
$taxon->id $self->throw('The supplied Taxon is missing its id!')
Truth table33%1/3
A || B
A= $taxon->idB= $self->throw('The supplied Taxon is missing its id!')
ABresult
1X1
011
000
426
427 4063 ▶ my $ancestor_id = $self->{ancestors}->{$id} || return;
Condition100%2/2
$self->{'ancestors'}{$id} || (return)
l!l
19342129
MC/DC100%1/1
$self->{'ancestors'}{$id} || (return)
$self->{'ancestors'}{$id}
Truth table100%2/2
A
A= $self->{'ancestors'}{$id}
Aresult
11
00
428 1934 return $self->get_taxon($ancestor_id);
429 }
430  
431  
432 =head2 each_Descendent
433  
434 Title : each_Descendent
435 Usage : my @taxa = $db->each_Descendent($taxon);
436 Function: Get all the descendents of the supplied Taxon (but not their
437 descendents, ie. not a recursive fetchall).
438 Returns : Array of Bio::Taxon objects
439 Args : Bio::Taxon (that was retrieved from this database)
440  
441 =cut
442  
443 18 ▶sub each_Descendent {
Subroutine each_Descendent: called CC=8 SCAR=23.7
Pod documented
444 18 my ($self, $taxon) = @_;
445 18 ▶ $self->throw("Must supply a Bio::Taxon") unless ref($taxon) && $taxon->isa('Bio::Taxon');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $taxon and $taxon->isa("Bio::Taxon") 0 18 18
Condition33%1/3
ref $taxon and $taxon->isa("Bio::Taxon")
!ll&&!rl&&r
0018
MC/DC0%0/2
ref $taxon and $taxon->isa("Bio::Taxon")
ref $taxon $taxon->isa("Bio::Taxon")
Truth table33%1/3
A and B
A= ref $taxonB= $taxon->isa("Bio::Taxon")
ABresult
0X0
100
111
446 18 ▶ $self->throw("The supplied Taxon must belong to this database")
Branch: 1 branch
BranchTrueFalseTotal
unless $taxon->db_handle and $taxon->db_handle eq $self 0 18 18
Condition33%1/3
$taxon->db_handle and $taxon->db_handle eq $self
!ll&&!rl&&r
0018
MC/DC0%0/2
$taxon->db_handle and $taxon->db_handle eq $self
$taxon->db_handle $taxon->db_handle eq $self
Truth table33%1/3
A and B
A= $taxon->db_handleB= $taxon->db_handle eq $self
ABresult
0X0
100
111
447 unless $taxon->db_handle && $taxon->db_handle eq $self;
448 18 ▶ my $id = $taxon->id || $self->throw("The supplied Taxon is missing its id!");
Condition33%1/3
$taxon->id || $self->throw('The supplied Taxon is missing its id!')
l!l&&r!l&&!r
1800
MC/DC0%0/2
$taxon->id || $self->throw('The supplied Taxon is missing its id!')
$taxon->id $self->throw('The supplied Taxon is missing its id!')
Truth table33%1/3
A || B
A= $taxon->idB= $self->throw('The supplied Taxon is missing its id!')
ABresult
1X1
011
000
449
450 18 my @children;
451 18 ▶ while ( my ($child_id, undef) = each %{$self->{children}->{$id}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($child_id, undef) = each %{$$self{"children"}{$id};}) 20 18 38
452 20 ▶ push @children, ($self->get_taxon($child_id) || next);
Condition50%1/2
$self->get_taxon($child_id) || (next)
l!l
200
MC/DC0%0/1
$self->get_taxon($child_id) || (next)
$self->get_taxon($child_id)
Truth table50%1/2
A
A= $self->get_taxon($child_id)
Aresult
11
00
453 }
454
455 18 return @children;
456 }
457  
458  
459 23 1;
« Bio/DB/Query/WebQuery.pm ↑ Summary Bio/Root/Root.pm »