~ubuntu-branches/ubuntu/saucy/bioperl/saucy-proposed

« back to all changes in this revision

Viewing changes to Bio/DB/Taxonomy.pm

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: Taxonomy.pm,v 1.11.4.2 2006/10/02 23:10:15 sendu Exp $
 
1
# $Id: Taxonomy.pm 11480 2007-06-14 14:16:21Z sendu $
2
2
#
3
3
# BioPerl module for Bio::DB::Taxonomy
4
4
#
17
17
=head1 SYNOPSIS
18
18
 
19
19
  use Bio::DB::Taxonomy;
20
 
  my $db = new Bio::DB::Taxonomy(-source => 'entrez');
 
20
  my $db = Bio::DB::Taxonomy->new(-source => 'entrez');
21
21
  # use NCBI Entrez over HTTP
22
22
  my $taxonid = $db->get_taxonid('Homo sapiens');
23
23
 
67
67
package Bio::DB::Taxonomy;
68
68
use vars qw($DefaultSource $TAXON_IIDS);
69
69
use strict;
70
 
 
 
70
use Bio::Tree::Tree;
71
71
 
72
72
use base qw(Bio::Root::Root);
73
73
 
77
77
=head2 new
78
78
 
79
79
 Title   : new
80
 
 Usage   : my $obj = new Bio::DB::Taxonomy(-source => 'entrez');
 
80
 Usage   : my $obj = Bio::DB::Taxonomy->new(-source => 'entrez');
81
81
 Function: Builds a new Bio::DB::Taxonomy object.
82
82
 Returns : an instance of Bio::DB::Taxonomy
83
83
 Args    : -source => which database source 'entrez' or 'flatfile' or 'list'
146
146
*get_taxonid = \&get_taxonids;
147
147
*get_taxaid = \&get_taxonids;
148
148
 
 
149
=head2 get_tree
 
150
 
 
151
 Title   : get_tree
 
152
 Usage   : my $tree = $db->get_tree(@species_names)
 
153
 Function: Generate a tree comprised of the full lineages of all the supplied
 
154
           species names. The nodes for the requested species are given
 
155
           name('supplied') values corresponding to the supplied name, such that
 
156
           they can be identified if the real species name in the database
 
157
           (stored under node_name()) is different.
 
158
 Returns : Bio::Tree::Tree
 
159
 Args    : a list of species names (strings)
 
160
 
 
161
=cut
 
162
 
 
163
sub get_tree {
 
164
    my ($self, @species_names) = @_;
 
165
    
 
166
    # the full lineages of the species are merged into a single tree
 
167
    my $tree;
 
168
    foreach my $name (@species_names) {
 
169
        my $ncbi_id = $self->get_taxonid($name);
 
170
        if ($ncbi_id) {
 
171
            my $node = $self->get_taxon(-taxonid => $ncbi_id);
 
172
            $node->name('supplied', $name);
 
173
            
 
174
            if ($tree) {
 
175
                $tree->merge_lineage($node);
 
176
            }
 
177
            else {
 
178
                $tree = Bio::Tree::Tree->new(-verbose => $self->verbose, -node => $node);
 
179
            }
 
180
        }
 
181
        else {
 
182
            $self->throw("No taxonomy database node for species ".$name);
 
183
        }
 
184
    }
 
185
    
 
186
    return $tree;
 
187
}
 
188
 
149
189
=head2 ancestor
150
190
 
151
191
 Title   : ancestor