Bio/Tools/Analysis/SimpleAnalysisBase.pm

filter: Statementstmt 25.6% 20 / 78 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 29.4% 5 / 17 Podpod 100% 10 / 10 totaltotal 25.1% 35 / 139 CC 18 SCAR 27.6
CC
18
Cov
18%
_process_arguments
42.0
seq
30.0
clear
12.0
CRAP 15.8
« Bio/Tools/Glimmer.pm ↑ Summary Bio/Tree/RandomFactory.pm »
1 #
2 # BioPerl module for Bio::Tools::Analysis::SimpleAnalysisBase
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
7 #
8 # Copyright Richard Adams
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Tools::Analysis::SimpleAnalysisBase - abstract superclass for
17 SimpleAnalysis implementations
18  
19 =head1 SYNOPSIS
20  
21 # not to be run directly
22  
23 =head1 DESCRIPTION
24  
25 This class is a generic implementation of SimpleAnalysisI and should
26 be used as a base class for specific implementations.
27  
28 Modules implementing SimpleAnalysisBase only need to provide specific
29 _init(), _run() and result() methods, plus any get/set methods for
30 parameters to the analysis program.
31  
32 =head1 SEE ALSO
33  
34 L<Bio::SimpleAnalysisI>,
35 L<Bio::WebAgent>
36  
37 =head1 FEEDBACK
38  
39 =head2 Mailing Lists
40  
41 User feedback is an integral part of the evolution of this and other
42 Bioperl modules. Send your comments and suggestions preferably to one
43 of the Bioperl mailing lists. Your participation is much appreciated.
44  
45 bioperl-l@bioperl.org - General discussion
46 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47  
48 =head2 Support
49  
50 Please direct usage questions or support issues to the mailing list:
51  
52 I<bioperl-l@bioperl.org>
53  
54 rather than to the module maintainer directly. Many experienced and
55 reponsive experts will be able look at the problem and quickly
56 address it. Please include a thorough description of the problem
57 with code and data examples if at all possible.
58  
59 =head2 Reporting Bugs
60  
61 Report bugs to the Bioperl bug tracking system to help us keep track
62 the bugs and their resolution. Bug reports can be submitted via the
63 web:
64  
65 https://github.com/bioperl/bioperl-live/issues
66  
67 =head1 AUTHORS
68  
69 Richard Adams, Richard.Adams@ed.ac.uk,
70 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
71  
72 =head1 APPENDIX
73  
74 The rest of the documentation details each of the object
75 methods. Internal methods are usually preceded with a _
76  
77 =cut
78  
79  
80 # Let the code begin...
81  
82  
83 package Bio::Tools::Analysis::SimpleAnalysisBase;
84 1 $Bio::Tools::Analysis::SimpleAnalysisBase::VERSION = '1.7.8';
85 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 1 my $FLOAT = '[+-]?\d*\.\d*';
89  
90 1 my %STATUS = map { $_ => 1 } qw(CREATED COMPLETED TERMINATED_BY_ERROR);
91  
92 1 ▶use base qw(Bio::WebAgent Bio::SimpleAnalysisI);
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 =head2 new
95  
96 Usage : $job->new(...)
97 Returns : a new analysis object,
98 Args : none (but an implementation may choose
99 to add arguments representing parameters for the analysis
100 program. Each key value of must have a method implemented
101 for it in a subclass. A seq () method is provided here as
102 this will probably be needed by all sequence analysis programs
103  
104 =cut
105  
106 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
107 0 my $class = shift;
108  
109 0 my $self = $class->SUPER::new(); #WebAgent new
110 0 $self->_init; #this line has to be before the attributes are filled in
111 0 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
112 0 my $key = lc shift;
113 0 $key =~ s/^-//;
114 0 $self->$key(shift);
115 }
116 0 return $self;
117 }
118  
119 =head2 seq
120  
121 Usage : $job->seq()
122 Returns : a Bio::PrimarySeqI implementing sequence object, or void
123 Args : None, or a Bio::PrimarySeqI implementing object
124  
125 =cut
126  
127 0 ▶sub seq {
Subroutine seq: not called CC=5 SCAR=34.0
Pod documented
128 0 my ($self,$value) = @_;
129 0 ▶ if ( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
130 0 ▶ $self->throw("I need a Bio::PrimarySeqI, not [". $value. "]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Bio::PrimarySeqI") 0 0 0
131 unless $value->isa('Bio::PrimarySeqI');
132 0 ▶ $self->throw(" I need a PrimarySeq object, not a BioSeq object ")
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Bio::SeqI") 0 0 0
133 if $value->isa('Bio::SeqI');
134  
135 0 my $mol_type = $self->analysis_spec->{'type'};
136 0 ▶ $self->throw("I need a [" . $mol_type . "] seq, not a [". $value->alphabet. "]")
Branch: 1 branch
BranchTrueFalseTotal
unless $value->alphabet =~ /$mol_type/i 0 0 0
137 unless $value->alphabet =~/$mol_type/i;
138 0 $self->{'_seq'} = $value;
139 0 return $self;
140 }
141 0 return $self->{'_seq'} ;
142 }
143  
144 =head2 analysis_name
145  
146 Usage : $analysis->analysis_name();
147 Returns : The analysis name
148 Arguments : none
149  
150 =cut
151  
152 0 ▶sub analysis_name {
Subroutine analysis_name: not called CC=1 SCAR=6.9
Pod documented
153 0 my $self = shift;
154 0 return $self->{'_ANALYSIS_NAME'};
155 }
156  
157 =head2 analysis_spec
158  
159 Usage : $analysis->analysis_spec();
160 Returns : a hash reference to a hash of analysis parameters. See
161 Bio::SimpleAnalysisI for a list of recommended key values.
162 Arguments: none
163  
164 =cut
165  
166 0 ▶sub analysis_spec {
Subroutine analysis_spec: not called CC=1 SCAR=6.9
Pod documented
167 0 my $self = shift;
168 0 return $self->{'_ANALYSIS_SPEC'};
169 }
170  
171 =head2 clear
172  
173 Usage : $analysis->clear();
174 Returns : true value on success
175 Arguments : none
176 Purpose : to remove raw results from a previous analysis so that
177 an analysis can be repeated with different parameters.
178  
179 =cut
180  
181 0 ▶sub clear {
Subroutine clear: not called CC=3 SCAR=24.8
Pod documented
182 0 my $self= shift;
183 0 ▶ if (defined($self->{'_result'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_result"}) 0 0 0
184 0 delete $self->{'_result'};
185 }
186 0 ▶ if (defined ($self->{'_parsed'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_parsed"}) 0 0 0
187 0 delete $self->{'_parsed'};
188 }
189 0 return 1;
190 }
191
192  
193  
194 =head2 input_spec
195  
196 Usage : $analysis->input_spec();
197 Returns : a reference to an array of hashes of analysis parameters. See
198 Bio::SimpleAnalysisI for a list of recommended key values.
199 Arguments : none
200  
201 =cut
202  
203 0 ▶sub input_spec {
Subroutine input_spec: not called CC=1 SCAR=6.9
Pod documented
204 0 my $self = shift;
205 0 return $self->{'_INPUT_SPEC'};
206 }
207  
208 =head2 result_spec
209  
210 Usage : $analysis->result_spec();
211 Returns : a reference to a hashes of resultformats. See
212 Bio::SimpleAnalysisI for a list of recommended key values.
213 The key values can be used as parameters to the result()
214 method, the values provide descriptions.
215 Arguments : none
216  
217 =cut
218  
219 0 ▶sub result_spec {
Subroutine result_spec: not called CC=1 SCAR=6.9
Pod documented
220 0 my $self = shift;
221 0 return $self->{'_RESULT_SPEC'};
222 }
223  
224 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
225 0 my ($self, $args) = @_;
226 0 ▶ $self->_process_arguments ($args) if $args;
Branch: 1 branch
BranchTrueFalseTotal
if $args 0 0 0
227  
228 # check input
229 0 ▶ $self->throw("Need a sequence object as an input") unless $self->seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->seq 0 0 0
230 0 $self->debug(Data::Dumper->Dump([$self],[$self]));
231  
232 # internal run()
233 0 $self->_run;
234 0 return $self;
235 }
236  
237 0 ▶sub wait_for {
Subroutine wait_for: not called CC=1 SCAR=6.9
Pod documented
238 0 my ($self, $args) = @_;
239 0 $self->run($args);
240 }
241  
242 0 ▶sub status {
Subroutine status: not called CC=4 SCAR=21.7
Pod documented
243 0 my ($self,$value) = @_;
244  
245 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
246 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
247 0 my $class = ref($self);
248 $self->throw("Not a valid status value [$value]\n".
249 "Valid values are ". join(", ", keys %STATUS ))
250 0 ▶ unless defined $STATUS{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $STATUS{$value} 0 0 0
251 0 $self->{'_status'} = $value;
252 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
253 }
254 0 ▶ return $self->{'_status'} || 'CREATED' ;
Condition0%0/2
$self->{'_status'} || 'CREATED'
l!l
00
MC/DC0%0/1
$self->{'_status'} || 'CREATED'
$self->{'_status'}
Truth table0%0/2
A
A= $self->{'_status'}
Aresult
11
00
255 }
256  
257 0 ▶sub _process_arguments {
Subroutine _process_arguments: not called CC=6 SCAR=37.4
258 0 my ($self, $args) = @_;
259  
260 0 my %spec;
261 0 map {$spec{ $_->{'name'} } = $_ } @{$self->input_spec};
262  
263 0 $self->debug(Data::Dumper->Dump([\%spec, $args],[\%spec, $args]));
264 0 foreach my $key (keys %$args) {
265 0 my $value = $args->{$key};
266  
267 $self->throw("Unknown argument [$key]")
268 0 ▶ unless $spec{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $spec{$key} 0 0 0
269 0 $self->$key($value);
270 }
271  
272 0 foreach my $key (keys %spec) {
273 $self->throw("Mandatory argument [$key] is not set")
274 0 ▶ if $spec{$key}{'mandatory'} eq 'true' and not defined $self->$key;
Branch: 1 branch
BranchTrueFalseTotal
if $spec{$key}{"mandatory"} eq "true" and not defined $self->$key 0 0 0
Condition0%0/3
$spec{$key}{"mandatory"} eq "true" and not defined $self->$key
!ll&&!rl&&r
000
MC/DC0%0/2
$spec{$key}{"mandatory"} eq "true" and not defined $self->$key
$spec{$key}{"mandatory"} eq "true" not defined $self->$key
Truth table0%0/3
A and not(B)
A= $spec{$key}{"mandatory"} eq "true"B= not defined $self->$key
ABresult
0X0
100
111
275 }
276 }
277  
278  
279 0 ▶sub _run { shift->throw_not_implemented();}
Subroutine _run: not called CC=1 SCAR=6.9
280
281 1 1;
« Bio/Tools/Glimmer.pm ↑ Summary Bio/Tree/RandomFactory.pm »