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

implemented searching in collection by a combination of filters

parent df854397
......@@ -486,7 +486,7 @@ sub run {
my $resource_class;
if( $resource_class = $all_rc_coll->find_one_by('name', $rc_name) ) {
warn "Attempt to re-create and potentially redefine resource_class '$rc_name'. NB: This may affect already created analyses!\n";
warn "Found an already existing resource_class '$rc_name'.\n";
} else {
warn "Creating a new resource_class '$rc_name'.\n";
$resource_class = Bio::EnsEMBL::Hive::ResourceClass->new(
......@@ -498,13 +498,22 @@ sub run {
while( my($meadow_type, $resource_param_list) = each %{ $resource_classes_hash->{$rc_name} } ) {
$resource_param_list = [ $resource_param_list ] unless(ref($resource_param_list)); # expecting either a scalar or a 2-element array
my $resource_description = Bio::EnsEMBL::Hive::ResourceDescription->new(
'resource_class' => $resource_class,
'meadow_type' => $meadow_type,
'submission_cmd_args' => $resource_param_list->[0],
'worker_cmd_args' => $resource_param_list->[1],
);
push @{ $all_rd_coll->listref }, $resource_description;
my $resource_description;
if( $resource_description = $all_rd_coll->find_one_by('resource_class', $resource_class, 'meadow_type', $meadow_type) ) {
warn "Attempting to redefine an existing description for '$rc_name/$meadow_type' resource class\n";
$resource_description->submission_cmd_args( $resource_param_list->[0] );
$resource_description->worker_cmd_args( $resource_param_list->[1] );
} else {
warn "Creating a new description for '$rc_name/$meadow_type' resource class\n";
$resource_description = Bio::EnsEMBL::Hive::ResourceDescription->new(
'resource_class' => $resource_class,
'meadow_type' => $meadow_type,
'submission_cmd_args' => $resource_param_list->[0],
'worker_cmd_args' => $resource_param_list->[1],
);
push @{ $all_rd_coll->listref }, $resource_description;
}
}
}
unless(my $default_rc = $all_rc_coll->find_one_by('name', 'default') ) {
......
......@@ -40,20 +40,32 @@ sub hashed_by_dbID {
sub find_one_by {
my ($self, $method, $filter_value) = @_;
my @values = grep { $_->$method() eq $filter_value } $self->list;
return $values[0];
my ($self, %method_to_filter_value) = @_;
ELEMENT: foreach my $element (@{ $self->listref }) {
keys %method_to_filter_value; # sic! This is to "rewind" the each% operator to the beginning each time
while(my ($method, $filter_value) = each %method_to_filter_value) {
next ELEMENT unless($element->$method() eq $filter_value);
}
return $element;
}
}
sub find_all_by {
my ($self, $method, $filter_value) = @_;
my ($self, %method_to_filter_value) = @_;
my @values = grep { $_->$method() eq $filter_value } $self->list;
my @filtered_elements = ();
ELEMENT: foreach my $element (@{ $self->listref }) {
keys %method_to_filter_value; # sic! This is to "rewind" the each% operator to the beginning each time
while(my ($method, $filter_value) = each %method_to_filter_value) {
next ELEMENT unless($element->$method() eq $filter_value);
}
push @filtered_elements, $element;
}
return \@values;
return \@filtered_elements;
}
......
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