~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to scripts/taxa/bp_taxid4species.pl

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

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