Accumulator.pm 3.77 KB
Newer Older
1 2 3 4
=pod 

=head1 NAME

5
    Bio::EnsEMBL::Hive::Accumulator
6 7 8 9 10 11

=head1 DESCRIPTION

    A data container object that defines parameters for accumulated dataflow.
    This object is generated from specially designed datalow URLs.

12 13
=head1 LICENSE

14
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
15
    Copyright [2016-2021] EMBL-European Bioinformatics Institute
16 17 18 19 20 21 22 23 24 25

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

26 27
=head1 CONTACT

28
  Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates
29 30 31

=cut

32

33 34 35
package Bio::EnsEMBL::Hive::Accumulator;

use strict;
36
use warnings;
37

38
use Bio::EnsEMBL::Hive::Utils ('stringify');
39

40
use base ( 'Bio::EnsEMBL::Hive::Storable' );
41 42 43


sub unikey {    # override the default from Cacheable parent
44
    return [ 'accu_name', 'accu_address', 'accu_input_variable' ];
45
}
46 47


48
sub accu_name {
49 50 51
    my $self = shift @_;

    if(@_) {
52
        $self->{'_accu_name'} = shift @_;
53
    }
54
    return $self->{'_accu_name'};
55 56 57
}


58
sub accu_address {
59 60 61
    my $self = shift @_;

    if(@_) {
62
        $self->{'_accu_address'} = shift @_;
63
    }
64
    return ( $self->{'_accu_address'} // '' );
65 66 67
}


68 69 70 71 72 73 74 75 76 77
sub accu_input_variable {
    my $self = shift @_;

    if(@_) {
        $self->{'_accu_input_variable'} = shift @_;
    }
    return ( $self->{'_accu_input_variable'} // $self->accu_name );
}


78 79 80 81 82 83 84 85
sub url_query_params {
     my ($self) = @_;

     return {   # direct access to the actual (possibly missing) values
        'accu_name'             => $self->accu_name,
        'accu_address'          => $self->{'_accu_address'},
        'accu_input_variable'   => $self->{'_accu_input_variable'},
     };
86 87 88 89
}


sub display_name {
90
    my ($self) = @_;
91
    return  $self->accu_name
92
            . $self->accu_address
93 94
            . ':='
            . $self->accu_input_variable;
95 96 97 98 99 100
}


sub dataflow {
    my ( $self, $output_ids, $emitting_job ) = @_;

101
    if(my $receiving_semaphore = $emitting_job->controlled_semaphore) {
102

103 104 105
        my $sending_job_id          = $emitting_job->dbID;
        my $receiving_semaphore_id  = $receiving_semaphore->dbID;
        my $accu_adaptor            = $receiving_semaphore->adaptor->db->get_AccumulatorAdaptor;
106

107 108 109
        my $accu_name           = $self->accu_name;
        my $accu_address        = $self->accu_address;
        my $accu_input_variable = $self->accu_input_variable;
110

111
        my @rows = ();
112

113
        foreach my $output_id (@$output_ids) {
114

115 116 117 118
            my $key_signature = $accu_address;
            $key_signature=~s/(\w+)/$emitting_job->_param_possibly_overridden($1,$output_id)/eg;

            push @rows, {
119 120 121 122 123
                'sending_job_id'            => $sending_job_id,
                'receiving_semaphore_id'    => $receiving_semaphore_id,
                'struct_name'               => $accu_name,
                'key_signature'             => $key_signature,
                'value'                     => stringify( $emitting_job->_param_possibly_overridden($accu_input_variable, $output_id) ),
124 125
            };
        }
126

127 128 129
        $accu_adaptor->store( \@rows );

    } else {
130
        die "No controlled semaphore, cannot perform accumulated dataflow";
131
    }
132 133
}

134 135 136 137

sub toString {
    my $self = shift @_;

138
    return 'Accumulator(' . $self->display_name . ')';
139 140
}

141 142
1;