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