Bump RC to 2; will tag, bag, and ship tomorrow after tests
[bioperl-live.git] / Bio / DB / EntrezGene.pm
blobc018e77de72d629ef3043186fa410495d19ca567
1 # $Id$
3 # BioPerl module for Bio::DB::EntrezGene
5 # Cared for by Brian Osborne bosborne at alum.mit.edu
7 # Copyright Brian Osborne
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::DB::EntrezGene - Database object interface to Entrez Gene
17 =head1 SYNOPSIS
19 use Bio::DB::EntrezGene;
21 my $db = Bio::DB::EntrezGene->new;
23 my $seq = $db->get_Seq_by_id(2); # Gene id
25 # or ...
27 my $seqio = $db->get_Stream_by_id([2, 4693, 3064]); # Gene ids
28 while ( my $seq = $seqio->next_seq ) {
29 print "id is ", $seq->display_id, "\n";
32 =head1 DESCRIPTION
34 Allows the dynamic retrieval of Sequence objects from the
35 Entrez Gene database at NCBI, via an Entrez query using Gene ids.
37 This module requires the CPAN Bio::ASN1 module.
39 WARNING: Please do NOT spam the Entrez web server with multiple requests.
40 NCBI offers Batch Entrez for this purpose.
42 =head1 NOTES
44 The Entrez eutils API does not allow Entrez Gene queries by name as
45 of this writing, therefore there are only get_Seq_by_id and
46 get_Stream_by_id methods in this module, and these expect Gene ids.
47 There are no get_Seq_by_acc or get_Stream_by_acc methods.
49 =head1 FEEDBACK
51 =head2 Mailing Lists
53 User feedback is an integral part of the
54 evolution of this and other Bioperl modules. Send
55 your comments and suggestions preferably to one
56 of the Bioperl mailing lists. Your participation
57 is much appreciated.
59 bioperl-l@bioperl.org - General discussion
60 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
62 =head2 Reporting Bugs
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 the bugs and their resolution. Bug reports can be submitted via the
66 web:
68 http://bugzilla.open-bio.org/
70 =head1 AUTHOR - Brian Osborne
72 Email bosborne at alum.mit.edu
74 =head1 APPENDIX
76 The rest of the documentation details each of the object
77 methods. Internal methods are usually preceded with a _
79 =cut
81 # Let the code begin...
83 package Bio::DB::EntrezGene;
84 use strict;
85 use vars qw($DEFAULTFORMAT $DEFAULTMODE %PARAMSTRING);
87 use base qw(Bio::DB::NCBIHelper);
88 BEGIN {
89 $DEFAULTMODE = 'single';
90 $DEFAULTFORMAT = 'asn.1';
91 %PARAMSTRING = ('batch' => {'db' => 'gene',
92 'usehistory' => 'y',
93 'tool' => 'bioperl',
94 'retmode' => 'asn.1'},
95 'gi' => {'db' => 'gene',
96 'usehistory' => 'y',
97 'tool' => 'bioperl',
98 'retmode' => 'asn.1'},
99 'version' => {'db' => 'gene',
100 'usehistory' => 'y',
101 'tool' => 'bioperl',
102 'retmode' => 'asn.1'},
103 'single' => {'db' => 'gene',
104 'usehistory' => 'y',
105 'tool' => 'bioperl',
106 'retmode' => 'asn.1'} );
109 # the new way to make modules a little more lightweight
110 sub new {
111 my($class, @args) = @_;
112 my $self = $class->SUPER::new(@args);
113 # Seems that Bio::SeqIO::entrezgene requires this:
114 $self->{_retrieval_type} = "tempfile";
115 $self->request_format($self->default_format);
116 return $self;
119 =head2 get_params
121 Title : get_params
122 Usage : my %params = $self->get_params($mode)
123 Function: Returns key,value pairs to be passed to NCBI database
124 for either 'batch' or 'single' sequence retrieval method
125 Returns : A key,value pair hash
126 Args : 'single' or 'batch' mode for retrieval
128 =cut
130 sub get_params {
131 my ($self, $mode) = @_;
132 return defined $PARAMSTRING{$mode} ? %{$PARAMSTRING{$mode}} :
133 %{$PARAMSTRING{$DEFAULTMODE}};
136 =head2 default_format
138 Title : default_format
139 Usage : my $format = $self->default_format
140 Function: Returns default sequence format for this module
141 Returns : string
142 Args : none
144 =cut
146 sub default_format {
147 return $DEFAULTFORMAT;
150 # from Bio::DB::WebDBSeqI from Bio::DB::RandomAccessI
152 =head1 Routines from Bio::DB::WebDBSeqI and Bio::DB::RandomAccessI
154 =head2 get_Seq_by_id
156 Title : get_Seq_by_id
157 Usage : $seq = $db->get_Seq_by_id(2)
158 Function: Gets a Bio::Seq object by its name
159 Returns : A Bio::Seq object
160 Args : Gene id
161 Throws : "id does not exist" exception
163 =head1 Routines implemented by Bio::DB::NCBIHelper
165 =head2 get_request
167 Title : get_request
168 Usage : my $url = $self->get_request
169 Function: HTTP::Request
170 Returns :
171 Args : %qualifiers = a hash of qualifiers (ids, format, etc)
173 =head2 get_Stream_by_id
175 Title : get_Stream_by_id
176 Usage : $stream = $db->get_Stream_by_id( [$gid1, $gid2] );
177 Function: Gets a series of Seq objects using Gene ids
178 Returns : A Bio::SeqIO stream object
179 Args : A reference to an array of Gene ids
181 =head2 request_format
183 Title : request_format
184 Usage : my $format = $self->request_format;
185 $self->request_format($format);
186 Function: Get or set sequence format retrieval
187 Returns : String representing format
188 Args : $format = sequence format
190 =cut
192 # override to force format
193 sub request_format {
194 my ($self) = @_;
195 return $self->SUPER::request_format($self->default_format());
200 __END__