tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / scripts / taxa / taxid4species.PLS
blob6ddc12a53e76c771dc443d203d15493548d56cdb
1 #!perl -w
2 # Author:  Jason Stajich <jason@bioperl.org>
3 # Purpose: Retrieve the NCBI Taxa ID for organism(s)
5 # TODO: add rest of POD
8 use LWP::UserAgent;
9 use XML::Twig;
10 use strict;
11 use Getopt::Long;
12 my $verbose = 0;
13 my $plain   = 0;
14 my $help    = 0;
15 my $USAGE = "taxid4species: [-v] [-p] \"Genus1 species1\" \"Genus2 species2\"";
17 GetOptions('v|verbose' => \$verbose,
18            'p|plain'   => \$plain,
19            'h|help'    => \$help);
20 die("$USAGE\n") if $help;
22 my $ua = new LWP::UserAgent();
24 my $urlbase = 'http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=taxonomy&term=';
26 my (@organisms) = @ARGV;
27 die("must provide valid organism") unless @organisms;
28 my $organismstr = join(" OR ", @organisms);
29 $organismstr =~ s/\s/\+/g;
31 my $response = $ua->get($urlbase.$organismstr);
32 my $t = XML::Twig->new();
33 print $response->content,"\n"if($verbose);
34 $t->parse($response->content);
35 my $root = $t->root;
36 my $list = $root->first_child('IdList');
37 my @data;
38 foreach my $child ($list->children('Id') ) {
39     push @data, $child->text;
40     if( $plain ) { print $child->text, "\n" }
42 unless( $plain  ) {
43     $list = $root->first_child('TranslationStack');
44     foreach my $set ($list->children('TermSet') ) {
45         foreach my $term ( $set->children('Term') ) {
46             print "\"",$term->text(), "\", ", shift @data, "\n";
47         }
48     }
51 =head1 NAME
53 taxid4species - simple script which returns the NCBI Taxonomic id for a requested species
55 =head1 SYNOPSIS
57 taxid4species [-v] [-p] [-h] "Genus1 species1" "Genus2 species2"
59 Options:
60   -v   verbose
61   -p   plain
62   -h   help
64 =head1 DESCRIPTION
66 This simple script shows how to get the taxa id from NCBI Entrez and
67 will return a list of taxa ids for requested organisms.
69 =head1 FEEDBACK
71 =head2 Mailing Lists
73 User feedback is an integral part of the evolution of this and other
74 Bioperl modules. Send your comments and suggestions preferably to
75 the Bioperl mailing list.  Your participation is much appreciated.
77   bioperl-l@bioperl.org                  - General discussion
78   http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
80 =head2 Reporting Bugs
82 Report bugs to the Bioperl bug tracking system to help us keep track
83 of the bugs and their resolution. Bug reports can be submitted via the
84 web:
86   http://bugzilla.open-bio.org/
88 =head1 AUTHOR
90  Jason Stajich jason-at-bioperl-dot-org
92 =cut