small update
[bioperl-live.git] / Bio / DB / RefSeq.pm
blob1efee784695112f15212daab68cdaa7193875dd3
2 # $Id$
4 # BioPerl module for Bio::DB::EMBL
6 # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::DB::RefSeq - Database object interface for RefSeq retrieval
18 =head1 SYNOPSIS
20 use Bio::DB::RefSeq;
22 $db = Bio::DB::RefSeq->new();
24 # most of the time RefSeq_ID eq RefSeq acc
25 $seq = $db->get_Seq_by_id('NM_006732'); # RefSeq ID
26 print "accession is ", $seq->accession_number, "\n";
28 # or changeing to accession number and Fasta format ...
29 $db->request_format('fasta');
30 $seq = $db->get_Seq_by_acc('NM_006732'); # RefSeq ACC
31 print "seq is ", $seq->seq, "\n";
33 # especially when using versions, you better be prepared
34 # in not getting what what want
35 eval {
36 $seq = $db->get_Seq_by_version('NM_006732.1'); # RefSeq VERSION
38 print "accesion is ", $seq->accession_number, "\n" unless $@;
40 # or ... best when downloading very large files, prevents
41 # keeping all of the file in memory
43 # also don't want features, just sequence so let's save bandwith
44 # and request Fasta sequence
45 $db = Bio::DB::RefSeq->new(-retrievaltype => 'tempfile' ,
46 -format => 'fasta');
47 my $seqio = $db->get_Stream_by_id(['NM_006732', 'NM_005252'] );
48 while( my $seq = $seqio->next_seq ) {
49 print "seqid is ", $seq->id, "\n";
52 =head1 DESCRIPTION
54 Allows the dynamic retrieval of sequence objects L<Bio::Seq> from the
55 RefSeq database using the dbfetch script at EBI:
56 L<http:E<sol>E<sol>www.ebi.ac.ukE<sol>cgi-binE<sol>dbfetch>.
58 In order to make changes transparent we have host type (currently only
59 ebi) and location (defaults to ebi) separated out. This allows later
60 additions of more servers in different geographical locations.
62 The functionality of this module is inherited from L<Bio::DB::DBFetch>
63 which implements L<Bio::DB::WebDBSeqI>.
65 This module retrieves entries from EBI although it
66 retrives database entries produced at NCBI. When read into bioperl
67 objects, the parser for GenBank format it used. RefSeq is a
68 NONSTANDARD GenBank file so be ready for surprises.
70 =head1 FEEDBACK
72 =head2 Mailing Lists
74 User feedback is an integral part of the evolution of this and other
75 Bioperl modules. Send your comments and suggestions preferably to one
76 of the Bioperl mailing lists. Your participation is much appreciated.
78 bioperl-l@bioperl.org - General discussion
79 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
81 =head2 Reporting Bugs
83 Report bugs to the Bioperl bug tracking system to help us keep track
84 the bugs and their resolution. Bug reports can be submitted via the
85 web:
87 http://bugzilla.open-bio.org/
89 =head1 AUTHOR - Heikki Lehvaslaiho
91 Email Heikki Lehvaslaiho E<lt>heikki-at-bioperl-dot-orgE<gt>
93 =head1 APPENDIX
95 The rest of the documentation details each of the object
96 methods. Internal methods are usually preceded with a _
98 =cut
100 # Let the code begin...
102 package Bio::DB::RefSeq;
103 use strict;
104 use vars qw($MODVERSION %HOSTS %FORMATMAP $DEFAULTFORMAT);
106 $MODVERSION = '0.1';
108 use base qw(Bio::DB::DBFetch);
110 BEGIN {
111 # you can add your own here theoretically.
112 %HOSTS = (
113 'dbfetch' => {
114 baseurl => 'http://%s/cgi-bin/dbfetch?db=refseq&style=raw',
115 hosts => {
116 'ebi' => 'www.ebi.ac.uk'
120 %FORMATMAP = ( 'embl' => 'embl',
121 'genbank' => 'genbank',
122 'fasta' => 'fasta'
124 $DEFAULTFORMAT = 'genbank';
127 sub new {
128 my ($class, @args ) = @_;
129 my $self = $class->SUPER::new(@args);
131 $self->{ '_hosts' } = {};
132 $self->{ '_formatmap' } = {};
134 $self->hosts(\%HOSTS);
135 $self->formatmap(\%FORMATMAP);
136 $self->{'_default_format'} = $DEFAULTFORMAT;
138 return $self;
142 sub get_seq_stream {
143 my ($self,%qualifiers) = @_;
144 if( exists $qualifiers{'-uids'} ) {
145 if( ref($qualifiers{'-uids'}) =~ /ARRAY/i ) {
146 foreach my $u ( @{$qualifiers{'-uids'}} ) {
147 $u =~ s/^(\S+)\|//;
149 } else {
150 $qualifiers{'-uids'} =~ s/^(\S+)\|//;
153 $self->SUPER::get_seq_stream(%qualifiers);