bin/bp_biofetch_genbank_proxy: move to Bio-DB-NCBIHelper
[bioperl-live.git] / bin / bp_local_taxonomydb_query
blobfefcc676a5e6887482e96bbbc61c8745175af322
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Bio::DB::Taxonomy;
6 use strict;
7 use Getopt::Long;
8 my $verbose = 0;
9 my $plain = 0;
10 my ($nodesfile,$namesfile);
11 my $idx_dir = '/tmp/idx';
12 GetOptions('v|verbose' => \$verbose,
13 'nodes:s' => \$nodesfile,
14 'names:s' => \$namesfile,
15 'idx:s' => \$idx_dir,
16 'h|help' => sub{ exec('perldoc',$0);
17 exit(0)
18 } );
20 unless( @ARGV || $nodesfile || $namesfile ) {
21 exec('perldoc',$0);
22 exit(0);
24 mkdir($idx_dir) unless -d $idx_dir;
26 my $db = new Bio::DB::Taxonomy(-source => 'flatfile',
27 -nodesfile => $nodesfile,
28 -namesfile => $namesfile,
29 -directory => $idx_dir);
30 foreach my $sp ( @ARGV ) {
31 my $node = $db->get_Taxonomy_Node(-name => $sp);
32 if( defined $node ) {
33 print "id is ", $node->id, "\n"; # 9606
34 print "rank is ", $node->rank, "\n"; # species
35 print "scientific name is ", $node->scientific_name, "\n"; # Homo sapiens
36 print "division is ", $node->division, "\n"; # Primates
37 } else {
38 warn("no node found for query $sp");
42 =head1 NAME
44 bp_local_taxonomydb_query - query a local TaxonomyDB for species or taxonid
46 =head1 DESCRIPTION
48 This script provides an example implementation of access to a local
49 Taxonomy database implemented with Berkeley DB (DB_File module is needed).
51 Usage:
53 bp_local_taxonomydb_query.PLS: [-v] --nodes nodes.dmp --names names.dmp "Genus1 species1" "Genus2 species2"
55 Providing the nodes.dmp and names.dmp files from the NCBI Taxonomy
56 dump (see Bio::DB::Taxonomy::flatfile for more info) is only necessary
57 on the first time running. This will create the local indexes and may
58 take quite a long time. However once created, these indexes will
59 allow fast access for species to taxon id OR taxon id to species name
60 lookups.