blib/lib/Bio/Tools/Run/Analysis.pm

filter: Statementstmt 16.7% 25 / 149 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 44.4% 8 / 18 Podpod 100% 1 / 1 totaltotal 12.7% 34 / 266 CC 50 SCAR 43.7
CC
50
Cov
10%
_prepare_inputs
156.0
_save_result
156.0
new
72.0
CRAP 79.4
« blib/lib/Bio/Tools/Run/Alignment/Probcons.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Probalign.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Analysis
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Martin Senger <martin.senger@gmail.com>
8 # For copyright and disclaimer see below.
9 #
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::Tools::Run::Analysis - Module representing any (remote or local)
16 analysis tool
17  
18 =head1 SYNOPSIS
19  
20 # run analysis 'seqret' using a default location and a default
21 # access method (which means using a Web Service at EBI)
22 use Bio::Tools::Run::Analysis;
23 print new Bio::Tools::Run::Analysis (-name => 'edit::seqret')
24 ->wait_for ({ sequence_direct_data => 'tatatacgtatacga',
25 osformat => 'embl'
26 })
27 ->result ('outseq');
28  
29 # run a longer job without waiting for its completion
30 use Bio::Tools::Run::Analysis;
31 my $job = Bio::Tools::Run::Analysis->new(-name => 'edit::seqret')
32 ->run ({ sequence_direct_data => 'tatatacgtatacga',
33 osformat => 'embl'
34 });
35 # ...and after a while
36 $job->result ('outseq');
37  
38 # get all results in the same invocation (as a hash reference
39 # with result names as keys) - let the module decide which
40 # results are binary (images in this examples) and save those
41 # in file (or files); it also shows how to tell that the module
42 # should read input data from a local file first
43 use Bio::Tools::Run::Analysis;
44 my $results =
45 Bio::Tools::Run::Analysis->new(-name => 'alignment_multiple::prettyplot')
46 ->wait_for ( { msf_direct_data => '@/home/testdata/my.seq' } )
47 ->results ('?');
48 use Data::Dumper;
49 print Dumper ($results);
50  
51 # get names, types of all inputs and results,
52 # get short and detailed (in XML) service description
53 use Bio::Tools::Run::Analysis;
54 my $service = Bio::Tools::Run::Analysis->new(-name => 'edit::seqret');
55 my $hash1 = $service->input_spec;
56 my $hash2 = $service->result_spec;
57 my $hash3 = $service->analysis_spec;
58 my $xml = $service->describe;
59  
60 # get current job status
61 use Bio::Tools::Run::Analysis;
62 print new Bio::Tools::Run::Analysis (-name => 'edit::seqret')
63 ->run ( { #...input data...
64 } )
65 ->status;
66  
67 # run a job and print its job ID, keep the job un-destroyed
68 use Bio::Tools::Run::Analysis;
69 my $job =
70 Bio::Tools::Run::Analysis->new(-name => 'edit::seqret',
71 -destroy_on_exit => 0)
72 ->run ( { sequence_direct_data => '@/home/testdata/mzef.seq' } );
73 print $job->id . "\n";
74 # ...it prints (for example):
75 # edit::seqret/c8ef56:ef535489ac:-7ff4
76  
77 # ...in another time, on another planet, you may say
78 use Bio::Tools::Run::Analysis;
79 my $job =
80 Bio::Tools::Run::Analysis::Job->new(-name => 'edit::seqret',
81 -id => 'edit::seqret/c8ef56:ef535489ac:-7ff4');
82 print join ("\n",
83 $job->status,
84 'Finished: ' . $job->ended (1), # (1) means 'formatted'
85 'Elapsed time: ' . $job->elapsed,
86 $job->last_event,
87 $job->result ('outseq')
88 );
89  
90 # ...or you may achieve the same keeping module
91 # Bio::Tools::Run::Analysis::Job invisible
92 use Bio::Tools::Run::Analysis;
93 my $job =
94 Bio::Tools::Run::Analysis->new(-name => 'edit::seqret')
95 ->create_job ('edit::seqret/c8ef56:ef535489ac:-7ff4');
96 print join ("\n",
97 $job->status,
98 # ...
99 );
100  
101 # ...and later you may free this job resources
102 $job->remove;
103  
104 #
105 # --- See DESCRIPTION for using generator 'applmaker.pl':
106 #
107  
108  
109 =head1 DESCRIPTION
110  
111 The module represents an access to the local and/or remote analysis
112 tools in a unified way that allows adding new access methods
113 (protocols) seamlessly.
114  
115 At the moment of writing, there is available a I<SOAP> access to
116 almost all EMBOSS applications, running at the
117 European Bioinformatics Institute.
118  
119 The documentation of all C<public> methods are to be found
120 in C<Bio::AnalysisI>. A tutorial (and examples how to call almost all
121 public methods) is in the script C<panalysis.PLS> (go to the C<scripts>
122 directory and type C<perldoc panalysis.PLS>).
123  
124 The module C<Bio::Tools::Run::Analysis> uses general approach allowing to set
125 arbitrary input data and to retrieve results by naming them. However,
126 sometimes is more convenient to use a specific module, representing
127 one analysis tool, that already knows about available input and result
128 names. Such analyses-specific Perl modules can be generated by
129 C<papplmaker.PLS> generator. Its features and usage are documented in
130 the generator (go to the C<scripts> directory and type C<perldoc
131 papplmaker.PLS>).
132  
133 # this will generate module Seqret.pm
134 perl papplmaker.PLS -n edit.seqret -m Seqret
135  
136 # ...which can be used with data-specific methods
137 use Seqret;
138 my $outseq = new Seqret
139 ->sequence_direct_data ('@/home/testdata/my.seq')
140 ->osformat ('embl')
141 ->wait_for
142 ->outseq
143 ;
144 print $outseq;
145  
146 =head1 FEEDBACK
147  
148 =head2 Mailing Lists
149  
150 User feedback is an integral part of the evolution of this and other
151 Bioperl modules. Send your comments and suggestions preferably to
152 the Bioperl mailing list. Your participation is much appreciated.
153  
154 bioperl-l@bioperl.org - General discussion
155 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
156  
157 =head2 Support
158  
159 Please direct usage questions or support issues to the mailing list:
160  
161 I<bioperl-l@bioperl.org>
162  
163 rather than to the module maintainer directly. Many experienced and
164 reponsive experts will be able look at the problem and quickly
165 address it. Please include a thorough description of the problem
166 with code and data examples if at all possible.
167  
168 =head2 Reporting Bugs
169  
170 Report bugs to the Bioperl bug tracking system to help us keep track
171 of the bugs and their resolution. Bug reports can be submitted via the
172 web:
173  
174 http://redmine.open-bio.org/projects/bioperl/
175  
176 =head1 AUTHOR
177  
178 Martin Senger (martin.senger@gmail.com)
179  
180 =head1 COPYRIGHT
181  
182 Copyright (c) 2003, Martin Senger and EMBL-EBI.
183 All Rights Reserved.
184  
185 This module is free software; you can redistribute it and/or modify
186 it under the same terms as Perl itself.
187  
188 =head1 DISCLAIMER
189  
190 This software is provided "as is" without warranty of any kind.
191  
192 =head1 SEE ALSO
193  
194 =over
195  
196 =item *
197  
198 http://www.ebi.ac.uk/soaplab/Perl_Client.html
199  
200 =back
201  
202 =head1 APPENDIX
203  
204 Here is the rest of the object methods. Internal methods are preceded
205 with an underscore _.
206  
207 =cut
208  
209  
210 # Let the code begin...
211  
212 package Bio::Tools::Run::Analysis;
213 2 ▶use vars qw(@ISA $Revision);
Subroutine BEGIN: called CC=1 SCAR=0.0
214 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
215  
216 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
217 2 ▶use Bio::AnalysisI;
Subroutine BEGIN: called CC=1 SCAR=0.0
218 2 @ISA = qw(Bio::Root::Root Bio::AnalysisI);
219  
220 BEGIN {
221 2 ▶ $Revision = q[$Id$];
Subroutine BEGIN: called CC=1 SCAR=0.0
222 }
223  
224 # -----------------------------------------------------------------------------
225  
226 =head2 new
227  
228 Usage : my $tool =
229 Bio::Tools::Run::Analysis->new(-access => 'soap',
230 -name => 'edit.seqret',
231 ...
232 );
233 Returns : a new Bio::Tools::Run::Analysis object representing the given tool
234 Args : There may be additional arguments which are specific
235 to the access method (see methods 'new' or '_initialize'
236 of the access-specific implementations (such as module
237 Bio::Tools::Run::Analysis::soap for a SOAP-based access).
238  
239 The recognised and used arguments are:
240 -access
241 -location
242 -name
243 -httpproxy
244 -timeout
245  
246 It builds, populates and returns a new C<Bio::Tools::Run::Analysis> object. This
247 is how it is seen from the outside. But in fact, it builds, populates
248 and returns a more specific lower-level object, for example
249 C<Bio::Tools::Run::Analysis::soap> object - which one it depends on the C<-access>
250 parameter.
251  
252 =over
253  
254 =item -access
255  
256 It indicates what lower-level module to load. Default is 'soap'.
257 Other (but future) possibilities may be:
258  
259 -access => 'novella'
260 -access => 'local'
261  
262 =item -location
263  
264 A location of the service. The contents is access-specific (see
265 details in the lower-level implementation modules).
266  
267 Default is C<http://www.ebi.ac.uk/soaplab/services> ( services running
268 at European Bioinformatics Institute on top of most of EMBOSS
269 analyses, and on few others).
270  
271 =item -name
272  
273 A name of an analysis tool, or a name of its higher-level abstraction,
274 possibly including a category where the analysis belong to. There is
275 no default value (which usually means that this parameter is mandatory
276 unless your I<-location> parameter includes also the name (but it is
277 then access-dependent).
278  
279 =item -destroy_on_exit =E<gt> '0'
280  
281 Default value is '1' which means that all Bio::Tools::Run::Analysis::Job
282 objects - when being finalised - will send a request
283 to the remote site to forget the results of these jobs.
284  
285 If you change it to '0' make sure that you know the job identification
286 - otherwise you will not be able to re-established connection with it
287 (later, when you use your program again). This can be done by calling
288 method C<id> on the job object (such object is returned by any of
289 these methods: C<create_job>, C<run>, C<wait_for>).
290  
291 =item -httpproxy
292  
293 In addition to the I<location> parameter, you may need to specify also
294 a location/URL of an HTTP proxy server (if your site requires
295 one). The expected format is C<http://server:port>. There is no
296 default value. It is also an access-specific parameter which may not
297 be used by all access methods.
298  
299 =item -timeout
300  
301 For long(er) running jobs the HTTP connection may be time-outed. In
302 order to avoid it (or, vice-versa, to call timeout sooner) you may
303 specify C<timeout> with the number of seconds the connection will be
304 kept alive. Zero means to keep it alive forever. The default value is
305 two minutes.
306  
307 =back
308  
309 =cut
310  
311 sub new {
312 0 ▶ my ($caller,@args) = @_;
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
313 0 ▶ my $class = ref($caller) || $caller;
Condition0%0/3
ref $caller || $caller
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table0%0/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
314
315 0 ▶ if ($class eq 'Bio::Tools::Run::Analysis') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'Bio::Tools::Run::Analysis') { } 0 0 0
316  
317 # this is called only the first time when somebody calls: 'new
318 # Bio::Tools::Run::Analysis (...)', and it actually loads a 'real-work-doing'
319 # module and call this new() method again (unless the loaded
320 # module has its own new() method)
321  
322 0 my %param = @args;
323 0 @param { map { lc $_ } keys %param } = values %param; # lowercase keys
324 my $access =
325 0 ▶ $param {'-access'} || # use -access parameter
Condition0%0/5
$param{'-access'} || &Bio::Tools::Run::Analysis::Utils::_guess_access(\%param) || 'soap'
l!l
00
$param{"-access"} or &Bio::Tools::Run::Analysis::Utils::_guess_access(\%param)
l!l&&r!l&&!r
000
MC/DC0%0/2
$param{'-access'} || &Bio::Tools::Run::Analysis::Utils::_guess_access(\%param) || 'soap'
$param{"-access"} &Bio::Tools::Run::Analysis::Utils::_guess_access(\%param)
Truth table0%0/3
A or B
A= $param{"-access"}B= &Bio::Tools::Run::Analysis::Utils::_guess_access(\%param)
ABresult
1X1
011
000
326 &Bio::Tools::Run::Analysis::Utils::_guess_access ( \%param ) || # or guess from other parameters
327 'soap'; # or use a default access method
328 0 $access = "\L$access"; # normalize capitalization to lower case
329  
330 # remember the access method (putting it into @args means that the
331 # object - when created - will remember it)
332 0 ▶ push (@args, (-access => $access)) unless $param {'-access'};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"-access"} 0 0 0
333  
334 # load module with the real implementation - as defined in $access
335 0 ▶ return undef unless (&Bio::Tools::Run::Analysis::Utils::_load_access_module ($access));
Branch: 1 branch
BranchTrueFalseTotal
unless &Bio::Tools::Run::Analysis::Utils::_load_access_module($access) 0 0 0
336  
337 # this calls this same method new() - but now its object part
338 # (see the upper branche above) is called
339 0 return "Bio::Tools::Run::Analysis::$access"->new (@args);
340  
341 } else {
342  
343 # if $caller is an object, or if it is an underlying
344 # 'real-work-doing' class (e.g. Bio::Tools::Run::Analysis::soap) then
345 # we want to call SUPER to create and bless a new object
346  
347 0 my ($self) = $class->SUPER::new (@args);
348  
349 # now the $self is an empty object - we will populate it from
350 # the $caller - if $caller is an object (so we do cloning here)
351  
352 0 ▶ if (ref ($caller)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $caller) 0 0 0
353 0 %{ $self } = %{ $caller };
354 }
355  
356 # and finally add values from '@args' into the newly created
357 # object (the values will overwrite the values copied above);
358 # this is done by calling '_initialize' of the 'real-work-doing'
359 # class (if there is no one there, there is always an empty one
360 # in Bio::Root::Root)
361  
362 0 $self->_initialize (@args);
363 0 return $self;
364 }
365  
366 }
367  
368 #
369 # Create a hash with named inputs, all extracted
370 # from the given data.
371 #
372 sub _prepare_inputs {
373 0 ▶ my $self = shift;
Subroutine _prepare_inputs: not called CC=12 SCAR=50.5
374 0 my %inputs = (); # collect here input data
375  
376 0 foreach my $input (@_) {
377  
378 0 ▶ next unless defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 0 0
379  
380 # an element can be an array reference
381 # (with scalar elements: 'name = [[@]value]')
382 0 ▶ if (ref $input eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $input eq 'ARRAY') { } 0 0 0
elsif (ref $input eq 'HASH') { } 0 0 0
elsif (ref \$input eq 'SCALAR') { } 0 0 0
383 0 foreach my $elem (@$input) {
384 0 ▶ unless (ref $elem) { # taking only scalars
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $elem) 0 0 0
385 0 my ($name, $value) = split (/\s*=\s*/, $elem, 2);
386 0 ▶ next unless $name; # am I paranoid ?
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
387 0 ▶ $value = 1 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
388 0 $inputs{$name} = $value;
389 0 next;
390 }
391 }
392 }
393  
394 # ...or an element can be a hash
395 # (name => [@]value)
396 elsif (ref $input eq 'HASH') {
397 0 foreach my $name (keys %$input) {
398 0 my $value = $$input{$name};
399 0 $inputs{$name} = $value;
400 }
401 }
402  
403 # ...or an element can be a scalar (which means that it
404 # represents a name of a boolean parameter (an option)
405 elsif (ref \$input eq 'SCALAR') {
406 0 $input =~ s/^@/\\@/; # this cannot be a filename
407 0 $inputs{$input} = 1;
408 }
409  
410 # everything else is ignored
411 else {
412 0 warn "Unrecognized input data type: $input\n";
413 }
414 }
415  
416 # extracted inputs may be actually filenames and we want the
417 # contents of the files instead
418 # TBD: to support also filehandlers here?
419 0 foreach my $name (keys %inputs) {
420 0 $inputs{$name} = $self->_read_value ($inputs{$name});
421 }
422 0 return \%inputs;
423 }
424  
425 # --- if a $value is a filename, read it and return its contents
426 # otherwise return the $value itself; if $value start with
427 # an escaped '@', change it to a normal '@'
428 sub _read_value {
429 0 ▶ my ($self, $value) = @_;
Subroutine _read_value: not called CC=6 SCAR=37.4
430 0 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
431 0 ▶ if ($value =~ s/^\@//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ s/^\@//) { } 0 0 0
elsif ($value =~ s/^\\\@/\@/) { } 0 0 0
432 0 my ($buf);
433 0 ▶ open (DATA, $value) || $self->throw ("Cannot read from '$value' ($!)");
Branch: 1 branch
BranchTrueFalseTotal
open DATA, $value or $self->throw("Cannot read from '${value}' ($!)") 0 0 0
434 0 binmode (DATA);
435 0 undef $value;
436 0 ▶ while (read (DATA, $buf, 8 * 2**10)) {
Branch: 1 branch
BranchTrueFalseTotal
if (read DATA, $buf, 8192) 0 0 0
437 0 $value .= $buf;
438 }
439 0 close DATA;
440 } elsif ($value =~ s/^\\\@/@/) {
441 }
442 0 $value;
443 }
444  
445 # --- save $value of result $name into file $filename + $seq;
446 # use some default filename if $filename not given
447  
448 #$part = $self->_save_result (-value => $part,
449 # -name => $name,
450 # -filename => $filename,
451 # -template => $template,
452 # -seq => $seq++);
453  
454 sub _save_result {
455 0 ▶ my ($self, %params) = @_;
Subroutine _save_result: not called CC=12 SCAR=50.5
456 0 ▶ my $name = $params{'-name'} || 'result';
Condition0%0/2
$params{'-name'} || 'result'
l!l
00
MC/DC0%0/1
$params{'-name'} || 'result'
$params{'-name'}
Truth table0%0/2
A
A= $params{'-name'}
Aresult
11
00
457  
458 # invent filename (if not given) from the given or default template
459 0 my $filename = $params{'-filename'};
460 0 ▶ unless ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename) 0 0 0
461 0 $filename = $params{'-template'};
462 0 ▶ $filename = "\$ANALYSIS_*_$name" unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
463  
464 # replace $ANALYSIS and $RESULT in the filename
465 0 ▶ if ($filename =~ /\$\{?ANALYSIS\}?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /\$\{?ANALYSIS\}?/) 0 0 0
466 # (better to ask if we need it because getting
467 # the analysis name may require going to server)
468 0 my $analysis = $self->analysis_name;
469 0 $analysis =~ s/[:\/]/_/g; # would be troubles in filename
470 0 $filename =~ s/\$\{?ANALYSIS\}?/$analysis/ig;
471 }
472 0 $filename =~ s/\$\{?RESULT\}?/$name/ig;
473 }
474  
475 # include the sequential number before file extension (if any)
476 0 my $seq = $params{'-seq'};
477 0 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 0 0 0
478 0 my $pos = rindex ($filename, '.');
479 0 ▶ if ($pos > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > -1) { } 0 0 0
480 0 substr ($filename, $pos, 0) = ".$seq"; # insert $seq
481 } else {
482 0 $filename .= ".$seq"; # add $seq
483 }
484 }
485  
486 # replace '*' in filename with a unique number
487 0 ▶ while ($filename =~ /\*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /\*/) 0 0 0
488 0 my $unique_name;
489 0 my $number = 1;
490 0 while (1) {
491 0 ($unique_name = $filename) =~ s/\*/$number/;
492 0 ▶ last unless -e $unique_name;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $unique_name 0 0 0
493 0 $number++;
494 }
495 0 $filename = $unique_name;
496 }
497  
498 # and finally write the file
499 0 ▶ open (DATA, ">$filename") ||
Branch: 1 branch
BranchTrueFalseTotal
open DATA, ">$filename" or $self->throw("Error by saving result '${name}' into '${filename}' ($!)") 0 0 0
500 $self->throw ("Error by saving result '$name' into '$filename' ($!)");
501 0 binmode (DATA);
502 0 ▶ print (DATA $params{'-value'}) ||
Branch: 1 branch
BranchTrueFalseTotal
print DATA $params{"-value"} or $self->throw("Error by writing result '${name}' into '${filename}' ($!)") 0 0 0
503 $self->throw ("Error by writing result '$name' into '$filename' ($!)");
504 0 ▶ close DATA ||
Branch: 1 branch
BranchTrueFalseTotal
close DATA or $self->throw("Error by closing result '${name}' in '${filename}' ($!)") 0 0 0
505 $self->throw ("Error by closing result '$name' in '$filename' ($!)");
506  
507 0 return $filename;
508 }
509  
510  
511 =head2 VERSION and Revision
512  
513 Usage : print $Bio::Tools::Run::Analysis::VERSION;
514 print $Bio::Tools::Run::Analysis::Revision;
515  
516 =cut
517  
518 # -----------------------------------------------------------------------------
519 # Bio::Tools::Run::Analysis::Job
520 # A module representing an invocation (execution, job) of an analysis.
521 # -----------------------------------------------------------------------------
522  
523 package Bio::Tools::Run::Analysis::Job;
524  
525 =head1 Module Bio::Tools::Run::Analysis::Job
526  
527 It represents a job, a single execution of an analysis tool. Usually
528 you do not instantiate these objects - they are returned by methods
529 C<create_job>, C<run>, and C<wait_for> of C<Bio::Tools::Run::Analysis> object.
530  
531 However, if you wish to re-create a job you need to know its ID
532 (method C<id> gives it to you). The ID can be passed directly to the
533 C<new> method, or again you may use C<create_job> of a
534 C<Bio::Tools::Run::Analysis> object with the ID as parameter. See SYNOPSIS above
535 for an example.
536  
537 Remember that all public methods of this module are described in
538 details in interface module C<Bio::AnalysisI> and in the tutorial in
539 the C<analysis.pl> script.
540  
541 =cut
542  
543  
544 2 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
545 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
546  
547 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
548 2 @ISA = qw(Bio::Root::Root Bio::AnalysisI::JobI);
549  
550 # -----------------------------------------------------------------------------
551  
552 =head2 new
553  
554 Usage : my $job = Bio::Tools::Run::Analysis::Job->new
555 (-access => 'soap',
556 -name => 'edit.seqret',
557 -id => 'xxxyyy111222333'
558 );
559 Returns : a re-created object representing a job
560 Args : The same arguments as for Bio::Tools::Run::Analysis object:
561 -access
562 -location
563 -name
564 -httpproxy
565 -timeout
566 (and perhaps others)
567 Additionally and specifically for this object:
568 -id
569 -analysis
570  
571 =over
572  
573 =item -id
574  
575 A job ID created some previous time and now used to re-create the same
576 job (in order to re-gain access to this job results, for example).
577  
578 =item -analysis
579  
580 A C<Bio::Tools::Run::Analysis> object whose properties (such as C<-access> and
581 C<-location> are used to re-create this job object.
582  
583 =back
584  
585 =cut
586  
587 sub new {
588 0 ▶ my ($caller, @args) = @_;
Subroutine new: not called CC=6 SCAR=37.4
589 0 ▶ my $class = ref($caller) || $caller;
Condition0%0/3
ref $caller || $caller
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table0%0/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
590
591 0 ▶ if ($class eq 'Bio::Tools::Run::Analysis::Job') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'Bio::Tools::Run::Analysis::Job') { } 0 0 0
592  
593 # this is called only the first time when somebody calls:
594 #'Bio::Tools::Run::Analysis::Job->new(...)'
595  
596 0 my %param = @args;
597 0 @param { map { lc $_ } keys %param } = values %param; # lowercase keys
598 0 ▶ if ($param {'-analysis'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{'-analysis'}) { } 0 0 0
599  
600 # usually a new Job object is created from an existing
601 # Analysis object - which means that the Analysis already
602 # loaded a 'real-work-doing' Job object, so we need just
603 # to create a Job object (by calling its new() method,
604 # which calls actually this new() method again - but its
605 # 'object' part - see below
606  
607 0 my $analysis = $param {'-analysis'};
608 0 ▶ return undef unless $analysis->{'_access'}; # TBD: error message here?
Branch: 1 branch
BranchTrueFalseTotal
unless $analysis->{"_access"} 0 0 0
609 0 my $access = $analysis->{'_access'};
610 0 return "Bio::Tools::Run::Analysis::Job::$access"->new (@args);
611  
612 } else {
613  
614 # if a new Job object is created directly (by a user, not
615 # by a parent Analysis object) we need to create the
616 # Analysis object first (because it is the Analysis object
617 # who knows how to contact the underlying analysis tool),
618 # and only then let the Analysis create this Job object
619 # (which may be an empty Job - if there is no 'id' in @args)
620  
621 0 return new Bio::Tools::Run::Analysis (@args)->create_job ($param {'-id'});
622 }
623  
624 } else {
625  
626 # if $caller is an object, or if it is an underlying
627 # 'real-work-doing' class (e.g. Bio::Tools::Run::Analysis::Job::soap) then
628 # we want to call SUPER to create and bless a new object
629  
630 0 my ($self) = $class->SUPER::new (@args);
631  
632 # now the $self is an empty object - we will populate it from
633 # the $caller - if $caller is an object (so we do cloning here)
634  
635 0 ▶ if (ref ($caller)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $caller) 0 0 0
636 0 %{ $self } = %{ $caller };
637 }
638  
639 # and finally add values from '@args' into the newly created
640 # object (the values will overwrite the values copied above);
641 # this is done by calling '_initialize' of the 'real-work-doing'
642 # class (if there is no one there, there is always an empty one
643 # in Bio::Root::Root)
644  
645 0 $self->_initialize (@args);
646 0 return $self;
647 }
648  
649 }
650  
651 0 ▶sub id { shift->{'_id'}; }
Subroutine id: not called CC=1 SCAR=6.9
652  
653 # ---------------------------------------------------------------------
654 #
655 # A Utility module...
656 #
657 # ---------------------------------------------------------------------
658  
659 package Bio::Tools::Run::Analysis::Utils;
660  
661 =head1 Module Bio::Tools::Run::Analysis::Utils
662  
663 It contains several general utilities. These are C<functions>, not
664 methods. Therefore call them like, for example:
665  
666 &Bio::Tools::Run::Analysis::Utils::format_time (...);
667  
668 =cut
669  
670 # -----------------------------------------------------------------------------
671  
672 =head2 format_time
673  
674 Usage : Bio::Tools::Run::Analysis::Utils::format_time ($time);
675 Returns : Slightly formatted $time
676 Args : $time is number of seconds from the beginning of Epoch
677  
678 It returns what C<localtime> returns which means that return value is
679 different in the array and scalar context (see localtime). If C<$time>
680 is ``-1'' it returns 'n/a' (in the scalar context) or an empty array
681 (in the array context). If C<$time> is too small to represent the
682 distance from the beginning of the Epoch, it returns it unchanged (the
683 same in any contex) - this is reasonable for C<$time> representing an
684 elapsed time.
685  
686 The function is used to format times coming back from various job time
687 methods.
688  
689 =cut
690  
691 sub format_time {
692 0 ▶ my $time = shift;
Subroutine format_time: not called CC=4 SCAR=30.0
693 0 ▶ return wantarray ? () : 'n/a' if "$time" eq '-1';
Branch: 2 branches
BranchTrueFalseTotal
if "$time" eq -1 0 0 0
wantarray ? : 0 0 0
694 0 ▶ return $time if $time < 1000000000;
Branch: 1 branch
BranchTrueFalseTotal
if $time < 1000000000 0 0 0
695 0 return localtime $time;
696 }
697  
698 # -----------------------------------------------------------------------------
699  
700 # It processes given result names which may be of various different
701 # types and returns a hash reference with result names as keys and
702 # values being result destinations (such as file names, or templates
703 # how to create filenames.
704 #
705 # Or, it returns a scalar ('@[template]' or '?[template]') if there
706 # were no real result names but only a global rule how to create
707 # result destinantions for all results.
708 #
709 # Or, it returns 'undef' if there were no result names at all.
710  
711 sub normalize_names {
712 0 ▶ return undef unless @_;
Subroutine normalize_names: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
713 0 my %names = ();
714 0 foreach (@_) {
715 0 ▶ if (ref $_ eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'HASH') { } 0 0 0
elsif (not ref $_) { } 0 0 0
716 0 %names = (%names, %$_);
717 } elsif (not ref $_) {
718 0 my ($name, $dest) = split (/\s*=\s*/, $_, 2);
719 0 ▶ return $name if $name =~ /^@/; # special: it nullifies other rules
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^@/ 0 0 0
720 0 ▶ return $name if $name =~ /^\?/; # ditto
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^\?/ 0 0 0
721 0 $names{$name} = $dest; # $dest may be undef
722 }
723 }
724 0 \%names;
725 }
726  
727 # -----------------------------------------------------------------------------
728  
729 =head2 _load_access_module
730  
731 Usage : $class->_load_access_module ($access)
732 Returns : 1 on success, undef on failure
733 Args : 'access' should contain the last part of the
734 name of a module who does the real implementation
735  
736 It does (in the run-time) a similar thing as
737  
738 require Bio::Tools::Run::Analysis::$access
739  
740 It prints an error on STDERR if it fails to find and load the module
741 (for example, because of the compilation errors in the module).
742  
743 =cut
744  
745 sub _load_access_module {
746 0 ▶ my ($access) = @_;
Subroutine _load_access_module: not called CC=2 SCAR=17.9
747  
748 0 my $load = "Bio/Tools/Run/Analysis/$access.pm";
749 0 eval {
750 0 require $load;
751 };
752  
753 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
754 0 Bio::Root::Root->throw (<<END);
755 $load: $access cannot be found or loaded
756 Exception $@
757 For more information about the Analysis system please see the Bio::Tools::Run::Analysis docs.
758 END
759 ;
760 0 return;
761 }
762 0 return 1;
763 }
764  
765 # -----------------------------------------------------------------------------
766  
767 =head2 _guess_access
768  
769 Usage : Bio::Tools::Run::Analysis::Utils::guess_access ($rh_params)
770 Returns : string with a guessed access protocol (e.g. 'soap'),
771 or undef if the guessing failed
772 Args : 'rh_params' is a hash reference containing parameters given
773 to the 'new' method.
774  
775 It makes an expert guess what kind of access/transport protocol should
776 be used to access the underlying analysis. The guess is based on the
777 parameters in I<rh_params>. Rememeber that this method is called only
778 if there was no I<-access> parameter which could tell directly what
779 access method to use.
780  
781 =cut
782  
783 sub _guess_access {
784 0 ▶ my ($rh_params) = @_;
Subroutine _guess_access: not called CC=1 SCAR=6.9
785 0 return undef;
786 }
787  
788  
789  
790 2 1;
791 __END__
« blib/lib/Bio/Tools/Run/Alignment/Probcons.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Probalign.pm »