~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

Viewing changes to Bio/DB/BioFetch.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: BioFetch.pm,v 1.9.2.2 2002/03/15 14:40:02 heikki Exp $
 
1
# $Id: BioFetch.pm,v 1.22 2003/12/11 10:55:46 heikki Exp $
2
2
#
3
3
# BioPerl module for Bio::DB::BioFetch
4
4
#
26
26
 
27
27
 $bf = new Bio::DB::BioFetch;
28
28
 
29
 
 $seq = $sp->get_Seq_by_id('BUM');  # EMBL or SWALL ID
 
29
 $seq = $bf->get_Seq_by_id('BUM');  # EMBL or SWALL ID
30
30
 
31
31
 # change formats, storage procedures
32
32
 $bf = new Bio::DB::BioFetch(-format        => 'fasta',
75
75
or the web:
76
76
 
77
77
  bioperl-bugs@bio.perl.org
78
 
  http://bio.perl.org/bioperl-bugs/
 
78
  http://bugzilla.bioperl.org/
79
79
 
80
80
=head1 AUTHOR - Lincoln Stein
81
81
 
92
92
=cut
93
93
 
94
94
# Let the code begin...
95
 
use vars qw(@ISA $VERSION %FORMATMAP );
 
95
use vars qw(@ISA %FORMATMAP );
96
96
use Bio::Root::Root;
97
97
@ISA = qw(Bio::DB::WebDBSeqI Bio::Root::Root);
98
 
$VERSION = '1.0';
99
98
 
100
99
# warning: names used here must map into Bio::SeqIO::* space
101
100
use constant DEFAULT_LOCATION => 'http://www.ebi.ac.uk/cgi-bin/dbfetch';
102
101
 
103
102
BEGIN {
104
103
 
105
 
    %FORMATMAP = ( 
106
 
                   'embl' => {
107
 
                       default => 'embl', # default BioFetch format/SeqIOmodule pair
108
 
                       embl => 'embl',    # alternative BioFetch format/module pair 
109
 
                       fasta => 'fasta'   # alternative BioFetch format/module pair 
110
 
                       },
111
 
                   'swall' => {
112
 
                       default => 'swiss',
113
 
                       swissprot => 'swiss',
114
 
                       fasta => 'fasta'
115
 
                       },
116
 
                   'refseq' => {
117
 
                       default => 'genbank',
118
 
                       genbank => 'genbank',
119
 
                       fasta => 'fasta'
120
 
                       }
121
 
                   );
 
104
  %FORMATMAP = (
 
105
                'embl' => {
 
106
                           default => 'embl', # default BioFetch format/SeqIOmodule pair
 
107
                           embl => 'embl',    # alternative BioFetch format/module pair 
 
108
                           fasta => 'fasta',   # alternative BioFetch format/module pair 
 
109
                           namespace => 'embl',
 
110
                          },
 
111
                'swissprot' => {
 
112
                                default => 'swiss',
 
113
                                swissprot => 'swiss',
 
114
                                fasta => 'fasta',
 
115
                                namespace => 'swall',
 
116
                               },
 
117
                'refseq' => {
 
118
                             default => 'genbank',
 
119
                             genbank => 'genbank',
 
120
                             fasta => 'fasta',
 
121
                             namespace => 'RefSeq',
 
122
                            },
 
123
                'swall' => {
 
124
                            default => 'swiss',
 
125
                            swissprot => 'swiss',
 
126
                            fasta => 'fasta',
 
127
                            namespace => 'swall',
 
128
                           },
 
129
                'genbank' => {
 
130
                              default => 'genbank',
 
131
                              genbank => 'genbank',
 
132
                              namespace => 'genbank',
 
133
                             },
 
134
                'genpep' => {
 
135
                             default => 'genbank',
 
136
                             genbank => 'genbank',
 
137
                             namespace => 'genpep',
 
138
                            },
 
139
               );
122
140
}
123
141
 
124
142
=head2 new
139
157
 
140
158
  -baseaddress   location of dbfetch server       http://www.ebi.ac.uk/cgi-bin/dbfetch
141
159
  -retrievaltype "tempfile" or "io_string"        io_string
142
 
  -format        "embl" or "fasta" or "swissprot" embl
143
 
  -db            "embl", "genbank" or "swall"     embl
 
160
  -format        "embl", "fasta", "swissprot",    embl
 
161
                  or "genbank"
 
162
  -db            "embl", "genbank" or "swissprot" embl
144
163
 
145
164
=cut
146
165
 
173
192
    my $self = $class->SUPER::new(
174
193
                                  -BASEADDRESS=>$config{'location'}
175
194
                                  );
176
 
    $self->db($config{'biodbname'});
 
195
    $self->db($config{'dbname'}) if $config{dbname};
177
196
    return $self;
178
197
}
179
 
    
 
198
 
180
199
# from Bio::DB::RandomAccessI
181
200
 
182
201
=head2 get_Seq_by_id
289
308
    my ($uids, $format) = $self->_rearrange([qw(UIDS FORMAT)],
290
309
                                            @qualifiers);
291
310
    my $db     = $self->db;
 
311
    my $namespace = $self->_namespace;
 
312
 
292
313
    $self->throw("Must specify a value for UIDs to fetch")
293
314
        unless defined $uids;
294
315
    my $tmp;
301
322
    my $uid = join('+',ref $uids ? @$uids : $uids);
302
323
    $self->debug("\n$base$format_string&id=$uid\n");
303
324
    return POST($base,
304
 
                [ db     => $db,
 
325
                [ db     => $namespace,
305
326
                  id     => join('+',ref $uids ? @$uids : $uids),
306
327
                  format => $format,
307
328
                  style  => 'raw'
357
378
  return $self->{_db} || $self->default_db ;
358
379
}
359
380
 
 
381
sub _namespace {
 
382
  my $self = shift;
 
383
  my $db = $self->db;
 
384
  return $FORMATMAP{$db}{namespace} or $db;
 
385
}
 
386
 
360
387
=head2 postprocess_data
361
388
 
362
389
 Title   : postprocess_data
393
420
  }
394
421
 
395
422
  else {
396
 
    $self->throw("Don't know how to preprocess data of type $args{'type'}");
 
423
    $self->throw("Don't know how to postprocess data of type $args{'type'}");
397
424
  }
398
425
}
399
426
 
415
442
sub request_format {
416
443
    my ($self, $value) = @_;
417
444
    if ( defined $value ) { 
418
 
        my $db = $self->db; 
 
445
        my $db = $self->db;
 
446
        my $namespace = $self->_namespace;
419
447
        my $format = lc $value;
420
 
        print "format:", $format, " module:", $FORMATMAP{$db}->{$format}, " ($db)\n" 
 
448
        print "format:", $format, " module:", $FORMATMAP{$db}->{$format}, " ($namespace)\n" 
421
449
            if $self->verbose > 0; 
422
450
        $self->throw("Invalid format [$format], must be one of [".
423
451
                     join(' ',keys %{$FORMATMAP{$db}}). "]")
477
505
    # Asking for a RefSeq from EMBL/GenBank
478
506
 
479
507
    if ($id =~ /N._/ &&  $self->db ne 'refseq') {
480
 
        $self->warn("[$id] is not a normal sequence database but a RefSeq entry.".
 
508
        $self->warn("[$id] is not a normal sequence entry but a RefSeq entry.".
481
509
                   " Redirecting the request.\n")
482
510
            if $self->verbose >= 0;
483
511
        $self->db('RefSeq');