blib/lib/Bio/DB/ESoap.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Bio/Tools/Run/Ensembl.pm ↑ Summary blib/lib/Bio/Tools/Run/Meme.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::DB::ESoap
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::ESoap - Client for the NCBI Entrez EUtilities SOAP server
18  
19 =head1 SYNOPSIS
20  
21 $fac = Bio::DB::ESoap->new( -util => 'esearch' );
22 $som = $fac->run( -db => 'prot', -term => 'HIV and gp120' );
23 $fac->set_parameters( -term => 'HIV2 and gp160' );
24 # accessors corresponding to valid parameters are also created:
25 $fac->db('nuccore');
26 $som = $fac->run;
27  
28 # more later.
29
30 =head1 DESCRIPTION
31  
32 C<ESoap> provides a basic SOAP interface to the NCBI Entrez Utilities
33 Web Service
34 (L<http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/DOC/esoap_help.html>).
35 L<SOAP::Lite> handles the SOAP calls. Higher level access, pipelines,
36 BioPerl object I/O and such are provided by
37 L<Bio::DB::SoapEUtilities>.
38  
39 C<ESoap> complies with L<Bio::ParameterBaseI>. It depends explicitly
40 on NCBI web service description language files to inform the
41 C<available_parameters()> method. WSDLs are parsed by a relative
42 lightweight, Entrez-specific module L<Bio::DB::ESoap::WSDL>.
43  
44 The C<run()> method returns L<SOAP::SOM> (SOAP Message) objects. No
45 fault checking or other parsing is performed in this module.
46  
47 =head1 SEE ALSO
48  
49 L<Bio::DB::EUtilities>, L<Bio::DB::SoapEUtilities>,
50 L<Bio::DB::ESoap::WSDL>
51  
52 =head1 FEEDBACK
53  
54 =head2 Mailing Lists
55  
56 User feedback is an integral part of the evolution of this and other
57 Bioperl modules. Send your comments and suggestions preferably to
58 the Bioperl mailing list. Your participation is much appreciated.
59  
60 bioperl-l@bioperl.org - General discussion
61 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
62  
63 =head2 Support
64  
65 Please direct usage questions or support issues to the mailing list:
66  
67 L<bioperl-l@bioperl.org>
68  
69 rather than to the module maintainer directly. Many experienced and
70 reponsive experts will be able look at the problem and quickly
71 address it. Please include a thorough description of the problem
72 with code and data examples if at all possible.
73  
74 =head2 Reporting Bugs
75  
76 Report bugs to the Bioperl bug tracking system to help us keep track
77 of the bugs and their resolution. Bug reports can be submitted via
78 the web:
79  
80 http://redmine.open-bio.org/projects/bioperl/
81  
82 =head1 AUTHOR - Mark A. Jensen
83  
84 Email maj -at- fortinbras -dot- us
85  
86 =head1 APPENDIX
87  
88 The rest of the documentation details each of the object methods.
89 Internal methods are usually preceded with a _
90  
91 =cut
92  
93 # Let the code begin...
94  
95 package Bio::DB::ESoap;
96 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 2 ▶use Bio::DB::ESoap::WSDL;
Subroutine BEGIN: called CC=1 SCAR=2.6
101 use SOAP::Lite;
102  
103 use base qw(Bio::Root::Root Bio::ParameterBaseI);
104  
105 =head2 new
106  
107 Title : new
108 Usage : my $obj = new Bio::DB::ESoap();
109 Function: Builds a new Bio::DB::ESoap factory
110 Returns : an instance of Bio::DB::ESoap
111 Args :
112  
113 =cut
114  
115 sub new {
116 my ($class,@args) = @_;
117 my $self = $class->SUPER::new(@args);
118 my ($util, $fetch_db, $wsdl) = $self->_rearrange( [qw( UTIL FETCH_DB WSDL_FILE )], @args );
119 $self->throw("Argument -util must be specified") unless $util;
120 my @wsdl_pms;
121 if ($wsdl) {
122 @wsdl_pms = ( '-wsdl' => $wsdl );
123 }
124 else {
125 $fetch_db ||= 'seq';
126 my $url = ($util =~ /fetch/ ? 'f_'.$fetch_db : 'eutils');
127 $url = $NCBI_BASEURL.$WSDL{$url};
128 @wsdl_pms = ( '-url' => $url );
129 }
130 $self->_wsdl(Bio::DB::ESoap::WSDL->new(@wsdl_pms));
131 $self->_operation($util);
132 $self->_init_parameters;
133 $self->_client( SOAP::Lite->new( proxy => $self->_wsdl->service ) );
134
135 return $self;
136 }
137  
138 =head2 _wsdl()
139  
140 Title : _wsdl
141 Usage : $obj->_wsdl($newval)
142 Function: Bio::DB::ESoap::WSDL object associated with
143 this factory
144 Example :
145 Returns : value of _wsdl (object)
146 Args : on set, new value (object or undef, optional)
147  
148 =cut
149  
150 sub _wsdl {
151 my $self = shift;
152
153 return $self->{'_wsdl'} = shift if @_;
154 return $self->{'_wsdl'};
155 }
156  
157 =head2 _client()
158  
159 Title : _client
160 Usage : $obj->_client($newval)
161 Function: holds a SOAP::Lite object
162 Example :
163 Returns : value of _client (a SOAP::Lite object)
164 Args : on set, new value (a SOAP::Lite object or undef, optional)
165  
166 =cut
167  
168 sub _client {
169 my $self = shift;
170 return $self->{'_client'} = shift if @_;
171 return $self->{'_client'};
172 }
173  
174 =head2 _operation()
175  
176 Title : _operation
177 Alias : util
178 Usage :
179 Function: check and convert the requested operation based on the wsdl
180 Returns :
181 Args : operation (scalar string)
182  
183 =cut
184  
185 sub _operation {
186 my $self = shift;
187 my $util = shift;
188 return $self->{'_operation'} unless $util;
189 $self->throw("WSDL not yet initialized") unless $self->_wsdl;
190 my $opn = $self->_wsdl->operations;
191 if ( grep /^$util$/, keys %$opn ) {
192 return $self->{'_operation'} = $util;
193 }
194 elsif ( grep /^$util$/, values %$opn ) {
195 my @a = grep { $$opn{$_} eq $util } keys %$opn;
196 return $self->{'_operation'} = $a[0];
197 }
198 else {
199 $self->throw("Utility '$util' is not recognized");
200 }
201 }
202  
203 sub util { shift->_operation(@_) }
204  
205 =head2 action()
206  
207 Title : action
208 Usage :
209 Function: return the soapAction associated with the factory's utility
210 Returns : scalar string
211 Args : none
212  
213 =cut
214  
215 sub action {
216 my $self = shift;
217 return $self->{_action} if $self->{_action};
218 return $self->{_action} = ${$self->_wsdl->operations}{$self->util};
219 }
220  
221  
222  
223 =head2 wsdl_file()
224  
225 Title : wsdl_file
226 Usage :
227 Function: get filename of the local WSDL XML copy
228 Returns : filename (scalar string)
229 Args : none
230  
231 =cut
232  
233 sub wsdl_file {
234 my $self = shift;
235 if (ref ($self->_wsdl->wsdl) eq 'File::Temp') {
236 return $self->_wsdl->wsdl->filename;
237 }
238 return $self->_wsdl->wsdl;
239 }
240  
241 =head2 run()
242  
243 Title : _run
244 Usage : $som = $self->_run(@optional_setting_args)
245 Function: Call the SOAP service with the factory-associated utility
246 and parameters
247 Returns : SOAP::SOM (SOAP Message) object
248 Args : named parameters appropriate for the utility
249 Note : no fault checking here
250  
251 =cut
252  
253 sub run {
254 my $self = shift;
255 my @args = @_;
256 $self->throw("SOAP::Lite client not initialized") unless
257 $self->_client;
258 $self->throw("run requires named args") if @args % 2;
259 $self->set_parameters(@args) if scalar @args;
260 my %args = $self->get_parameters;
261 my @soap_data;
262 for my $k (keys %args) {
263 ## kludges for NCBI inconsistencies:
264 my $k_ncbi;
265 for ($k) {
266 /QueryKey/ && do {
267 $k_ncbi = 'query_key';
268 last;
269 };
270 /RetMax/ && do {
271 $k_ncbi = 'retmax';
272 last;
273 };
274 $k_ncbi = $k;
275 }
276 my $data = $args{$k};
277 next unless defined $data;
278 for (ref $data) {
279 /^$/ && do {
280 push @soap_data, SOAP::Data->name($k_ncbi)->value($data);
281 last;
282 };
283 /ARRAY/ && do {
284 push @soap_data, SOAP::Data->name($k_ncbi)->value(join(',',@$data));
285 last;
286 };
287 /HASH/ && do {
288 # for adding multiple data items with the same message
289 # key (id lists for elink, e.g.)
290 # see ...::SoapEUtilities, c. line 151
291 push @soap_data, map {
292 SOAP::Data->name($k_ncbi)->value($_)
293 } keys %$data;
294 };
295 }
296 }
297 $self->_client->on_action( sub { $self->action } );
298 my $som = $self->_client->call( $self->util,
299 @soap_data );
300
301 return $som;
302 }
303  
304 sub _result_elt_name { my $s=shift; (keys %{$s->_wsdl->response_parameters($s->util)})[0] };
305 sub _response_elt_name { shift->_result_elt_name }
306 sub _request_elt_name { my $s=shift; (keys %{$s->_wsdl->request_parameters($s->util)})[0] };
307  
308 =head2 Bio::ParameterBaseI compliance
309  
310 =cut
311  
312 sub available_parameters {
313 my $self = shift;
314 my @args = @_;
315 return @{$self->_init_parameters};
316 }
317  
318 sub set_parameters {
319 my $self = shift;
320 my @args = @_;
321 $self->throw("set_parameters requires named args") if @args % 2;
322 ($_%2 ? 1 : $args[$_] =~ s/^-//) for (0..$#args);
323 my %args = @args;
324  
325 # special translations :
326 if ( defined $args{'usehistory'} ) {
327 $args{'usehistory'} = ($args{'usehistory'} ? 'y' : undef);
328 }
329  
330 $self->_set_from_args(\%args, -methods=>$self->_init_parameters);
331 return $self->parameters_changed(1);
332  
333 }
334  
335 sub get_parameters {
336 my $self = shift;
337 my @ret;
338 foreach (@{$self->_init_parameters}) {
339 next unless defined $self->$_();
340 push @ret, ($_, $self->$_());
341 }
342 return @ret;
343 }
344  
345 sub reset_parameters {
346 my $self = shift;
347 my @args = @_;
348 $self->throw("reset_parameters requires named args") if @args % 2;
349 ($_%2 ? 1 : $args[$_] =~ s/^-//) for (0..$#args);
350 my %args = @args;
351 my %reset;
352 @reset{@{$self->_init_parameters}} = (undef) x @{$self->_init_parameters};
353 $reset{$_} = $args{$_} for keys %args;
354 $self->_set_from_args( \%reset, -methods => $self->_init_parameters );
355 $self->parameters_changed(1);
356 return 1;
357 }
358  
359 =head2 parameters_changed()
360  
361 Title : parameters_changed
362 Usage : $obj->parameters_changed($newval)
363 Function: flag to indicate, well, you know
364 Example :
365 Returns : value of parameters_changed (a scalar)
366 Args : on set, new value (a scalar or undef, optional)
367  
368 =cut
369  
370 sub parameters_changed {
371 my $self = shift;
372 return $self->{'parameters_changed'} = shift if @_;
373 return $self->{'parameters_changed'};
374 }
375  
376 =head2 _init_parameters()
377  
378 Title : _init_parameters
379 Usage : $fac->_init_parameters
380 Function: identify the available input parameters
381 using the wsdl object
382 Returns : arrayref of parameter names (scalar strings)
383 Args : none
384  
385 =cut
386  
387 sub _init_parameters {
388 my $self = shift;
389 return $self->{_params} if $self->{_params};
390 $self->throw("WSDL not yet initialized") unless $self->_wsdl;
391 my $phash = {};
392 my $val = (values %{$self->_wsdl->request_parameters($self->util)})[0];
393 $$phash{$_} = undef for map { keys %$_ } @{$val};
394 my $params =$self->{_params} = [sort keys %$phash];
395 # create parm accessors
396 $self->_set_from_args( $phash,
397 -methods => $params,
398 -create => 1,
399 -code =>
400 'my $self = shift;
401 if (@_) {
402 $self->parameters_changed(1);
403 return $self->{\'_\'.$method} = shift;
404 }
405 $self->parameters_changed(0);
406 return $self->{\'_\'.$method};' );
407 $self->parameters_changed(1);
408 return $self->{_params};
409 }
410  
411 1;
« blib/lib/Bio/Tools/Run/Ensembl.pm ↑ Summary blib/lib/Bio/Tools/Run/Meme.pm »