tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / examples / db / get_seqs.pl
blobcdbafe871cc88c3401ce166158d1b857d8d25f54
1 #!/usr/local/bin/perl -w
2 use strict;
3 use vars qw($USAGE);
4 use Carp;
5 use Getopt::Long;
6 use Bio::SeqIO;
8 $USAGE = "get_seqs.pl\t[--db=DBNAME] [--format=FORMAT] \n\t\t[--output=FILENAME] [--proxy=PROXY] accession1, accession2, ...\n Defaults: db=GenBank format=fasta output=STDOUT proxy=none\n See LWP::UserAgent for more information on proxy syntax";
9 my %dbs = (
10 'genbank' => 'Bio::DB::GenBank',
11 'embl' => 'Bio::DB::EMBL',
12 'swissprot' => 'Bio::DB::SwissProt',
15 my ($db,$format,$file,$proxy,$help) = ( 'genbank', 'fasta' );
17 &GetOptions
19 'db:s' => \$db,
20 'f|format:s' => \$format,
21 "file|out|output:s" => \$file,
22 'proxy:s' => \$proxy,
23 "h|\?|help" => \$help ,
26 if( $help ) { print $USAGE, "\n";exit; }
28 if( $db =~ /gb|gen|genbank/i ) {
29 $db = 'genbank';
30 } elsif( $db =~ /embl|em|e/i ) {
31 $db = 'embl';
32 } elsif( $db =~ /swiss|sp/i ) {
33 $db = 'swissprot';
34 } else {
35 croak("Unknown db parameter '$db' valid parameters are (" . join(',', keys %dbs) . ")");
38 my %params = ( '-format' => $format );
40 if( defined $file ) {
41 $params{'-file'} = ">$file";
42 } else {
43 $params{'-fh'} = \*STDOUT;
46 my $seqio = new Bio::SeqIO(%params);
48 my $remotedb;
50 eval {
51 my $filename = "$dbs{$db}.pm";
52 $filename =~ s!::!/!g;
53 require $filename;
54 $remotedb = "$dbs{$db}"->new();
57 die($@) unless ! $@;
59 if( defined $proxy ) { $remotedb->proxy($proxy); }
61 my $stream;
63 if( $remotedb->can('get_Stream_by_batch') ) {
64 $stream = $remotedb->get_Stream_by_batch(@ARGV);
65 } else {
66 $stream = $remotedb->get_Stream_by_acc(\@ARGV);
69 while( my $seq = $stream->next_seq ) {
70 $seqio->write_seq($seq);