Commit ee740713 authored by Leo Gordon's avatar Leo Gordon
Browse files

Substitution machinery now supports an extra $overriding_hash that contains...

Substitution machinery now supports an extra $overriding_hash that contains parameters with higher precedence than the whole of param() structure
parent 24ccc976
......@@ -29,6 +29,7 @@ package Bio::EnsEMBL::Hive::AnalysisJob;
use strict;
use Bio::EnsEMBL::Utils::Argument; # import 'rearrange()'
use Bio::EnsEMBL::Hive::Utils ('destringify');
use Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor;
use Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor;
......@@ -271,8 +272,9 @@ sub dataflow_output_id {
# parameter substitution into input_id_template is rule-specific
my $output_ids_for_this_rule;
if(my $template = $rule->input_id_template()) {
$output_ids_for_this_rule = [ eval $self->param_substitute($template) ];
if(my $template_string = $rule->input_id_template()) {
my $template_hash = destringify($template_string);
$output_ids_for_this_rule = [ map { $self->param_substitute($template_hash, $_) } @$output_ids ];
} else {
$output_ids_for_this_rule = $output_ids;
}
......
......@@ -206,7 +206,7 @@ sub param {
=cut
sub param_substitute {
my ($self, $structure) = @_;
my ($self, $structure, $overriding_hash) = @_;
my $ref_type = ref($structure);
......@@ -218,12 +218,12 @@ sub param_substitute {
} elsif($structure=~/^#([^#]*)#$/) { # if the given string is one complete substitution, we don't want to force the output into a string
return $self->_subst_one_hashpair($1);
return $self->_subst_one_hashpair($1, $overriding_hash);
} else {
my $scalar_defined = 1;
$structure=~s/(?:#(.+?)#)/my $value = $self->_subst_one_hashpair($1); $scalar_defined &&= defined($value); $value/eg;
$structure=~s/(?:#(.+?)#)/my $value = $self->_subst_one_hashpair($1, $overriding_hash); $scalar_defined &&= defined($value); $value/eg;
return $scalar_defined ? $structure : undef;
}
......@@ -231,13 +231,13 @@ sub param_substitute {
} elsif($ref_type eq 'ARRAY') {
my @substituted_array = ();
foreach my $element (@$structure) {
push @substituted_array, $self->param_substitute($element);
push @substituted_array, $self->param_substitute($element, $overriding_hash);
}
return \@substituted_array;
} elsif($ref_type eq 'HASH') {
my %substituted_hash = ();
while(my($key,$value) = each %$structure) {
$substituted_hash{$self->param_substitute($key)} = $self->param_substitute($value);
$substituted_hash{$self->param_substitute($key, $overriding_hash)} = $self->param_substitute($value, $overriding_hash);
}
return \%substituted_hash;
} else {
......@@ -273,7 +273,7 @@ sub csvq { # another example stringification formatter
=cut
sub _subst_one_hashpair {
my ($self, $inside_hashes) = @_;
my ($self, $inside_hashes, $overriding_hash) = @_;
if($self->{'_substitution_in_progress'}{$inside_hashes}++) {
die "ParamError: substitution loop among {".join(', ', map {"'$_'"} keys %{$self->{'_substitution_in_progress'}})."} has been detected\n";
......@@ -283,7 +283,9 @@ sub _subst_one_hashpair {
if($inside_hashes=~/^\w+$/) {
$value = $self->_param_silent($inside_hashes);
$value = ( (ref($overriding_hash) eq 'HASH') && exists($overriding_hash->{ $inside_hashes }) )
? $overriding_hash->{ $inside_hashes }
: $self->_param_silent($inside_hashes);
} elsif($inside_hashes=~/^(\w+):(\w+)$/) {
......
Markdown is supported
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