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