Bio::DB::Universal: move into its own distribution
[bioperl-live.git] / examples / db / rfetch.pl
blob4cd7614b11050dc2334f4769ae992e6d00f565cf
1 #!/usr/bin/perl
4 # Fetch sequence data via OBDA registry system
6 # usage: rfetch -i <file_with_accession_list> -a -v -d embl -s start -e end
9 use Bio::DB::Registry;
10 use Bio::SeqIO;
11 use Getopt::Long;
12 use strict;
14 my $database = 'embl_biosql';
15 my $start = undef;
16 my $end = undef;
17 my $format = 'fasta';
18 my $file = undef;
19 my $acc = undef;
20 my $verbose = undef;
22 &GetOptions(
23 'd|database:s' => \$database,
24 's|start:i' => \$start,
25 'e|end:i' => \$end,
26 'f|format:s' => \$format,
27 'i|input:s' => \$file,
28 'a|acc' => \$acc,
29 'v|verbose' => \$verbose,
33 my $registry = Bio::DB::Registry->new();
35 my $db = $registry->get_database($database);
37 my $seqout = Bio::SeqIO->new( '-format' => $format, '-fh' => \*STDOUT);
39 my @ids;
41 if( defined $file ) {
42 open my $F, '<', $file or die "Could not read file '$file': $!\n";
43 while( <$F> ) {
44 my ($id) = split;
45 push(@ids,$id);
47 close $F;
48 } else {
49 @ids = @ARGV;
52 foreach my $id ( @ids ) {
53 my $seq;
54 if( $verbose ){
55 print STDERR "fetching $id\n";
58 if( $acc ) {
59 $seq = $db->get_Seq_by_acc($id);
60 } else {
61 $seq = $db->get_Seq_by_id($id);
64 if( defined $start && defined $end ) {
65 $seq = $seq->trunc($start,$end);
68 $seqout->write_seq($seq);