3 # BioPerl module for Bio::DB::CUTG
5 # Cared for by Richard Adams (richard.adams@ed.ac.uk)
7 # Copyright Richard Adams
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::DB::CUTG - for access to the Codon usage Database
16 at http://www.kazusa.or.jp/codon.
20 use Bio::CodonUsage::Table;
23 my $db = Bio::DB::CUTG->new(-sp =>'Pan troglodytes');
24 my $CUT = $db->get_request();
29 This class retrieves and objectifies codon usage tables either from the
30 CUTG web database . The idea is that you can initially retrieve a CUT from
31 the web database, and write it to file in a way that can be read in
32 later, using the Bio::CodonUsage::IO module.
34 For a web query, two parameters need to be specified: species(sp) and
35 genetic code id (gc). The database is searched using regular
36 expressions, therefore the full latin name must be given to specify
37 the organism. If the species name is ambiguous the first CUT in the
38 list is retrieved. Defaults are Homo sapiens and 1(standard genetic
39 code). If you are retrieving CUTs from organisms using other genetic
40 codes this needs to be put in as a parameter. Parameters can be
41 entered in the constructor or in the get_web_request
42 ()method. Allowable parameters are listed in the $QUERY_KEYS hash
45 I intend at a later date to allow retrieval of multiple codon tables
46 e.g., from a wildcard search.
50 L<Bio::Tools::CodonTable>,
52 L<Bio::CodonUsage::Table>,
53 L<Bio::CodonUsage::IO>
60 User feedback is an integral part of the evolution of this and other
61 Bioperl modules. Send your comments and suggestions preferably to one
62 of the Bioperl mailing lists. Your participation is much appreciated.
64 bioperl-l@bioperl.org - General discussion
65 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
69 Report bugs to the Bioperl bug tracking system to help us keep track
70 the bugs and their resolution. Bug reports can be submitted via the web:
72 http://bugzilla.open-bio.org/
76 Richard Adams, Richard.Adams@ed.ac.uk
80 The rest of the documentation details each of the object
81 methods. Internal methods are usually preceded with a _
86 # Let the code begin...
90 package Bio
::DB
::CUTG
;
91 use Bio
::CodonUsage
::IO
;
94 use vars
qw($URL $QUERY_KEYS);
96 use base qw(Bio::WebAgent);
99 sp
=> 'full Latin species name',
100 gc
=> 'genetic code id'
104 $URL = "http://www.kazusa.or.jp"
111 Usage : my $db = Bio::DB::CUTG->new()
112 Returns : a reference to a new Bio::DB::CUTG
113 Args : hash of optional values for db query
118 my ($class, @args ) =@_;
120 my $self = $class->SUPER::new
(@args);
127 Usage : $db->query_keys()
128 Purpose : To determine valid keys for parameters for db query.
129 Returns : a reference to a hash describing valid query keys
141 Usage : my $sp = $db->sp();
142 Purpose: Get/set method for species name
143 Returns: void or species name string
144 Args : None or species name string
152 $self->{'_sp'} = $name;
154 return $self->{'_sp'}|| "Homo sapiens";
161 Usage : my $gc = $db->gc();
162 Purpose: Get/set method for genetic code id
163 Returns: void or genetic code integer
164 Args : None or genetic code integer
169 #### genetic code id for translations ####
172 if($_[0] =~ /^\d+$/ && $_[0] >= 1 && $_[0] <=15 && $_[0] != 7
174 $self->{'_gc'} = shift;
177 $self->warn("invalid genetic code index - setting to standard default (1)");
181 return $self->{'_gc'} || 1; #return 1 if not defined
189 Usage : my $cut = $db->get_request();
190 Purpose: To query remote CUT with a species name
191 Returns: a new codon usage table object
192 Args : species name(mandatory), genetic code id(optional)
197 my ($self, @args) = @_;
200 ### can put in parameters here as well
208 ###1st of all search DB to check species exists and is unique
209 my $nameparts = join "+", $self->sp =~ /(\w+)/g;
210 my $search_url = $self->url . "/codon/cgi-bin/spsearch.cgi?species="
211 . $nameparts . "&c=s";
212 my $rq = HTTP
::Request
->new(GET
=>$search_url);
213 my $reply = $self->request($rq);
214 if ($reply->is_error) {
215 $self->throw($reply->as_string()."\nError getting for url $search_url!\n");
217 my $content = $reply->content;
218 return 0 unless $content;
219 $self->debug (" reply from query is \n $content");
220 ##### if no matches, assign defaults - or can throw here? ######
221 if ($content =~ /not found/i) {
222 $self->warn("organism not found -selecting human [9606] as default");
228 my @names = $content =~ /species=([^"]+)/g;
229 ### get 1st species data from report ####
230 my @dbs = $content =~ /\[([^\]]+)\]:\s+\d+/g;
231 ## warn if more than 1 matching species ##
232 ## if multiple species retrieved, choose first one by default ##
233 $self->throw("No names returned for $nameparts") unless @names;
235 $self->warn ("too many species - not a unique species id\n".
236 "selecting $names[0] using database [$dbs[0]]");
238 ### now assign species and database value
239 $self->sp($names[0]);
244 ######## now get codon table , all defaults established now
247 $nameparts = $self->sp;
249 my $CT_url = $self->url . "/codon/cgi-bin/showcodon.cgi?species="
250 . $nameparts . "&aa=" . $self->gc . "&style=GCG";
251 $self->debug("URL : $CT_url\n");
252 ## retrieve data in html##
253 my $rq2 = HTTP
::Request
->new(GET
=> $CT_url);
254 $reply = $self->request($rq2);
255 if ($reply->is_error) {
256 $self->throw($reply->as_string()."\nError getting for url $CT_url!\n");
258 my $content2 = $reply->content;
260 ## strip html tags, basic but works here
261 $content2 =~ s/<[^>]+>//sg;
262 $content2 =~ s/Format.*//sg;
263 $self->debug ("raw DDB table is :\n $content2");
265 ### and pass to Bio::CodonUsage::IO for parsing
266 my $iostr = IO
::String
->new($content2);
267 my $io = Bio
::CodonUsage
::IO
->new (-fh
=>$iostr);
270 return $io->next_data;
275 ###checks parameters for matching $QUERYKEYS
277 while (my $key = lc(shift @args)) {
280 if (!exists ($QUERY_KEYS->{$key})) {
281 Bio
::Root
::Root
->throw("invalid parameter - must be one of [" .
282 (join "] [", keys %$QUERY_KEYS) . "]");
288 #### internal URL parameter not specifiable ######
292 $self->{'_db'} = shift;
294 return $self->{'_db'};