Skip to content
Snippets Groups Projects
Commit 10271cee authored by Leo Gordon's avatar Leo Gordon
Browse files

4 levels of hierarchy

parent 882bd936
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,11 @@ package Bio::EnsEMBL::Hive::ProcessWithParams;
use strict;
use base ('Bio::EnsEMBL::Hive::Process');
sub strict_hash_format { # This public virtual must be redefined to "return 0;" in all inheriting classes
# that want more flexibility for the format of parameters() or input_id()
return 1;
}
sub param_init { # normally will run automatically on the first execution of $self->param(),
# but you can enforce it by running manually, optionally supplying the default values
......@@ -38,23 +43,15 @@ sub param_init { # normally will run automatically on the first execution of
if( !$self->{'_param_hash'} or scalar(@_) ) {
my $defaults = scalar(@_) ? { @_ } : {}; # built-in defaults have the lowest precedence
my $defaults_hash = scalar(@_) ? { @_ } : {}; # module-wide built-in defaults have the lowest precedence (will always be the same for this module)
my $parameters = eval($self->parameters()) || {};
if($@) {
die "The module '".ref($self)."' for analysis '".$self->analysis->logic_name()
."' assumes analysis.parameters should evaluate into a {'param'=>'value'} hashref."
." The current value is '".$self->parameters()."'\n";
}
my $meta_params_hash = $self->_parse_meta(); # then come the pipeline-wide parameters from the 'meta' table (define things common to all modules in this pipeline)
my $input_id = eval($self->input_id()) || {};
if($@) {
die "The module '".ref($self)."' for analysis '".$self->analysis->logic_name()
."' assumes analysis_job.input_id should evaluate into a {'param'=>'value'} hashref."
." The current value is '".$self->input_id()."'\n";
}
my $parameters_hash = $self->_parse_string('parameters'); # analysis-wide 'parameters' are even more specific (can be defined differently for several occurence of the same module)
$self->{'_param_hash'} = { %$defaults, %$parameters, %$input_id };
my $input_id_hash = $self->_parse_string('input_id'); # job-specific 'input_id' parameters have the highest precedence
$self->{'_param_hash'} = { %$defaults_hash, %$meta_params_hash, %$parameters_hash, %$input_id_hash };
}
}
......@@ -71,4 +68,44 @@ sub param {
return $self->{'_param_hash'}{$param_name};
}
#--------------------------------------------[private methods]----------------------------------------------
sub _parse_string {
my ($self, $method) = @_;
my $string = $self->$method();
if($self->strict_hash_format() or $string=~/^\{.*\}$/) {
my $param_hash = eval($string) || {};
if($@ or (ref($param_hash) ne 'HASH')) {
die "The module '".ref($self)."' for analysis '".$self->analysis->logic_name()
."' assumes analysis.$method should evaluate into a {'param'=>'value'} hashref."
." The current value is '$string'\n";
}
return $param_hash;
} else {
return {};
}
}
# Unfortunately, MetaContainer is useless for us, as we need to load all the parameters in one go
#
sub _parse_meta {
my $self = shift @_;
my %meta_params_hash = ();
# Here we are assuming that meta_keys are unique.
# If they are not, you'll be getting the value with the highest meta_id.
#
my $sth = $self->db->dbc()->prepare("SELECT meta_key, meta_value FROM meta ORDER BY meta_id");
$sth->execute();
while (my ($meta_key, $meta_value)=$sth->fetchrow_array()) {
$meta_params_hash{$meta_key} = $meta_value;
}
$sth->finish();
return \%meta_params_hash;
}
1;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment