blib/lib/Bio/DB/SoapEUtilities.pm untested

filter: Statementstmt 0.0% 0 / 196 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 68 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 25 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 363 CC 30 SCAR 42.8
CC
30
Cov
0%
run
210.0
AUTOLOAD
90.0
_soap_facs
12.0
CRAP 72.0
1 # $Id$
2 #
3 # BioPerl module for Bio::DB::SoapEUtilities
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Mark A. Jensen <maj -at- fortinbras -dot- us>
8 #
9 # Copyright Mark A. Jensen
10 #
11 # You may distribute this module under the same terms as perl itself
12  
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::DB::SoapEUtilities - Interface to the NCBI Entrez web service *BETA*
18  
19 =head1 SYNOPSIS
20  
21 use Bio::DB::SoapEUtilities;
22  
23 # factory construction
24  
25 my $fac = Bio::DB::SoapEUtilities->new()
26  
27 # executing a utility call
28  
29 #get an iteratable adaptor
30 my $links = $fac->elink(
31 -dbfrom => 'protein',
32 -db => 'taxonomy',
33 -id => \@protein_ids )->run(-auto_adapt => 1);
34  
35 # get a Bio::DB::SoapEUtilities::Result object
36 my $result = $fac->esearch(
37 -db => 'gene',
38 -term => 'sonic and human')->run;
39  
40 # get the raw XML message
41 my $xml = $fac->efetch(
42 -db => 'gene',
43 -id => \@gids )->run( -raw_xml => 1 );
44  
45 # change parameters
46 my $new_result = $fac->efetch(
47 -db => 'gene',
48 -id => \@more_gids)->run;
49 # reset parameters
50 $fac->efetch->reset_parameters( -db => 'nucleotide',
51 -id => $nucid );
52 $result = $fac->efetch->run;
53
54 # parsing and iterating the results
55  
56 $count = $result->count;
57 @ids = $result->ids;
58
59 while ( my $linkset = $links->next_link ) {
60 $submitted = $linkset->submitted_id;
61 }
62
63 ($taxid) = $links->id_map($submitted_prot_id);
64 $species_io = $fac->efetch( -db => 'taxonomy',
65 -id => $taxid )->run( -auto_adapt => 1);
66 $species = $species_io->next_species;
67 $linnaeus = $species->binomial;
68  
69 =head1 DESCRIPTION
70  
71 This module allows the user to query the NCBI Entrez database via its
72 SOAP (Simple Object Access Protocol) web service (described at
73 L<http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/DOC/esoap_help.html>).
74 The basic tools (C<einfo, esearch, elink, efetch, espell, epost>) are
75 available as methods off a C<SoapEUtilities> factory
76 object. Parameters for each tool can be queried, set and reset for
77 each method through the L<Bio::ParameterBaseI> standard calls
78 (C<available_parameters(), set_parameters(), get_parameters(),
79 reset_parameters()>). Returned data can be retrieved, accessed and
80 parsed in several ways, according to user preference. Adaptors and
81 object iterators are available for C<efetch>, C<egquery>, C<elink>,
82 and C<esummary> results.
83  
84 =head1 USAGE
85  
86 The C<SoapEU> system has been designed to be as easy (few includes,
87 available parameter facilities, reasonable defaults, intuitive
88 aliases, built-in pipelines) or as complex (accessors for underlying
89 low-level objects, all parameters accessible, custom hooks for builder
90 objects, facilities for providing local copies of WSDLs) as the user
91 requires or desires. (To the extent that it does not succeed in either
92 direction, it is up to the user to report to the mailing list
93 (L</FEEDBACK>)!)
94  
95 =head2 Factory
96  
97 To begin, make a factory:
98  
99 my $fac = Bio::DB::SoapEUtilities->new();
100  
101 From the factory, utilities are called, parameters are set, and
102 results or adaptors are retrieved.
103  
104 If you have your own copy of the wsdl, use
105  
106 my $fac = Bio::Db::SoapEUtilities->new( -wsdl_file => $my_wsdl );
107  
108 otherwise, the correct one will be obtained over the network (by
109 L<Bio::DB::ESoap> and friends).
110  
111 =head2 Utilities and parameters
112  
113 To run any of the standard NCBI EUtilities (C<einfo, esearch, esummary,
114 elink, egquery, epost, espell>), call the desired utility from the factory.
115 To use a utility, you must set its parameters and run it to get a result.
116 TMTOWTDI:
117  
118 # verbose
119 my $fetch = $fac->efetch();
120 $fetch->set_parameters( -db => 'gene', -id => [828392, 790]);
121 my $result = $fetch->run;
122  
123 # compact
124 my $result = $fac->efetch(-db =>'gene',-id => [828392,790])->run;
125  
126 # change ids
127 $fac->efetch->set_parameters( -id => 470338 );
128 $result = $fac->run;
129  
130 # another util
131 $result = $fac->esearch(-db => 'protein', -term => 'BRCA and human')->run;
132
133 # the utilities are kept separate
134 %search_params = $fac->esearch->get_parameters;
135 %fetch_params = $fac->efetch->get_parameters;
136 $search_param{db}; # is 'protein'
137 $fetch_params{db}; # is 'gene'
138
139 The factory is L<Bio::ParameterBaseI> compliant: that means you can
140 find out what you can set with
141
142 @available_search = $fac->esearch->available_parameters;
143 @available_egquery = $fac->egquery->available_parameters;
144  
145 For more information on parameters, see
146 L<http://www.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.html>.
147  
148 =head2 Results
149  
150 The "intermediate" object for C<SoapEU> query results is the
151 L<Bio::DB::SoapEUtilities::Result>. This is a BioPerly parsing of the
152 SOAP message sent by NCBI when a query is C<run()>. This can be very
153 useful on it's own, but most users will likely want to proceed
154 directly to L</Adaptors>, which take a C<Result> and turn it into more
155 intuitive/familiar BioPerl objects. Go there if the following details
156 are too gory.
157  
158 Results can be highly- or lowly-parsed, depending on the parameters
159 passed to the factory C<run()> method. To get the raw XML message with
160 no parsing, do
161  
162 my $xml = $fac->$util->run(-raw_xml => 1); # $xml is a scalar string
163  
164 To retrieve a L<Bio::DB::SoapEUtilities::Result> object with limited
165 parsing, but with accessors to the L<SOAP::SOM> message (provided by
166 L<SOAP::Lite>), do
167  
168 my $result = $fac->$util->run(-no_parse => 1);
169 my $som = $result->som;
170 my $method_hash = $som->method; # etc...
171  
172 To retrieve a C<Result> object with message elements parsed into
173 accessors, including C<count()> and C<ids()>, run without arguments:
174  
175 my $result = $fac->esearch->run()
176 my $count = $result->count;
177 my @Count = $result->Count; # counts for each member of
178 # the translation stack
179 my @ids = $result->IdList_Id; # from automatic message parsing
180 @ids = $result->ids; # a convenient alias
181  
182 See L<Bio::DB::SoapEUtilities::Result> for more, even gorier details.
183  
184 =head2 Adaptors
185  
186 Adaptors convert EUtility C<Result>s into convenient objects, via a
187 handle that usually provides an iterator, in the spirit of
188 L<Bio::SeqIO>. These are probably more useful than the C<Result> to
189 the typical user, and so you can retrieve them automatically by
190 setting the C<run()> parameter C<-auto_adapt => 1>.
191  
192 In general, retrieve an adaptor like so:
193  
194 $adp = $fac->$util->run( -auto_adapt => 1 );
195 # iterate...
196 while ( my $obj = $adp->next_obj ) {
197 # do stuff with $obj
198 }
199  
200 The adaptor itself occasionally possesses useful methods besides the
201 iterator. The method C<next_obj> always works, but a natural alias is
202 also always available:
203  
204 $seqio = $fac->esearch->run( -auto_adapt => 1 );
205 while ( my $seq = $seqio->next_seq ) {
206 # do stuff with $seq
207 }
208  
209 In the above example, C<-auto_adapt => 1> also instructs the factory
210 to perform an C<efetch> based on the ids returned by the C<esearch>
211 (if any), so that the adaptor returned iterates over L<Bio::SeqI>
212 objects.
213  
214 Here is a rundown of the different adaptor flavors:
215  
216 =over
217  
218 =item * C<efetch>, Fetch Adaptors, and BioPerl object iterators
219  
220 The C<FetchAdaptor> creates bona fide BioPerl objects. Currently,
221 there are FetchAdaptor subclasses for sequence data (both Genbank and
222 FASTA rettypes) and taxonomy data. The choice of FetchAdaptor is based
223 on information in the result message, and should be transparent to the
224 user.
225  
226 $seqio = $fac->efetch( -db =>'nucleotide',
227 -id => \@ids,
228 -rettype => 'gb' )->run( -auto_adapt => 1 );
229 while (my $seq = $seqio->next_seq) {
230 my $taxio = $fac->efetch(
231 -db => 'taxonomy',
232 -id => $seq->species->ncbi_taxid )->run(-auto_adapt => 1);
233 my $tax = $taxio->next_species;
234 unless ( $tax->TaxId == $seq->species->ncbi_taxid ) {
235 print "more work for MAJ"
236 }
237 }
238  
239 See the pod for the FetchAdaptor subclasses (e.g.,
240 L<Bio::DB::SoapEUtilities::FetchAdaptor::seq>) for more detail.
241  
242 =item * C<elink>, the Link adaptor, and the C<linkset> iterator
243  
244 The C<LinkAdaptor> manages LinkSets. In C<SoapEU>, an C<elink> call
245 B<always> preserves the correspondence between submitted and retrieved
246 ids. The mapping between these can be accessed from the adaptor object
247 directly as C<id_map()>
248  
249 my $links = $fac->elink( -db => 'protein',
250 -dbfrom => 'nucleotide',
251 -id => \@nucids )->run( -auto_adapt => 1 );
252  
253 # maybe more than one associated id...
254 my @prot_0 = $links->id_map( $nucids[0] );
255
256 Or iterate over the linksets:
257
258 while ( my $ls = $links->next_linkset ) {
259 @ids = $ls->ids;
260 @submitted_ids = $ls->submitted_ids;
261 # etc.
262 }
263  
264 =item * C<esummary>, the DocSum adaptor, and the C<docsum> iterator
265  
266 The C<DocSumAdaptor> manages docsums, the C<esummary> return type.
267 The objects returned by iterating with a C<DocSumAdaptor> have
268 accessors that let you obtain field information directly. Docsums
269 contain lots of easy-to-forget fields; use C<item_names()> to remind yourself.
270  
271 my $docs = $fac->esummary( -db => 'taxonomy',
272 -id => 527031 )->run(-auto_adapt=>1);
273 # iterate over docsums
274 while (my $d = $docs->next_docsum) {
275 @available_items = $docsum->item_names;
276 # any available item can be called as an accessor
277 # from the docsum object...watch your case...
278 $sci_name = $d->ScientificName;
279 $taxid = $d->TaxId;
280 }
281  
282 =item * C<egquery>, the GQuery adaptor, and the C<query> iterator
283  
284 The C<GQueryAdaptor> manages global query items returned by calls to
285 C<egquery>, which identifies all NCBI databases containing hits for
286 your query term. The databases actually containing hits can be
287 retrieved directly from the adaptor with C<found_in_dbs>:
288  
289 my $queries = $fac->egquery(
290 -term => 'BRCA and human'
291 )->run(-auto_adapt=>1);
292 my @dbs = $queries->found_in_dbs;
293  
294 Retrieve the global query info returned for B<any> database with C<query_by_db>:
295
296 my $prot_q = $queries->query_by_db('protein');
297 if ($prot_q->count) {
298 #do something
299 }
300  
301 Or iterate as usual:
302  
303 while ( my $q = $queries->next_query ) {
304 if ($q->status eq 'Ok') {
305 # do sth
306 }
307 }
308  
309 =back
310  
311 =head2 Web environments and query keys
312  
313 To make large or complex requests for data, or to share queries, it
314 may be helpful to use the NCBI WebEnv system to manage your
315 queries. Each EUtility accepts the following parameters:
316  
317 -usehistory
318 -WebEnv
319 -QueryKey
320  
321 for this purpose. These store the details of your queries serverside.
322  
323 C<SoapEU> attempts to make using these relatively straightforward. Use
324 C<Result> objects to obtain the correct parameters, and don't forget
325 C<-usehistory>:
326  
327 my $result1 = $fac->esearch(
328 -term => 'BRCA and human',
329 -db => 'nucleotide',
330 -usehistory => 1 )->run( -no_parse=>1 );
331  
332 my $result = $fac->esearch(
333 -term => 'AND early onset',
334 -QueryKey => $result1->query_key,
335 -WebEnv => $result1->webenv )->run( -no_parse => 1 );
336  
337 my $result = $fac->esearch(
338 -db => 'protein',
339 -term => 'sonic',
340 -usehistory => 1 )->run( -no_parse => 1 );
341  
342 # later (but not more than 8 hours later) that day...
343  
344 $result = $fac->esearch(
345 -WebEnv => $result->webenv,
346 -QueryKey => $result->query_key,
347 -RetMax => 800 # get 'em all
348 )->run; # note we're parsing the result...
349 @all_ids = $result->ids;
350  
351 =head2 Error checking
352  
353 Two kinds of errors can ensue on an Entrez SOAP run. One is a SOAP
354 fault, and the other is an error sent in non-faulted SOAP message from
355 the server. The distinction is probably systematic, and I would
356 welcome an explanation of it. To check for result errors, try something like:
357  
358 unless ( $result = $fac->$util->run ) {
359 die $fac->errstr; # this will catch a SOAP fault
360 }
361 # a valid result object was returned, but it may carry an error
362 if ($result->count == 0) {
363 warn "No hits returned";
364 if ($result->ERROR) {
365 warn "Entrez error : ".$result->ERROR;
366 }
367 }
368  
369 Error handling will be improved in the package eventually.
370  
371 =head1 SEE ALSO
372  
373 L<Bio::DB::EUtilities>, L<Bio::DB::SoapEUtilities::Result>,
374 L<Bio::DB::ESoap>.
375  
376 =head1 FEEDBACK
377  
378 =head2 Mailing Lists
379  
380 User feedback is an integral part of the evolution of this and other
381 Bioperl modules. Send your comments and suggestions preferably to
382 the Bioperl mailing list. Your participation is much appreciated.
383  
384 bioperl-l@bioperl.org - General discussion
385 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
386  
387 =head2 Support
388  
389 Please direct usage questions or support issues to the mailing list:
390  
391 L<bioperl-l@bioperl.org>
392  
393 rather than to the module maintainer directly. Many experienced and
394 reponsive experts will be able look at the problem and quickly
395 address it. Please include a thorough description of the problem
396 with code and data examples if at all possible.
397  
398 =head2 Reporting Bugs
399  
400 Report bugs to the Bioperl bug tracking system to help us keep track
401 of the bugs and their resolution. Bug reports can be submitted via
402 the web:
403  
404 http://redmine.open-bio.org/projects/bioperl/
405  
406 =head1 AUTHOR - Mark A. Jensen
407  
408 Email maj -at- fortinbras -dot- us
409  
410 =head1 APPENDIX
411  
412 The rest of the documentation details each of the object methods.
413 Internal methods are usually preceded with a _
414  
415 =cut
416  
417 package Bio::DB::SoapEUtilities;
418 use strict;
419  
420 use Bio::Root::Root;
421 use Bio::DB::ESoap;
422 use Bio::DB::SoapEUtilities::DocSumAdaptor;
423 use Bio::DB::SoapEUtilities::FetchAdaptor;
424 use Bio::DB::SoapEUtilities::GQueryAdaptor;
425 use Bio::DB::SoapEUtilities::LinkAdaptor;
426 use Bio::DB::SoapEUtilities::Result;
427  
428 use base qw(Bio::Root::Root Bio::ParameterBaseI );
429  
430 our $AUTOLOAD;
431  
432 =head2 new
433  
434 Title : new
435 Usage : my $eutil = new Bio::DB::SoapEUtilities();
436 Function: Builds a new Bio::DB::SoapEUtilities object
437 Returns : an instance of Bio::DB::SoapEUtilities
438 Args :
439  
440 =cut
441  
442 sub new {
443 my ($class,@args) = @_;
444 my $self = $class->SUPER::new(@args);
445 my ($db, $wsdl) = $self->_rearrange( [qw( DB WSDL_FILE )], @args );
446 $self->{db} = $db;
447 $self->{'_wsdl_file'} = $wsdl;
448  
449 return $self;
450 }
451  
452 =head2 run()
453  
454 Title : run
455 Usage : $fac->$eutility->run(@args)
456 Function: Execute the EUtility
457 Returns : true on success, false on fault or error
458 (reason in errstr(), for more detail check the SOAP message
459 in last_result() )
460 Args : named params appropriate to utility
461 -auto_adapt => boolean ( return an iterator over results as
462 appropriate to util if true)
463 -raw_xml => boolean ( return raw xml result; no processing )
464 Bio::DB::SoapEUtilities::Result constructor parms
465  
466 =cut
467  
468 sub run {
469 my $self = shift;
470 my @args = @_;
471 $self->throw("run method requires named arguments") if @args % 2;
472 $self->throw("call run method like '\$fac->\$eutility->run(\@args)") unless
473 $self->_caller_util;
474 my ($autofetch, $raw_xml) = $self->_rearrange( [qw( AUTO_ADAPT RAW_XML)],
475 @args );
476 my ($adaptor);
477 my %args = @args;
478 # add tool argument for NCBI records
479 $args{tool} = "BioPerl";
480 my %params = $self->get_parameters;
481 $self->warn("No -email parameter set : be advised that NCBI requires a valid email to accompany all requests") unless $params{email};
482 my $util = $self->_caller_util;
483 # pass util args to run only to a downstream utility (i.e., efetch
484 # on autofetch..
485 # $self->set_parameters(%args) if %args;
486 # kludge for elink : make sure to-ids and from-ids are associated
487 if ( $util eq 'elink' ) {
488 my $es = $self->_soap_facs($util);
489 my $ids = $es->id;
490 if (ref $ids eq 'ARRAY') {
491 my %ids;
492 @ids{@$ids} = (1) x scalar @$ids;
493 $es->id(\%ids);
494 }
495 }
496 $self->_soap_facs($util)->_client->outputxml($raw_xml);
497 my $som = $self->{'_response_message'} = $self->_soap_facs($util)->run;
498 # raw xml only...
499 if ($raw_xml) {
500 return $som;
501 }
502 # SOAP::SOM parsing...
503 # check response status
504 if ($som->fault) {
505 $self->{'errstr'} = $som->faultstring;
506 return 0;
507 }
508 # elsif non-fault error
509 if (my $err = $som->valueof("//ErrorList")) {
510 while ( my ($key, $val) = each %$err ) {
511 $self->{'errstr'} .= join( " : ", $key, $val )."\n";
512 };
513 $self->{'errstr'} =~ s/\n$//;
514 return 0;
515 }
516 # attach some key properties to the factory
517 $self->{'_WebEnv'} = $som->valueof("//WebEnv");
518 # create convenient aliases off result for different utils
519 my @alias_hash;
520 for ($util) {
521 /einfo/ && do {
522 my %args = $self->get_parameters;
523 if ($args{db}) {
524 push @alias_hash, (
525 '-alias_hash' => {
526 'record_count' => 'DbInfo_Count',
527 'last_update' => 'DbInfo_LastUpdate',
528 'db' => 'DbInfo_DbName',
529 'description' => 'DbInfo_Description'
530 } );
531 }
532 else {
533 push @alias_hash, ('-alias_hash' => {'dbs' => 'DbList_DbName'} );
534 }
535 last;
536 };
537 # put others here as nec
538 }
539 my $result = Bio::DB::SoapEUtilities::Result->new($self, @args,
540 @alias_hash);
541  
542 # success, parse it out
543 if ($autofetch) {
544 for ($self->_caller_util) {
545 $_ eq 'esearch' && do {
546 # do an efetch with the same db and a returned list of ids...
547 # reentering here!
548 my $ids = $result->ids;
549 if (!$result->count) {
550 $self->warn("Can't fetch; no records returned");
551 return $result;
552 }
553 if (!$result->ids) {
554 $self->warn("Can't fetch; no id list returned");
555 return $result;
556 }
557 if ( !$self->db ) {
558 my %h = $self->get_parameters;
559 $self->{db} = $h{db} || $h{DB};
560 }
561 # pass run() args to the downstream utility here
562 # (so can specify -rettype, basically)
563 # note @args will contain -auto_adapt => 1 here.
564  
565 # keep the email arg
566 my %parms = $self->get_parameters;
567 $adaptor = $self->efetch( -db => $self->db,
568 -id => $ids,
569 -email => $parms{email},
570 -tool => $parms{tool},
571 @args )->run(-no_parse => 1, @args);
572 last;
573 };
574 $_ eq 'elink' && do {
575 $adaptor = Bio::DB::SoapEUtilities::LinkAdaptor->new(
576 -result => $result
577 );
578 last;
579 };
580 $_ eq 'esummary' && do {
581 $adaptor = Bio::DB::SoapEUtilities::DocSumAdaptor->new(
582 -result => $result
583 );
584 last;
585 };
586 $_ eq 'egquery' && do {
587 $adaptor = Bio::DB::SoapEUtilities::GQueryAdaptor->new(
588 -result => $result
589 );
590 last;
591 };
592 $_ eq 'efetch' && do {
593 $adaptor = Bio::DB::SoapEUtilities::FetchAdaptor->new(
594 -result => $result
595 );
596 last;
597 };
598 # else, ignore
599 }
600 return ($adaptor || $result);
601 }
602 else {
603 return $result;
604 1;
605 }
606 }
607  
608 =head2 Useful Accessors
609  
610 =head2 response_message()
611  
612 Title : response_message
613 Aliases : last_response, last_result
614 Usage : $som = $fac->response_message
615 Function: get the last response message
616 Returns : a SOAP::SOM object
617 Args : none
618  
619 =cut
620  
621 sub response_message { shift->{'_response_message'} }
622 sub last_response { shift->{'_response_message'} }
623 sub last_result { shift->{'_response_message'} }
624  
625 =head2 webenv()
626  
627 Title : webenv
628 Usage :
629 Function: contains WebEnv key referencing the session
630 (set after run() )
631 Returns : scalar
632 Args : none
633  
634 =cut
635  
636 sub webenv { shift->{'_WebEnv'} }
637  
638 =head2 errstr()
639  
640 Title : errstr
641 Usage : $fac->errstr
642 Function: get the last error, if any
643 Example :
644 Returns : value of errstr (a scalar)
645 Args : none
646  
647 =cut
648  
649 sub errstr { shift->{'errstr'} }
650  
651 sub _wsdl_file { shift->{'_wsdl_file'} }
652  
653 =head2 Bio::ParameterBaseI compliance
654  
655 =head2 available_parameters()
656  
657 Title : available_parameters
658 Usage :
659 Function: get available request parameters for calling
660 utility
661 Returns :
662 Args : -util => $desired_utility [optional, default is
663 caller utility]
664  
665 =cut
666  
667 sub available_parameters {
668 my $self = shift;
669 my @args = @_;
670 my %args = @args;
671 my $util = $args{'-util'} || $args{'-UTIL'} || $self->_caller_util;
672 return unless $self->_soap_facs($util);
673 delete $args{'-util'};
674 delete $args{'-UTIL'};
675 $self->_soap_facs($util)->available_parameters(%args);
676 }
677  
678 =head2 set_parameters()
679  
680 Title : set_parameters
681 Usage :
682 Function:
683 Returns : none
684 Args : -util => $desired_utility [optional, default is
685 caller utility],
686 named utility arguments
687  
688 =cut
689  
690 sub set_parameters {
691 my $self = shift;
692 my @args = @_;
693 my %args = @args;
694 my $util = $args{'-util'} || $args{'-UTIL'} || $self->_caller_util;
695 return unless $self->_soap_facs($util);
696 delete $args{'-util'};
697 delete $args{'-UTIL'};
698 $self->_soap_facs($util)->set_parameters(%args);
699 }
700  
701 =head2 get_parameters()
702  
703 Title : get_parameters
704 Usage :
705 Function:
706 Returns : array of named parameters
707 Args : utility (scalar string) [optional]
708 (default is caller utility)
709  
710 =cut
711  
712 sub get_parameters {
713 my $self = shift;
714 my @args = @_;
715 my %args = @args;
716 my $util = $args{'-util'} || $args{'-UTIL'} || $self->_caller_util;
717 return unless $self->_soap_facs($util);
718 return $self->_soap_facs($util)->get_parameters;
719 }
720  
721 =head2 reset_parameters()
722  
723 Title : reset_parameters
724 Usage :
725 Function:
726 Returns : none
727 Args : -util => $desired_utility [optional, default is
728 caller utility],
729 named utility arguments
730  
731 =cut
732  
733 sub reset_parameters {
734 my $self = shift;
735 my @args = @_;
736 my %args = @args;
737 my $util = $args{'-util'} || $args{'-UTIL'} || $self->_caller_util;
738 return unless $self->_soap_facs($util);
739 delete $args{'-util'};
740 delete $args{'-UTIL'};
741 $self->_soap_facs($util)->reset_parameters(%args);
742 }
743  
744 =head2 parameters_changed()
745  
746 Title : parameters_changed
747 Usage :
748 Function:
749 Returns : boolean
750 Args : utility (scalar string) [optional]
751 (default is caller utility)
752  
753 =cut
754  
755 sub parameters_changed {
756 my $self = shift;
757 my @args = @_;
758 my %args = @args;
759 my $util = $args{'-util'} || $args{'-UTIL'} || $self->_caller_util;
760 return unless $self->_soap_facs($util);
761 return $self->_soap_facs($util)->parameters_changed;
762 }
763  
764 # idea behind using autoload: attempt to buffer the module
765 # against additions of new eutilities, and (of course) to
766 # reduce work (laziness, not Laziness)
767  
768 sub AUTOLOAD {
769 my $self = shift;
770 my $util = $AUTOLOAD;
771 my @args = @_;
772 $util =~ s/.*:://;
773  
774 if ( $util =~ /^e/ ) { # this will bite me someday
775 # create an ESoap factory for this utility
776 my $fac = $self->_soap_facs($util); # check cache
777 my @pms = ( -util => $util );
778 if ($self->_wsdl_file) {
779 push @pms, ( -wsdl_file => $self->_wsdl_file );
780 }
781 eval {
782 $fac ||= Bio::DB::ESoap->new( @pms );
783 };
784 for ($@) {
785 /^$/ && do {
786 $self->_soap_facs($util,$fac); # put in cache
787 last;
788 };
789 /Utility .* not recognized/ && do {
790 my $err = (ref $@ ? $@->text : $@);
791 $self->throw($err);
792 };
793 do { #else
794 my $err = (ref $@ ? $@->text : $@);
795 die $err;
796 $self->throw("Problem creating ESoap client : $err");
797 };
798 }
799 # arg setting
800 $self->throw("Named arguments required") if @args % 2;
801 $fac->set_parameters(@args) if @args;
802 $self->_caller_util($util);
803 return $self; # now, can do $obj->esearch()->run, etc, with methods in
804 # this package, with an appropriate low-level factory
805 # set up in the background.
806 }
807 elsif ($self->_caller_util) {
808 # delegate to the appropriate soap factory
809 my $method = $util;
810 $util = $self->_caller_util;
811 my $soapfac = $self->_soap_facs($util);
812 if ( $soapfac && $soapfac->can($method) ) {
813 return $soapfac->$method(@args);
814 }
815 }
816 else {
817 $self->throw("Can't locate method '$util' in module ".
818 __PACKAGE__);
819 }
820 1;
821 }
822  
823 =head2 _soap_facs()
824  
825 Title : _soap_facs
826 Usage : $self->_soap_facs($util, $fac)
827 Function: caches Bio::DB::ESoap factories for the
828 eutils in use by this instance
829 Example :
830 Returns : Bio::DB::ESoap object
831 Args : $eutility, [optional on set] $esoap_factory_object
832  
833 =cut
834  
835 sub _soap_facs {
836 my $self = shift;
837 my ($util, $fac) = @_;
838 $self->throw("Utility must be specified") unless $util;
839 $self->{'_soap_facs'} ||= {};
840 if ($fac) {
841 return $self->{'_soap_facs'}->{$util} = $fac;
842 }
843 return $self->{'_soap_facs'}->{$util};
844 }
845  
846 =head2 _caller_util()
847  
848 Title : _caller_util
849 Usage : $self->_caller_util($newval)
850 Function: the utility requested off the main SoapEUtilities
851 object
852 Example :
853 Returns : value of _caller_util (a scalar string, a valid eutility)
854 Args : on set, new value (a scalar string [optional])
855  
856 =cut
857  
858 sub _caller_util {
859 my $self = shift;
860 return $self->{'_caller_util'} = shift if @_;
861 return $self->{'_caller_util'};
862 }
863 1;
864