Debian Codegraph @

eg/gb_get

raw
1 #!/usr/bin/perl
2
3 use strict 'vars';
4 use lib '..','../blib/lib','.','./blib/lib';
5 use Boulder::Stream;
6 use Boulder::Genbank;
7 use Getopt::Long;
8 use Text::Abbrev;
9 my ($ACCESSOR,$DELAY,$FIRST,$BOULDER,$DB);
10
11 GetOptions('accessor=s' => \$ACCESSOR,
12 'boulder' =>\$BOULDER,
13 'db=s' => \$DB,
14 'delay=i' => \$DELAY) || die <<USAGE;
15 Usage: $0 [options] [accession] [accession] ...
16
17 Retrieves Genbank entries from a list of accession
18 numbers. If no accession numbers are present on the
19 command line, or if the magic "-" argument is given,
20 will read accession numbers from standard in.
21
22 Outputs a series of Genbank records for each accession
23 number.
24
25 Options:
26 -accessor <Entrez|Yank> Use the Entrez|Yank methods
27 for retrieving records.
28 -boulder Return boulder format file
29 -db Database
30 -delay <seconds> Seconds to sleep between retrievals (10)
31
32 Options may be abbreviated, i.e. -acc E
33
34 Database specifiers:
35 m MEDLINE
36 p Protein
37 n Nucleotide
38 t 3-D structure
39 c Genome
40
41 USAGE
42 ;
43
44 $ACCESSOR ||= 'Entrez';
45 unless (defined $DELAY) {
46 warn "Warning: No -delay parameter. Introducing a 1 second delay between fetches\n";
47 $DELAY = 1;
48 }
49 my @accession_numbers;
50 my $from_stdin = !@ARGV;
51 my $abbrev = abbrev qw(Entrez Yank entrez yank);
52 my $accessor = $abbrev->{$ACCESSOR} || die "Unknown access method $ACCESSOR";
53 substr($accessor,0,1)=~tr/a-z/A-Z/; #canonicalize
54
55 while (defined (my $a = shift)) {
56 $from_stdin++,last if $a eq '-';
57 push(@accession_numbers,$a);
58 }
59
60 if ($from_stdin) {
61 while (<>) {
62 chomp;
63 next if /^\#/;
64 my ($a) = /^(\w+)/;
65 next unless $a;
66 push(@accession_numbers,$a);
67 }
68 }
69
70 $DB ||= 'n';
71
72 my $stream = new Boulder::Stream;
73 my $gb = new Boulder::Genbank(-accessor=>$accessor,-fetch=>\@accession_numbers,-db=>$DB)
74 || die "Couldn't open new Boulder::Genbank object";
75 my $count;
76 while (1) {
77 last if $count++ > @accession_numbers;
78 next unless my $s = $gb->get;
79 sleep $DELAY if $FIRST++ && $DELAY > 0;
80 unless ($BOULDER) {
81 print $s->Blob,"//\n";
82 } else {
83 $stream->put($s);
84 }
85 }
86