Permalink
Browse files

AssemblerBase.pm: In "reset_parameters", added an intermediary hash

to avoid passing an array to "_set_program_options" that can
potentially contain the same parameter multiple times
(some with value, some with undef), with unexpected consequences.
  • Loading branch information...
1 parent a6d0dc2 commit 54f3e66bcbdc6d77116a6c3d3f4913a553214805 @fjossandon fjossandon committed Dec 14, 2013
Showing with 14 additions and 6 deletions.
  1. +14 −6 lib/Bio/Tools/Run/AssemblerBase.pm
@@ -829,15 +829,23 @@ sub reset_parameters {
# don't like this, b/c _set_program_args will create a bunch of
# accessors with undef values, but oh well for now /maj
- for my $p (@$params) {
- push(@reset_args, $p => undef) unless grep /^$p$/, @args;
+ # Is better to use hashes than arrays, to use their unique keys
+ my %reset_args = @args;
+ foreach my $p (@$params) {
+ if (not exists $reset_args{"-$p"}) {
+ $reset_args{"-$p"} = undef;
+ }
+ }
+ foreach my $s (@$switches) {
+ if (not exists $reset_args{"-$s"}) {
+ $reset_args{"-$s"} = undef;
+ }
}
- for my $s (@$switches) {
- push(@reset_args, $s => undef) unless grep /^$s$/, @args;
+ while (my ($method, $value) = each %reset_args) {
+ push(@reset_args, $method => $value);
}
- push @args, @reset_args;
- $self->_set_program_options(\@args, $params, $switches, $translation,
+ $self->_set_program_options(\@reset_args, $params, $switches, $translation,
$qual_param, $use_dash, $join);
$self->parameters_changed(1);
}

0 comments on commit 54f3e66

Please sign in to comment.