AnalysisCtrlRule.pm 4.36 KB
Newer Older
1
=pod 
2 3

=head1 NAME
Jessica Severin's avatar
Jessica Severin committed
4

5
    Bio::EnsEMBL::Hive::AnalysisCtrlRule
6 7

=head1 DESCRIPTION
Jessica Severin's avatar
Jessica Severin committed
8

9 10 11 12 13 14 15 16 17
    An 'analysis control rule' is a high level blocking control structure where there is
    a 'ctrled_analysis' which is 'BLOCKED' from running until all of its 'condition_analysis' are 'DONE'.
    If a ctrled_analysis requires multiple analysis to be DONE before it can run, a separate
    AnalysisCtrlRule must be created/stored for each condtion analysis.

    Allows the 'condition' analysis to be specified with a network savy URL like
    mysql://ensadmin:<pass>@ecs2:3361/compara_hive_test?analysis.logic_name='blast_NCBI34'

=head1 LICENSE
18

19
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
20
    Copyright [2016-2021] EMBL-European Bioinformatics Institute
21 22 23 24 25 26 27 28 29

    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.
30 31

=head1 CONTACT
Jessica Severin's avatar
Jessica Severin committed
32

33
    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
34 35

=head1 APPENDIX
Jessica Severin's avatar
Jessica Severin committed
36

37 38
    The rest of the documentation details each of the object methods.
    Internal methods are usually preceded with a _
39 40 41 42 43 44

=cut


package Bio::EnsEMBL::Hive::AnalysisCtrlRule;

45
use strict;
46
use warnings;
47

48
use Bio::EnsEMBL::Hive::Utils ('throw');
49
use Bio::EnsEMBL::Hive::TheApiary;
50

51
use base ( 'Bio::EnsEMBL::Hive::Storable' );
52 53


54 55 56 57 58
sub unikey {    # override the default from Cacheable parent
    return [ 'condition_analysis_url', 'ctrled_analysis' ];
}   


59
=head1 AUTOLOADED
Jessica Severin's avatar
Jessica Severin committed
60

61
    ctrled_analysis_id / ctrled_analysis
Jessica Severin's avatar
Jessica Severin committed
62

63
=cut
64 65 66


=head2 condition_analysis_url
Jessica Severin's avatar
Jessica Severin committed
67

68 69 70 71 72
    Arg[1]  : (optional) string $url
    Usage   : $self->condition_analysis_url($url);
    Function: Get/set method for the analysis which must be 'DONE' in order for
                the controlled analysis to be un-BLOCKED. Specified as a URL.
    Returns : string
Jessica Severin's avatar
Jessica Severin committed
73
  
74
=cut
Jessica Severin's avatar
Jessica Severin committed
75

76
sub condition_analysis_url {
77 78 79 80 81 82 83 84 85
    my $self = shift @_;

    if(@_) {
        $self->{'_condition_analysis_url'} = shift @_;
        if( $self->{'_condition_analysis'} ) {
            $self->{'_condition_analysis'} = undef;
        }
    } elsif( !$self->{'_condition_analysis_url'} and my $condition_analysis=$self->{'_condition_analysis'} ) {

86 87
        my $ref_pipeline = $self->ctrled_analysis && $self->ctrled_analysis->hive_pipeline;
        $self->{'_condition_analysis_url'} = $condition_analysis->relative_url( $ref_pipeline );    # the URL may be shorter if hive_pipeline is the same for source and target
88
    }
89

90
    return $self->{'_condition_analysis_url'};
91 92 93 94
}


=head2 condition_analysis
Jessica Severin's avatar
Jessica Severin committed
95

96 97 98 99 100
    Arg[1]  : (optional) Bio::EnsEMBL::Hive::Analysis object
    Usage   : $self->condition_analysis($anal);
    Function: Get/set method for the analysis which must be 'DONE' in order for
                the controlled analysis to be un-BLOCKED
    Returns : Bio::EnsEMBL::Hive::Analysis
Jessica Severin's avatar
Jessica Severin committed
101
  
102
=cut
Jessica Severin's avatar
Jessica Severin committed
103

104
sub condition_analysis {
105
    my ($self, $analysis, $no_die) = @_;
106 107 108 109 110 111

    if( defined $analysis ) {
        unless ($analysis->isa('Bio::EnsEMBL::Hive::Analysis')) {
            throw( "condition_analysis arg must be a [Bio::EnsEMBL::Hive::Analysis] not a [$analysis]");
        }
        $self->{'_condition_analysis'} = $analysis;
112
    }
113

114
    if( !$self->{'_condition_analysis'} and my $condition_analysis_url = $self->condition_analysis_url ) {   # lazy-load through TheApiary
115

116
        $self->{'_condition_analysis'} = Bio::EnsEMBL::Hive::TheApiary->find_by_url( $condition_analysis_url, $self->hive_pipeline, $no_die );
117
    }
118 119

    return $self->{'_condition_analysis'};
120 121
}

Jessica Severin's avatar
Jessica Severin committed
122

123 124
=head2 toString

125 126 127 128
    Args       : (none)
    Example    : print $c_rule->toString()."\n";
    Description: returns a stringified representation of the rule
    Returntype : string
Jessica Severin's avatar
Jessica Severin committed
129 130 131

=cut

132 133 134 135
sub toString {
    my $self = shift;

    return join('',
136
            'AnalysisCtrlRule: ',
137
            $self->condition_analysis_url,
138
            ' ---| ',
139 140
            $self->ctrled_analysis->logic_name,
    );
141 142 143 144
}

1;