Module:Bio::DB::Taxonomy

From BioPerl

Jump to: navigation, search


Pdoc documentation: Bio::DB::Taxonomy CPAN documentation: Bio::DB::Taxonomy


Example usage

Here is some example usage that shows how to gather children from a node

#!/usr/bin/perl -w
use strict;
use Bio::DB::Taxonomy;
 
my $idx_dir = '/tmp';
 
my ($nodefile,$namesfile) = ('nodes.dmp','names.dmp');
my $db = new Bio::DB::Taxonomy(-source    => 'flatfile',
                               -nodesfile => $nodefile,
                               -namesfile => $namesfile,
                               -directory => $idx_dir);
my $node = $db->get_Taxonomy_Node(-taxonid => '33090');
print $node->id, " ", $node->scientific_name, " ", $node->rank, "\n";
# to only get children that are of a particular rank in the taxonomy test if their rank is 'species' for example
my @extant_children = grep { $_->rank eq 'species' } $node->get_all_Descendents;
 
for my $child ( @extant_children ) {
    print "id is ", $child->id, "\n"; # NCBI taxa id
    print "rank is ", $child->rank, "\n"; # e.g. species
    print "scientific name is ", $child->scientific_name, "\n"; # scientific name
}

Ammended for Bio::Taxon missing each_Descendent implementation

Note that this was fixed in CVS 18-Jun-2007 so you don't need to add the extra overridden each_Descendent code.

#!/usr/bin/perl -w
use strict;
use Bio::DB::Taxonomy;
use Bio::Taxon;
 
sub Bio::Taxon::each_Descendent {
    my ($self) = shift;
    my $db ||= $self->db_handle || return;
    return $db->each_Descendent($self);
}
 
 
my $idx_dir = '/tmp';
 
my ($nodefile,$namesfile) = ('nodes.dmp','names.dmp');
my $db = new Bio::DB::Taxonomy(-source    => 'flatfile',
                               -nodesfile => $nodefile,
                               -namesfile => $namesfile,
                               -directory => $idx_dir);
my $node = $db->get_Taxonomy_Node(-taxonid => '33090');
print $node->id, " ", $node->scientific_name, " ", $node->rank, "\n";
# to only get children that are of a particular rank in the taxonomy test if their rank is 'species' for example
my @extant_children = grep { $_->rank eq 'species' } $node->get_all_Descendents;
 
for my $child ( @extant_children ) {
    print "id is ", $child->id, "\n"; # NCBI taxa id
    print "rank is ", $child->rank, "\n"; # e.g. species
    print "scientific name is ", $child->scientific_name, "\n"; # scientific name
}
Personal tools