Bio/Species.pm

filter: Statementstmt 73.7% 143 / 194 Branchbran 65.9% 62 / 94 Conditioncond 60.4% 29 / 48 MC/DCmcdc 29.6% 8 / 27 Subroutinesub 51.1% 23 / 45 Podpod 44.7% 17 / 38 totaltotal 63.2% 282 / 446 CC 67 SCAR 24.2
CC
67
Cov
70%
species
32.2
validate_species_name
20.0
classification
15.3
CRAP 11.2
« Bio/Search/Result/CrossMatchResult.pm ↑ Summary Bio/TreeIO/phyloxml.pm »
1 #
2 # BioPerl module for Bio::Species
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by James Gilbert <jgrg@sanger.ac.uk>
7 # Reimplemented by Sendu Bala <bix@sendu.me.uk>
8 # Re-reimplemented by Chris Fields <cjfields - at - bioperl dot org>
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::Species - Generic species object.
17  
18 =head1 SYNOPSIS
19  
20 $species = Bio::Species->new(-classification => [@classification]);
21 # Can also pass classification
22 # array to new as below
23  
24 $species->classification(qw( sapiens Homo Hominidae
25 Catarrhini Primates Eutheria
26 Mammalia Vertebrata Chordata
27 Metazoa Eukaryota ));
28  
29 $genus = $species->genus();
30  
31 $bi = $species->binomial(); # $bi is now "Homo sapiens"
32  
33 # For storing common name
34 $species->common_name("human");
35  
36 # For storing subspecies
37 $species->sub_species("accountant");
38  
39 =head1 DESCRIPTION
40  
41 B<NOTE: This class is planned for deprecation in favor of the simpler Bio::Taxon.
42 Please use that class instead.>
43  
44 Provides a very simple object for storing phylogenetic information. The
45 classification is stored in an array, which is a list of nodes in a phylogenetic
46 tree. Access to getting and setting species and genus is provided, but not to
47 any of the other node types (eg: "phylum", "class", "order", "family"). There's
48 plenty of scope for making the model more sophisticated, if this is ever needed.
49  
50 A methods are also provided for storing common names, and subspecies.
51  
52 =head1 FEEDBACK
53  
54 =head2 Mailing Lists
55  
56 User feedback is an integral part of the evolution of this and other
57 Bioperl modules. Send your comments and suggestions preferably to
58 the Bioperl mailing list. Your participation is much appreciated.
59  
60 bioperl-l@bioperl.org - General discussion
61 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
62  
63 =head2 Support
64  
65 Please direct usage questions or support issues to the mailing list:
66  
67 I<bioperl-l@bioperl.org>
68  
69 rather than to the module maintainer directly. Many experienced and
70 reponsive experts will be able look at the problem and quickly
71 address it. Please include a thorough description of the problem
72 with code and data examples if at all possible.
73  
74 =head2 Reporting Bugs
75  
76 Report bugs to the Bioperl bug tracking system to help us keep track
77 of the bugs and their resolution. Bug reports can be submitted via the
78 web:
79  
80 https://github.com/bioperl/bioperl-live/issues
81  
82 =head1 AUTHOR
83  
84 James Gilbert email B<jgrg@sanger.ac.uk>
85  
86 =head1 CONTRIBUTORS
87  
88 Sendu Bala, bix@sendu.me.uk
89 Chris Fields, cjfields at bioperl dot org
90  
91 =head1 APPENDIX
92  
93 The rest of the documentation details each of the object
94 methods. Internal methods are usually preceded with a _
95  
96 =cut
97  
98 #' Let the code begin...
99  
100 package Bio::Species;
101 41 $Bio::Species::VERSION = '1.7.8';
102 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 41 ▶use Bio::DB::Taxonomy;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 41 ▶use Bio::Tree::Tree;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 41 ▶use Bio::Taxon;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 41 ▶use base qw(Bio::Root::Root Bio::Tree::NodeI);
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 =head2 new
111  
112 Title : new
113 Usage : my $obj = Bio::Species->new(-classification => \@class)
114 Function: Build a new Species object
115 Returns : Bio::Species object
116 Args : -ncbi_taxid => NCBI taxonomic ID (optional)
117 -classification => arrayref of classification
118  
119 =cut
120  
121 210 ▶sub new {
Subroutine new: called CC=7 SCAR=19.7
Pod documented
122 210 my($class, @args) = @_;
123
124 210 my $self = $class->SUPER::new(@args);
125
126 # Bio::Species is now just a proxy object that just observes the NodeI
127 # interface methods but delegates them to the proper classes (Bio::Taxon and
128 # Bio::Tree::Tree). This will be surplanted by the much simpler
129 # Bio::Taxon/Bio::DB::Taxonomy modules in the future.
130
131 # Using a proxy allows proper GC w/o using weaken(). This just wraps the
132 # older instances, which have no reciprocal refs (thus no circular refs).
133 # This can then run proper cleanup
134
135 210 $self->taxon(Bio::Taxon->new(@args));
136
137 210 my ($org, $sp, $var, $classification) =
138 $self->_rearrange([qw(ORGANELLE
139 SUB_SPECIES
140 VARIANT
141 CLASSIFICATION)], @args);
142
143 210 ▶ if (defined $classification && ref($classification) eq "ARRAY" && @{$classification}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $classification and ref $classification eq 'ARRAY' and @{$classification;}) { } 13 197 210
Condition66%4/6
defined $classification and ref $classification eq "ARRAY" and @{$classification;}
!ll&&!rl&&r
197013
defined $classification and ref $classification eq "ARRAY"
!ll&&!rl&&r
197013
MC/DC33%1/3
defined $classification and ref $classification eq "ARRAY" and @{$classification;}
defined $classification ref $classification eq "ARRAY" @{$classification;}
Truth table50%2/4
A and B and C
A= defined $classificationB= ref $classification eq "ARRAY"C= @{$classification;}
ABCresult
0XX0
10X0
1100
1111
144 13 $self->classification(@$classification);
145 }
146 else {
147 197 $self->tree(Bio::Tree::Tree->new());
148 }
149
150 210 ▶ defined $org && $self->organelle($org);
Branch: 1 branch
BranchTrueFalseTotal
defined $org and $self->organelle($org) 0 210 210
151 210 ▶ defined $sp && $self->sub_species($sp);
Branch: 1 branch
BranchTrueFalseTotal
defined $sp and $self->sub_species($sp) 2 208 210
152 210 ▶ defined $var && $self->variant($var);
Branch: 1 branch
BranchTrueFalseTotal
defined $var and $self->variant($var) 0 210 210
153
154 210 return $self;
155 }
156  
157 =head2 classification
158  
159 Title : classification
160 Usage : $self->classification(@class_array);
161 @classification = $self->classification();
162 Function: Get/set the lineage of this species. The array provided must be in
163 the order ... ---> SPECIES, GENUS ---> KINGDOM ---> etc.
164 Example : $obj->classification(qw( 'Homo sapiens' Homo Hominidae
165 Catarrhini Primates Eutheria Mammalia Vertebrata
166 Chordata Metazoa Eukaryota));
167 Returns : Classification array
168 Args : Classification array
169 OR
170 A reference to the classification array. In the latter case
171 if there is a second argument and it evaluates to true,
172 names will not be validated. NB: in any case, names are never
173 validated anyway.
174  
175 =cut
176  
177 259 ▶sub classification {
Subroutine classification: called CC=13 SCAR=27.3
Pod documented
178 259 my ($self, @vals) = @_;
179  
180 259 my $taxon = $self->taxon;
181  
182 259 ▶ if (@vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 209 50 259
183 209 ▶ if (ref($vals[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vals[0] eq "ARRAY") 2 207 209
184 2 @vals = @{$vals[0]};
185 }
186
187 209 ▶ $vals[1] ||= '';
Condition100%2/2
$vals[1] ||= ""
l!l
2072
MC/DC100%1/1
$vals[1] ||= ""
$vals[1]
Truth table100%2/2
A
A= $vals[1]
Aresult
11
00
188 # make sure the lineage contains us as first or second element
189 # (lineage may have subspecies, species, genus ...)
190 209 my $name = $taxon->node_name;
191 209 my ($genus, $species) = (quotemeta($vals[1]), quotemeta($vals[0]));
192 209 ▶ if ($name &&
Branch: 1 branch
BranchTrueFalseTotal
if ($name and not $name =~ /$species/i || $name =~ /$genus/i and not $name =~ /$genus $species/i) 0 209 209
Condition44%4/9
$name and not $name =~ /$species/i || $name =~ /$genus/i and not $name =~ /$genus $species/i
!ll&&!rl&&r
20900
$name and not $name =~ /$species/i || $name =~ /$genus/i
!ll&&!rl&&r
171920
$name =~ /$species/i || $name =~ /$genus/i
l!l&&r!l&&!r
19200
MC/DC0%0/4
$name and not $name =~ /$species/i || $name =~ /$genus/i and not $name =~ /$genus $species/i
$name $name =~ /$species/i $name =~ /$genus/i not $name =~ /$genus $species/i
Truth table40%2/5
A and not(B || C) and not(D)
A= $nameB= $name =~ /$species/iC= $name =~ /$genus/iD= not $name =~ /$genus $species/i
ABCDresult
0XXX0
11XX0
101X0
10000
10011
193 ($name !~ m{$species}i && $name !~ m{$genus}i) &&
194 $name !~ m{$genus $species}i) {
195 0 ▶ if ($name =~ /^$genus $species\s*(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^$genus $species\s*(.+)/) { } 0 0 0
196 # just assume the problem is someone tried to make a Bio::Species starting at subspecies
197 #*** no idea if this is appropriate! just a possible fix related to bug 2092
198 0 $self->sub_species($1);
199 0 $name = $taxon->node_name("$vals[1] $vals[0]");
200 }
201 else {
202 0 $self->warn("The supplied lineage does not start near '$name' (I was supplied '".join(" | ", @vals)."')");
203 }
204 }
205
206 # create a lineage for ourselves
207 209 my $db = Bio::DB::Taxonomy->new(-source => 'list', -names => [reverse @vals]);
208 209 ▶ unless ($taxon->scientific_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($taxon->scientific_name) 17 192 209
209 # assume we're supposed to be the leaf of the supplied lineage
210 17 $self->taxon->scientific_name($vals[0]);
211 }
212 209 ▶ unless ($taxon->rank) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($taxon->rank) 207 2 209
213 # and that we are rank species
214 207 $taxon->rank('species');
215 }
216
217 209 $taxon->db_handle($db);
218
219 209 $self->tree(Bio::Tree::Tree->new(-node => $taxon));
220 }
221
222 259 @vals = ();
223 259 foreach my $node ($self->tree->get_lineage_nodes($taxon), $taxon) {
224 2586 ▶ unshift(@vals, $node->scientific_name || next);
Condition100%2/2
$node->scientific_name || (next)
l!l
25842
MC/DC100%1/1
$node->scientific_name || (next)
$node->scientific_name
Truth table100%2/2
A
A= $node->scientific_name
Aresult
11
00
225 }
226 259 return @vals;
227 }
228  
229 =head2 ncbi_taxid
230  
231 Title : ncbi_taxid
232 Usage : $obj->ncbi_taxid($newval)
233 Function: Get/set the NCBI Taxon ID
234 Returns : the NCBI Taxon ID as a string
235 Args : newvalue to set or undef to unset (optional)
236  
237 =cut
238  
239 =head2 common_name
240  
241 Title : common_name
242 Usage : $self->common_name( $common_name );
243 $common_name = $self->common_name();
244 Function: Get or set the common name of the species
245 Example : $self->common_name('human')
246 Returns : The common name in a string
247 Args : String, which is the common name (optional)
248  
249 =cut
250  
251 =head2 division
252  
253 Title : division
254 Usage : $obj->division($newval)
255 Function: Genbank Division for a species
256 Returns : value of division (a scalar)
257 Args : value of division (a scalar)
258  
259 =cut
260  
261 =head2 species
262  
263 Title : species
264 Usage : $self->species( $species );
265 $species = $self->species();
266 Function: Get or set the species name.
267 Note that this is NOT genus and species
268 -- use $self->binomial() for that.
269 Example : $self->species('sapiens');
270 Returns : species name as string (NOT genus and species)
271 Args : species name as string (NOT genus and species)
272  
273 =cut
274  
275 94 ▶sub species {
Subroutine species: called CC=21 SCAR=34.7
Pod documented
276 94 my ($self, $species) = @_;
277
278 94 ▶ if ($species) {
Branch: 1 branch
BranchTrueFalseTotal
if ($species) 9 85 94
279 9 $self->{_species} = $species;
280 }
281  
282 94 ▶ unless (defined $self->{_species}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_species"}) 44 50 94
283 # work it out from our nodes
284 44 my $species_taxon = $self->tree->find_node(-rank => 'species');
285 44 ▶ unless ($species_taxon) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($species_taxon) 0 44 44
286 # just assume we are rank species
287 0 $species_taxon = $self->taxon;
288 }
289  
290 44 $species = $species_taxon->scientific_name;
291
292 #
293 # munge it like the Bio::SeqIO modules used to do
294 # (more or less copy/pasted from old Bio::SeqIO::genbank, hence comments
295 # referring to 'ORGANISM' etc.)
296 #
297  
298 44 my $root = $self->tree->get_root_node;
299 44 ▶ unless ($root) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($root) 0 44 44
300 0 $self->tree(Bio::Tree::Tree->new(-node => $species_taxon));
301 0 $root = $self->tree->get_root_node;
302 }
303
304 44 my @spflds = split(' ', $species);
305 44 ▶ if (@spflds > 1 && $root->node_name ne 'Viruses') {
Branch: 1 branch
BranchTrueFalseTotal
if (@spflds > 1 and $root->node_name ne "Viruses") 36 8 44
Condition66%2/3
@spflds > 1 and $root->node_name ne "Viruses"
!ll&&!rl&&r
8036
MC/DC50%1/2
@spflds > 1 and $root->node_name ne "Viruses"
@spflds > 1 $root->node_name ne "Viruses"
Truth table66%2/3
A and B
A= @spflds > 1B= $root->node_name ne "Viruses"
ABresult
0X0
100
111
306 36 $species = undef;
307  
308 # does the next term start with uppercase?
309 # yes: valid genus; no then unconventional
310 # e.g. leaf litter basidiomycete sp. Collb2-39
311 36 my $genus;
312 36 ▶ if ($spflds[0] =~ m/^[A-Z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spflds[0] =~ /^[A-Z]/) { } 36 0 36
313 36 $genus = shift(@spflds);
314 }
315 else {
316 0 undef $genus;
317 }
318
319 36 my $sub_species;
320 36 ▶ if (@spflds) {
Branch: 1 branch
BranchTrueFalseTotal
if (@spflds) { } 36 0 36
321 36 ▶ while (my $fld = shift @spflds) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fld = shift @spflds) 38 34 72
322 38 $species .= "$fld ";
323 # does it have subspecies or varieties?
324 38 ▶ last if ($fld =~ m/(sp\.|var\.)/);
Branch: 1 branch
BranchTrueFalseTotal
if $fld =~ /(sp\.|var\.)/ 2 36 38
325 }
326 36 chop $species; # last space
327 36 ▶ $sub_species = join ' ',@spflds if(@spflds);
Branch: 1 branch
BranchTrueFalseTotal
if @spflds 2 34 36
328 }
329 else {
330 0 $species = 'sp.';
331 }
332  
333 # does ORGANISM start with any words which make its genus undefined?
334 # these are in @unkn_genus
335 # this in case species starts with uppercase so isn't caught above.
336 # alter common name if required
337 36 my $unconv = 0; # is it unconventional species name?
338 36 my @unkn_genus = ('unknown','unclassified','uncultured','unidentified');
339 36 foreach (@unkn_genus) {
340 144 ▶ if ($genus && $genus =~ m/$_/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($genus and $genus =~ /$_/i) { } 0 144 144
elsif ($species =~ /$_/i) { } 0 144 144
Condition33%1/3
$genus and $genus =~ /$_/i
!ll&&!rl&&r
01440
MC/DC0%0/2
$genus and $genus =~ /$_/i
$genus $genus =~ /$_/i
Truth table33%1/3
A and B
A= $genusB= $genus =~ /$_/i
ABresult
0X0
100
111
341 0 $species = $genus . " " . $species;
342 0 undef $genus;
343 0 $unconv = 1;
344 0 last;
345 }
346 elsif ($species =~ m/$_/i) {
347 0 $unconv = 1;
348 0 last;
349 }
350 }
351 36 ▶ if (!$unconv && !$sub_species && $species =~ s/^(\w+)\s(\w+)$/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $unconv || $sub_species and $species =~ s/^(\w+)\s(\w+)$/$1/) 0 36 36
Condition66%4/6
not $unconv || $sub_species and $species =~ s/^(\w+)\s(\w+)$/$1/
!ll&&!rl&&r
2340
$unconv || $sub_species
l!l&&r!l&&!r
0234
MC/DC0%0/3
not $unconv || $sub_species and $species =~ s/^(\w+)\s(\w+)$/$1/
$unconv $sub_species $species =~ s/^(\w+)\s(\w+)$/$1/
Truth table50%2/4
not(A || B) and C
A= $unconvB= $sub_speciesC= $species =~ s/^(\w+)\s(\w+)$/$1/
ABCresult
1XX0
01X0
0000
0011
352 # need to extract subspecies from conventional ORGANISM format.
353 # Will the 'word' in a two element species name
354 # e.g. $species = 'thummi thummi' => $species='thummi' &
355 # $sub_species='thummi'
356 0 $sub_species = $2;
357 }
358  
359 36 ▶ $self->genus($genus) if $genus;
Branch: 1 branch
BranchTrueFalseTotal
if $genus 36 0 36
360 36 ▶ $self->sub_species($sub_species) if $sub_species;
Branch: 1 branch
BranchTrueFalseTotal
if $sub_species 2 34 36
361 }
362  
363 44 $self->{_species} = $species;
364 }
365 94 return $self->{_species};
366 }
367  
368 =head2 genus
369  
370 Title : genus
371 Usage : $self->genus( $genus );
372 $genus = $self->genus();
373 Function: Get or set the scientific genus name.
374 Example : $self->genus('Homo');
375 Returns : Scientific genus name as string
376 Args : Scientific genus name as string
377  
378 =cut
379  
380 145 ▶sub genus {
Subroutine genus: called CC=5 SCAR=16.2
Pod documented
381 145 my ($self, $genus) = @_;
382  
383 # TODO: instead of caching the raw name, cache the actual node instance.
384 145 ▶ if ($genus) {
Branch: 1 branch
BranchTrueFalseTotal
if ($genus) 53 92 145
385 53 $self->{_genus} = $genus;
386 }
387 145 ▶ unless (defined $self->{_genus}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_genus"}) 8 137 145
388 8 my $genus_taxon = $self->tree->find_node(-rank => 'genus');
389 8 ▶ unless ($genus_taxon) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($genus_taxon) 8 0 8
390 # just assume our ancestor is rank genus
391 8 $genus_taxon = $self->taxon->ancestor;
392 }
393
394 8 ▶ $self->{_genus} = $genus_taxon->scientific_name if $genus_taxon;
Branch: 1 branch
BranchTrueFalseTotal
if $genus_taxon 8 0 8
395 }
396
397 145 return $self->{_genus};
398 }
399  
400 =head2 sub_species
401  
402 Title : sub_species
403 Usage : $obj->sub_species($newval)
404 Function: Get or set the scientific subspecies name.
405 Returns : value of sub_species
406 Args : newvalue (optional)
407  
408 =cut
409  
410 9 ▶sub sub_species {
Subroutine sub_species: called CC=5 SCAR=18.7
Pod documented
411 9 my ($self, $sub) = @_;
412
413 # TODO: instead of caching the raw name, cache the actual node instance.
414 9 ▶ if (!defined $self->{'_sub_species'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_sub_species"}) 5 4 9
415 5 my $ss_taxon = $self->tree->find_node(-rank => 'subspecies');
416 5 ▶ if ($ss_taxon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss_taxon) { } 0 5 5
417 0 ▶ if ($sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub) 0 0 0
418 0 $ss_taxon->scientific_name($sub);
419
420 # *** weakening ref to our root node in species() to solve a
421 # memory leak means that we have a subspecies taxon to set
422 # during the first call to species(), but it has vanished by
423 # the time a user subsequently calls sub_species() to get the
424 # value. So we 'cheat' and just store the subspecies name in
425 # our self hash, instead of the tree. Is this a problem for
426 # a Species object? Can't decide --sendu
427
428 # This can now be changed to deal with this information on the
429 # fly. For now, the caching remains, but maybe we should just
430 # let these things deal with mutable data as needed? -- cjfields
431
432 0 $self->{'_sub_species'} = $sub;
433 }
434 0 return $ss_taxon->scientific_name;
435 }
436 else {
437 # should we create a node here to be added to the tree?
438 }
439 }
440
441 # fall back to direct storage on self
442 9 ▶ $self->{'_sub_species'} = $sub if $sub;
Branch: 1 branch
BranchTrueFalseTotal
if $sub 5 4 9
443 9 return $self->{'_sub_species'};
444 }
445  
446 =head2 variant
447  
448 Title : variant
449 Usage : $obj->variant($newval)
450 Function: Get/set variant information for this species object (strain,
451 isolate, etc).
452 Example :
453 Returns : value of variant (a scalar)
454 Args : new value (a scalar or undef, optional)
455  
456 =cut
457  
458 2 ▶sub variant{
Subroutine variant: called CC=5 SCAR=20.3
Pod documented
459 2 my ($self, $var) = @_;
460
461 # TODO: instead of caching the raw name, cache the actual node instance.
462 2 ▶ if (!defined $self->{'_variant'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_variant"}) 2 0 2
463 2 my $var_taxon = $self->tree->find_node(-rank => 'variant');
464 2 ▶ if ($var_taxon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_taxon) { } 0 2 2
465 0 ▶ if ($var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var) 0 0 0
466 0 $var_taxon->scientific_name($var);
467 }
468 0 return $var_taxon->scientific_name;
469 }
470 else {
471 # should we create a node here to be added to the tree?
472 }
473 }
474
475 # fall back to direct storage on self
476 2 ▶ $self->{'_variant'} = $var if $var;
Branch: 1 branch
BranchTrueFalseTotal
if $var 0 2 2
477 2 return $self->{'_variant'};
478 }
479  
480 =head2 binomial
481  
482 Title : binomial
483 Usage : $binomial = $self->binomial();
484 $binomial = $self->binomial('FULL');
485 Function: Returns a string "Genus species", or "Genus species subspecies",
486 if the first argument is 'FULL' (and the species has a subspecies).
487 Args : Optionally the string 'FULL' to get the full name including
488 the subspecies.
489 Note : This is just munged from the taxon() name
490  
491 =cut
492  
493 75 ▶sub binomial {
Subroutine binomial: called CC=7 SCAR=20.4
Pod documented
494 75 my ($self, $full) = @_;
495 75 ▶ my $rank = $self->taxon->rank || 'no rank';
Condition50%1/2
$self->taxon->rank || 'no rank'
l!l
750
MC/DC0%0/1
$self->taxon->rank || 'no rank'
$self->taxon->rank
Truth table50%1/2
A
A= $self->taxon->rank
Aresult
11
00
496
497 75 my ($species, $genus) = ($self->species, $self->genus);
498 75 ▶ unless (defined $species) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $species) 0 75 75
499 0 $species = 'sp.';
500 0 $self->warn("requested binomial but classification was not set");
501 }
502 75 ▶ $genus = '' unless( defined $genus);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $genus 0 75 75
503
504 75 $species =~ s/$genus\s+//;
505
506 75 my $bi = "$genus $species";
507 75 ▶ if (defined($full) && $full =~ /full/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $full and $full =~ /full/i) 3 72 75
Condition66%2/3
defined $full and $full =~ /full/i
!ll&&!rl&&r
7203
MC/DC50%1/2
defined $full and $full =~ /full/i
defined $full $full =~ /full/i
Truth table66%2/3
A and B
A= defined $fullB= $full =~ /full/i
ABresult
0X0
100
111
508 3 my $ssp = $self->sub_species;
509 3 ▶ if ($ssp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssp) 3 0 3
510 3 $ssp =~ s/$bi\s+//;
511 3 $ssp =~ s/$species\s+//;
512 3 $bi .= " $ssp";
513 }
514 }
515 75 return $bi;
516 }
517  
518 =head2 validate_species_name
519  
520 Title : validate_species_name
521 Usage : $result = $self->validate_species_name($string);
522 Function: Validate the species portion of the binomial
523 Args : string
524 Notes : The string following the "genus name" in the NCBI binomial is so
525 variable that it's not clear that this is a useful function. Consider
526 the binomials "Simian 11 rotavirus (serotype 3 / strain
527 SA11-Patton)", or "St. Thomas 3 rotavirus", straight from GenBank.
528 This is particularly problematic in microbes and viruses. As such,
529 this isn't actually used automatically by any Bio::Species method.
530  
531 =cut
532  
533 0 ▶sub validate_species_name {
Subroutine validate_species_name: not called CC=4 SCAR=30.0
Pod documented
534 0 my( $self, $string ) = @_;
535  
536 0 ▶ return 1 if $string eq "sp.";
Branch: 1 branch
BranchTrueFalseTotal
if $string eq "sp." 0 0 0
537 0 ▶ return 1 if $string =~ /strain/;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /strain/ 0 0 0
538 0 ▶ return 1 if $string =~ /^[a-z][\w\s-]+$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^[a-z][\w\s-]+$/i 0 0 0
539 0 $self->throw("Invalid species name '$string'");
540 }
541  
542 0 ▶sub validate_name {
Subroutine validate_name: not called CC=1 SCAR=6.9
Pod undocumented
543 0 return 1;
544 }
545  
546 =head2 organelle
547  
548 Title : organelle
549 Usage : $self->organelle( $organelle );
550 $organelle = $self->organelle();
551 Function: Get or set the organelle name
552 Example : $self->organelle('Chloroplast')
553 Returns : The organelle name in a string
554 Args : String, which is the organelle name
555 Note : TODO: We currently do not know where the organelle definition will
556 eventually go. This is stored in the source seqfeature, though,
557 so the information isn't lost.
558  
559 =cut
560  
561 40 ▶sub organelle {
Subroutine organelle: called CC=2 SCAR=6.9
Pod documented
562 40 my($self) = shift;
563 40 ▶ return $self->{'_organelle'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 11 29 40
564 29 return $self->{'_organelle'};
565 }
566  
567 =head2 Delegation
568  
569 The following methods delegate to the internal Bio::Taxon instance. This is
570 mainly to allow code continue using older methods, with the mind to migrate to
571 using Bio::Taxon and related methods when this class is deprecated.
572  
573 =cut
574  
575 5 ▶sub node_name {shift->taxon->node_name(@_)}
Subroutine node_name: called CC=1 SCAR=0.0
Pod undocumented
576 247 ▶sub scientific_name {shift->taxon->node_name(@_)}
Subroutine scientific_name: called CC=1 SCAR=0.0
Pod undocumented
577  
578 0 ▶sub id {shift->taxon->id(@_)}
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
579 0 ▶sub object_id {shift->taxon->id(@_)}
Subroutine object_id: not called CC=1 SCAR=6.9
Pod undocumented
580 326 ▶sub ncbi_taxid {shift->taxon->ncbi_taxid(@_)}
Subroutine ncbi_taxid: called CC=1 SCAR=0.0
Pod documented
581 1 ▶sub rank {shift->taxon->rank(@_)}
Subroutine rank: called CC=1 SCAR=0.0
Pod undocumented
582 0 ▶sub division {shift->taxon->division(@_)}
Subroutine division: not called CC=1 SCAR=6.9
Pod documented
583  
584 0 ▶sub common_names {shift->taxon->common_names(@_)}
Subroutine common_names: not called CC=1 SCAR=6.9
Pod undocumented
585 110 ▶sub common_name {shift->taxon->common_names(@_)}
Subroutine common_name: called CC=1 SCAR=0.0
Pod documented
586  
587 0 ▶sub genetic_code {shift->taxon->genetic_code(@_)}
Subroutine genetic_code: not called CC=1 SCAR=6.9
Pod undocumented
588 0 ▶sub mitochondrial_genetic_code {shift->taxon->mitochondrial_genetic_code(@_)}
Subroutine mitochondrial_genetic_code: not called CC=1 SCAR=6.9
Pod undocumented
589  
590 0 ▶sub create_date { shift->taxon->create_date(@_)}
Subroutine create_date: not called CC=1 SCAR=6.9
Pod undocumented
591 0 ▶sub pub_date { shift->taxon->pub_date(@_)}
Subroutine pub_date: not called CC=1 SCAR=6.9
Pod undocumented
592 0 ▶sub update_date { shift->taxon->update_date(@_)}
Subroutine update_date: not called CC=1 SCAR=6.9
Pod undocumented
593  
594 0 ▶sub db_handle { shift->taxon->db_handle(@_)}
Subroutine db_handle: not called CC=1 SCAR=6.9
Pod undocumented
595  
596 0 ▶sub parent_id { shift->taxon->parent_id(@_)}
Subroutine parent_id: not called CC=1 SCAR=6.9
Pod undocumented
597 0 ▶sub parent_taxon_id { shift->taxon->parent_id(@_)}
Subroutine parent_taxon_id: not called CC=1 SCAR=6.9
Pod undocumented
598  
599 0 ▶sub version { shift->taxon->version(@_)}
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
600 0 ▶sub authority { shift->taxon->authority(@_)}
Subroutine authority: not called CC=1 SCAR=6.9
Pod undocumented
601 0 ▶sub namespace { shift->taxon->namespace(@_)}
Subroutine namespace: not called CC=1 SCAR=6.9
Pod undocumented
602  
603 0 ▶sub ancestor { shift->taxon->ancestor(@_)}
Subroutine ancestor: not called CC=1 SCAR=6.9
Pod documented
604 0 ▶sub get_Parent_Node { shift->taxon->get_Parent_Node(@_)}
Subroutine get_Parent_Node: not called CC=1 SCAR=6.9
Pod undocumented
605 0 ▶sub each_Descendent { shift->taxon->each_Descendent(@_)}
Subroutine each_Descendent: not called CC=1 SCAR=6.9
Pod documented
606 0 ▶sub get_Children_Nodes { shift->taxon->get_Children_Nodes(@_)}
Subroutine get_Children_Nodes: not called CC=1 SCAR=6.9
Pod undocumented
607 0 ▶sub remove_Descendant { shift->taxon->remove_Descendant(@_)}
Subroutine remove_Descendant: not called CC=1 SCAR=6.9
Pod undocumented
608  
609 205 ▶sub name { shift->taxon->name(@_)}
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
610  
611 =head2 taxon
612  
613 Title : taxon
614 Usage : $obj->taxon
615 Function : retrieve the internal Bio::Taxon instance
616 Returns : A Bio::Taxon. If one is not previously set,
617 an instance is created lazily
618 Args : Bio::Taxon (optional)
619
620 =cut
621  
622 1720 ▶sub taxon {
Subroutine taxon: called CC=4 SCAR=14.3
Pod documented
623 1720 my ($self, $taxon) = @_;
624 1720 ▶ if (!$self->{taxon} || $taxon) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"taxon"} or $taxon) 210 1510 1720
Condition66%2/3
not $self->{"taxon"} or $taxon
l!l&&r!l&&!r
21001510
MC/DC50%1/2
not $self->{"taxon"} or $taxon
not $self->{"taxon"} $taxon
Truth table66%2/3
not(A) or B
A= not $self->{"taxon"}B= $taxon
ABresult
1X1
011
000
625 210 ▶ $taxon ||= Bio::Taxon->new();
Condition33%1/3
$taxon ||= "Bio::Taxon"->new
l!l&&r!l&&!r
21000
MC/DC0%0/2
$taxon ||= "Bio::Taxon"->new
$taxon "Bio::Taxon"->new
Truth table33%1/3
A ||= B
A= $taxonB= "Bio::Taxon"->new
ABresult
1X1
011
000
626 210 $self->{taxon} = $taxon;
627 }
628 1720 $self->{taxon};
629 }
630  
631 =head2 tree
632  
633 Title : tree
634 Usage : $obj->tree
635 Function : Returns a Bio::Tree::Tree object
636 Returns : A Bio::Tree::Tree. If one is not previously set,
637 an instance is created lazily
638 Args : Bio::Tree::Tree (optional)
639
640 =cut
641  
642 1025 ▶sub tree {
Subroutine tree: called CC=4 SCAR=14.0
Pod documented
643 1025 my ($self, $tree) = @_;
644 1025 ▶ if (!$self->{tree} || $tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"tree"} or $tree) 406 619 1025
Condition100%3/3
not $self->{"tree"} or $tree
l!l&&r!l&&!r
210196619
MC/DC100%2/2
not $self->{"tree"} or $tree
not $self->{"tree"} $tree
Truth table100%3/3
not(A) or B
A= not $self->{"tree"}B= $tree
ABresult
1X1
011
000
645 406 ▶ $tree ||= Bio::Tree::Tree->new();
Condition33%1/3
$tree ||= "Bio::Tree::Tree"->new
l!l&&r!l&&!r
40600
MC/DC0%0/2
$tree ||= "Bio::Tree::Tree"->new
$tree "Bio::Tree::Tree"->new
Truth table33%1/3
A ||= B
A= $treeB= "Bio::Tree::Tree"->new
ABresult
1X1
011
000
646 406 delete $tree->{_root_cleanup_methods};
647 406 $self->{tree} = $tree;
648 }
649 1025 $self->{tree};
650 }
651  
652 257 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
653 257 my $self = shift;
654 257 $self->tree->cleanup_tree;
655 257 delete $self->{tree};
656 257 $self->taxon->node_cleanup;
657 }
658  
659 41 1;
« Bio/Search/Result/CrossMatchResult.pm ↑ Summary Bio/TreeIO/phyloxml.pm »