9 A data container
object that defines parameters
for accumulated dataflow.
10 This
object is generated from specially designed datalow URLs.
14 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
15 Copyright [2016-2024] EMBL-European Bioinformatics Institute
17 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
18 You may obtain a copy of the License at
22 Unless required by applicable law or agreed to in writing, software distributed under the License
23 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License
for the specific language governing permissions and limitations under the License.
28 Please subscribe to the
Hive mailing list: http:
33 package Bio::EnsEMBL::Hive::Accumulator;
40 use base (
'Bio::EnsEMBL::Hive::Storable' );
43 sub unikey { #
override the
default from
Cacheable parent
44 return [
'accu_name',
'accu_address',
'accu_input_variable' ];
52 $self->{
'_accu_name'} = shift @_;
54 return $self->{
'_accu_name'};
62 $self->{
'_accu_address'} = shift @_;
64 return ( $self->{
'_accu_address'}
68 sub accu_input_variable {
72 $self->{
'_accu_input_variable'} = shift @_;
74 return ( $self->{
'_accu_input_variable'}
78 sub url_query_params {
81 return { # direct access to the actual (possibly missing) values
82 'accu_name' => $self->accu_name,
83 'accu_address' => $self->{
'_accu_address'},
84 'accu_input_variable' => $self->{
'_accu_input_variable'},
91 return $self->accu_name
94 . $self->accu_input_variable;
99 my ( $self, $output_ids, $emitting_job ) = @_;
101 if(my $receiving_semaphore = $emitting_job->controlled_semaphore) {
103 my $sending_job_id = $emitting_job->dbID;
104 my $receiving_semaphore_id = $receiving_semaphore->dbID;
105 my $accu_adaptor = $receiving_semaphore->adaptor->db->get_AccumulatorAdaptor;
107 my $accu_name = $self->accu_name;
108 my $accu_address = $self->accu_address;
109 my $accu_input_variable = $self->accu_input_variable;
113 foreach my $output_id (@$output_ids) {
115 my $key_signature = $accu_address;
116 $key_signature=~s{(\w+)}{$emitting_job->_param_possibly_overridden($1,$output_id)
118 _check_empty_keys($key_signature, $accu_address);
121 'sending_job_id' => $sending_job_id,
122 'receiving_semaphore_id' => $receiving_semaphore_id,
123 'struct_name' => $accu_name,
124 'key_signature' => $key_signature,
125 'value' => stringify( $emitting_job->_param_possibly_overridden($accu_input_variable, $output_id) ),
129 $accu_adaptor->store( \@rows );
132 die
"No controlled semaphore, cannot perform accumulated dataflow";
136 =head2 _check_empty_keys
138 Description: a
private function that checks the $key_signature
for empty
139 bracket pairs that weren
't empty before
143 sub _check_empty_keys {
144 my ( $key_signature, $accu_address ) = @_;
146 foreach my $pair ( ( ['{
', '}
'], ['[
', ']
'] ) ) {
148 # verify that each empty pair of brackets in key_signature was also empty in accu_address
149 my $empty_in_key = _find_empty_brackets( $key_signature, $pair->[0], $pair->[1] );
150 my $empty_in_address = _find_empty_brackets( $accu_address, $pair->[0], $pair->[1] );
151 my %empty_in_address_idx = map { $_ => 1 } @$empty_in_address;
153 foreach my $index (@$empty_in_key) {
154 if ( !exists( $empty_in_address_idx{$index} ) ) {
155 die "A key in the accumulator had an empty substitution. Bracket '"
156 . $pair->[0] . $pair->[1] .
157 "' pair number $index, substitution from '$accu_address
' to '$key_signature
'";
163 =head2 _find_empty_brackets
165 Description: a private function that finds and counts opening brackets in a
167 Returns: a ref to an array with an entry for each empty bracket pair. The
168 entry is the count of how many preceding opening brackets there are.
172 sub _find_empty_brackets {
173 my ( $string, $open, $close ) = @_;
177 # look for opening bracket
178 while ( $string =~ /\Q$open/g ) {
179 # count how many opening brackets we have
181 if ( $string =~ /\G(?=$close)/ ) {
182 # store number of bracket if we find an empty pair (like {})
183 push( @$result, $count );
192 return 'Accumulator(
' . $self->display_name . ')
';