181
#### genetic code id for translations ####
184
if($_[0] =~ /^\d+$/ && $_[0] >= 1 && $_[0] <=15 && $_[0] != 7
186
$self->{'_gc'} = shift;
189
$self->warn("invalid genetic code index - setting to standard default (1)");
193
return $self->{'_gc'} || 1; #return 1 if not defined
181
#### genetic code id for translations ####
184
if ( $_[0] =~ /^\d+$/
190
$self->{'_gc'} = shift;
194
"invalid genetic code index - setting to standard default (1)");
198
return $self->{'_gc'} || 1; #return 1 if not defined
198
202
=head2 get_request
200
204
Title : get_request
201
205
Usage : my $cut = $db->get_request();
202
206
Purpose: To query remote CUT with a species name
203
Returns: a new codon usage table object
207
Returns: a new codon usage table object
204
208
Args : species name(mandatory), genetic code id(optional)
208
212
sub get_request {
209
my ($self, @args) = @_;
212
### can put in parameters here as well
213
my ( $self, @args ) = @_;
216
### can put in parameters here as well
216
220
$self->$key(shift);
220
###1st of all search DB to check species exists and is unique
221
my $nameparts = join "+", $self->sp =~ /(\S+)/g;
222
my $search_url = $self->url . "/codon/cgi-bin/spsearch.cgi?species="
223
. $nameparts . "&c=s";
224
my $rq = HTTP::Request->new(GET=>$search_url);
225
my $reply = $self->request($rq);
226
if ($reply->is_error) {
227
$self->throw($reply->as_string()."\nError getting for url $search_url!\n");
229
my $content = $reply->content;
230
return 0 unless $content;
231
$self->debug (" reply from query is \n $content");
232
##### if no matches, assign defaults - or can throw here? ######
233
if ($content =~ /not found/i) {
234
$self->warn("organism not found -selecting human [9606] as default");
240
my @names = $content =~ /species=([^"]+)/g;
241
### get 1st species data from report ####
224
###1st of all search DB to check species exists and is unique
225
my $nameparts = join "+", $self->sp =~ /(\S+)/g;
227
$self->url . "/codon/cgi-bin/spsearch.cgi?species=" . $nameparts . "&c=s";
228
my $rq = HTTP::Request->new( GET => $search_url );
229
my $reply = $self->request($rq);
230
if ( $reply->is_error ) {
232
$reply->as_string() . "\nError getting for url $search_url!\n" );
234
my $content = $reply->content;
235
return 0 unless $content;
236
$self->debug(" reply from query is \n $content");
237
##### if no matches, assign defaults - or can throw here? ######
238
if ( $content =~ /not found/i ) {
239
$self->warn("organism not found -selecting human [9606] as default");
245
my @names = $content =~ /species=([^"]+)/g;
246
### get 1st species data from report ####
242
247
my @dbs = $content =~ /\[([^\]]+)\]:\s+\d+/g;
243
## warn if more than 1 matching species ##
244
## if multiple species retrieved, choose first one by default ##
248
## warn if more than 1 matching species ##
249
## if multiple species retrieved, choose first one by default ##
245
250
$self->throw("No names returned for $nameparts") unless @names;
247
$self->warn ("too many species - not a unique species id\n".
248
"selecting $names[0] using database [$dbs[0]]");
250
### now assign species and database value
251
$self->sp($names[0]);
256
######## now get codon table , all defaults established now
259
$nameparts = $self->sp;
261
my $CT_url = $self->url . "/codon/cgi-bin/showcodon.cgi?species="
262
. $nameparts . "&aa=" . $self->gc . "&style=GCG";
252
$self->warn( "too many species - not a unique species id\n"
253
. "selecting $names[0] using database [$dbs[0]]" );
255
### now assign species and database value
256
$self->sp( $names[0] );
257
$self->_db( $dbs[0] );
260
######## now get codon table , all defaults established now
263
$nameparts = $self->sp;
267
. "/codon/cgi-bin/showcodon.cgi?species="
268
. $nameparts . "&aa="
263
271
$self->debug("URL : $CT_url\n");
264
## retrieve data in html##
265
my $rq2 = HTTP::Request->new(GET => $CT_url);
272
## retrieve data in html##
273
my $rq2 = HTTP::Request->new( GET => $CT_url );
266
274
$reply = $self->request($rq2);
267
if ($reply->is_error) {
268
$self->throw($reply->as_string()."\nError getting for url $CT_url!\n");
275
if ( $reply->is_error ) {
277
$reply->as_string() . "\nError getting for url $CT_url!\n" );
270
my $content2 = $reply->content;
272
## strip html tags, basic but works here
273
$content2 =~ s/<[^>]+>//sg;
274
$content2 =~ s/Format.*//sg;
275
$self->debug ("raw DDB table is :\n $content2");
277
### and pass to Bio::CodonUsage::IO for parsing
278
my $iostr = IO::String->new($content2);
279
my $io = Bio::CodonUsage::IO->new (-fh=>$iostr);
282
return $io->next_data;
279
my $content2 = $reply->content;
281
## strip html tags, basic but works here
282
$content2 =~ s/<[^>]+>//sg;
283
$content2 =~ s/Format.*//sg;
284
$self->debug("raw DDB table is :\n $content2");
286
### and pass to Bio::CodonUsage::IO for parsing
287
my $iostr = IO::String->new($content2);
288
my $io = Bio::CodonUsage::IO->new( -fh => $iostr );
291
return $io->next_data;
285
294
sub _check_args {
287
###checks parameters for matching $QUERYKEYS
289
while (my $key = shift @args) {
296
###checks parameters for matching $QUERYKEYS
298
while ( my $key = shift @args ) {
293
if (!exists ($QUERY_KEYS->{$key})) {
294
Bio::Root::Root->throw("invalid parameter - must be one of [" .
295
(join "] [", keys %$QUERY_KEYS) . "]");
302
if ( !exists( $QUERY_KEYS->{$key} ) ) {
303
Bio::Root::Root->throw( "invalid parameter - must be one of ["
304
. ( join "] [", keys %$QUERY_KEYS )
301
311
#### internal URL parameter not specifiable ######
305
$self->{'_db'} = shift;
307
return $self->{'_db'};
315
$self->{'_db'} = shift;
317
return $self->{'_db'};