/
EMBL.pm
220 lines (158 loc) · 5.74 KB
/
EMBL.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#
#
# BioPerl module for Bio::DB::EMBL
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
#
# Copyright Jason Stajich
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::DB::EMBL - Database object interface for EMBL entry retrieval
=head1 SYNOPSIS
use Bio::DB::EMBL;
$embl = Bio::DB::EMBL->new();
# remember that EMBL_ID does not equal GenBank_ID!
$seq = $embl->get_Seq_by_id('BUM'); # EMBL ID
print "cloneid is ", $seq->id, "\n";
# or changeing to accession number and Fasta format ...
$embl->request_format('fasta');
$seq = $embl->get_Seq_by_acc('J02231'); # EMBL ACC
print "cloneid is ", $seq->id, "\n";
# especially when using versions, you better be prepared
# in not getting what what want
eval {
$seq = $embl->get_Seq_by_version('J02231.1'); # EMBL VERSION
};
print "cloneid is ", $seq->id, "\n" unless $@;
# or ... best when downloading very large files, prevents
# keeping all of the file in memory
# also don't want features, just sequence so let's save bandwith
# and request Fasta sequence
$embl = Bio::DB::EMBL->new(-retrievaltype => 'tempfile' ,
-format => 'fasta');
my $seqio = $embl->get_Stream_by_id(['AC013798', 'AC021953'] );
while( my $clone = $seqio->next_seq ) {
print "cloneid is ", $clone->id, "\n";
}
=head1 DESCRIPTION
Allows the dynamic retrieval of sequence objects L<Bio::Seq> from the
EMBL database using the dbfetch script at EBI:
L<http://www.ebi.ac.uk/cgi-bin/dbfetch>.
In order to make changes transparent we have host type (currently only
ebi) and location (defaults to ebi) separated out. This allows later
additions of more servers in different geographical locations.
The functionality of this module is inherited from L<Bio::DB::DBFetch>
which implements L<Bio::DB::WebDBSeqI>.
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
http://bugzilla.open-bio.org/
=head1 AUTHOR - Heikki Lehvaslaiho
Email Heikki Lehvaslaiho E<lt>heikki-at-bioperl-dot-orgE<gt>
=head1 APPENDIX
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
=cut
# Let the code begin...
package Bio::DB::EMBL;
use strict;
use vars qw($MODVERSION %HOSTS %FORMATMAP $DEFAULTFORMAT);
$MODVERSION = '0.2';
use Bio::DB::RefSeq;
use base qw(Bio::DB::DBFetch);
BEGIN {
# you can add your own here theoretically.
%HOSTS = (
'dbfetch' => {
baseurl => 'http://%s/Tools/dbfetch/dbfetch?db=embl&style=raw',
hosts => {
'ebi' => 'www.ebi.ac.uk'
}
}
);
%FORMATMAP = ( 'embl' => 'embl',
'fasta' => 'fasta'
);
$DEFAULTFORMAT = 'embl';
}
=head2 new
Title : new
Usage : $gb = Bio::DB::GenBank->new(@options)
Function: Creates a new genbank handle
Returns : New genbank handle
Args : -delay number of seconds to delay between fetches (3s)
NOTE: There are other options that are used internally.
=cut
sub new {
my ($class, @args ) = @_;
my $self = $class->SUPER::new(@args);
$self->{ '_hosts' } = {};
$self->{ '_formatmap' } = {};
$self->hosts(\%HOSTS);
$self->formatmap(\%FORMATMAP);
$self->{'_default_format'} = $DEFAULTFORMAT;
return $self;
}
=head2 Bio::DB::WebDBSeqI methods
Overriding WebDBSeqI method to help newbies to retrieve sequences.
EMBL database is all too often passed RefSeq accessions. This
redirects those calls. See L<Bio::DB::RefSeq>.
=head2 get_Stream_by_acc
Title : get_Stream_by_acc
Usage : $seq = $db->get_Seq_by_acc([$acc1, $acc2]);
Function: Gets a series of Seq objects by accession numbers
Returns : a Bio::SeqIO stream object
Args : $ref : a reference to an array of accession numbers for
the desired sequence entries
Note : For GenBank, this just calls the same code for get_Stream_by_id()
=cut
sub get_Stream_by_acc {
my ($self, $ids ) = @_;
my $newdb = $self->_check_id($ids);
if ($newdb && $newdb->isa('Bio::DB::RefSeq')) {
return $newdb->get_seq_stream('-uids' => $ids, '-mode' => 'single');
} else {
return $self->get_seq_stream('-uids' => $ids, '-mode' => 'single');
}
}
=head2 _check_id
Title : _check_id
Usage :
Function:
Returns : A Bio::DB::RefSeq reference or throws
Args : $id(s), $string
=cut
sub _check_id {
my ($self, $ids) = @_;
# NT contigs can not be retrieved
$self->throw("NT_ contigs are whole chromosome files which are not part of regular".
"database distributions. Go to ftp://ftp.ncbi.nih.gov/genomes/.")
if $ids =~ /NT_/;
# Asking for a RefSeq from EMBL/GenBank
if ($ids =~ /N._/) {
$self->warn("[$ids] is not a normal sequence entry but a RefSeq entry.".
" Redirecting the request.\n")
if $self->verbose >= 0;
return Bio::DB::RefSeq->new(-verbose => $self->verbose);
}
}
1;