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