Accumulator.pm 3.43 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-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
15 16 17 18 19 20 21 22 23 24

    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.

25 26 27 28 29 30
=head1 CONTACT

  Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.

=cut

31

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

use strict;
use Scalar::Util ('weaken');

37
use Bio::EnsEMBL::Utils::Argument ('rearrange');
38
use Bio::EnsEMBL::Hive::Utils ('stringify');
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

sub new {
    my $class = shift @_;

    my $self = bless {}, $class;

    my ($adaptor, $struct_name, $signature_template) = 
         rearrange([qw(adaptor struct_name signature_template) ], @_);

    $self->adaptor($adaptor)                        if(defined($adaptor));
    $self->struct_name($struct_name)                if(defined($struct_name));
    $self->signature_template($signature_template)  if(defined($signature_template));

    return $self;
}


sub adaptor {
    my $self = shift @_;

    if(@_) {
        $self->{'_adaptor'} = shift @_;
        weaken $self->{'_adaptor'};
    }

    return $self->{'_adaptor'};
}


sub struct_name {
    my $self = shift @_;

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


sub signature_template {
    my $self = shift @_;

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


sub url {
    my $self    = shift @_;
    my $ref_dba = shift @_;     # if reference dba is the same as 'our' dba, a shorter url can be generated

    if(my $adaptor = $self->adaptor) {
        my $dbc_prefix = ($adaptor->db == $ref_dba) ? ':///' : $adaptor->db->dbc->url();
        return $dbc_prefix .'/accu?'.$self->struct_name(). '=' . $self->signature_template();
    } else {
        return;
    }
}


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

    my $sending_job_id      = $emitting_job->dbID();
    my $receiving_job_id    = $emitting_job->semaphored_job_id() || die "No semaphored job, cannot perform accumulated dataflow";

    my $struct_name         = $self->struct_name();
    my $signature_template  = $self->signature_template();

    my @rows = ();

    foreach my $output_id (@$output_ids) {

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

        push @rows, {
            'sending_job_id'    => $sending_job_id,
            'receiving_job_id'  => $receiving_job_id,
            'struct_name'       => $struct_name,
            'key_signature'     => $key_signature,
122
            'value'             => stringify( $emitting_job->_param_possibly_overridden($struct_name, $output_id) ),
123 124 125 126 127 128 129 130 131
        };
    }

    $self->adaptor->store( \@rows );
}


1;