AnalysisCtrlRule.pm 5.14 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
Brandon Walts's avatar
Brandon Walts committed
20
    Copyright [2016-2020] 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 50
use Bio::EnsEMBL::Hive::URLFactory;

51
use base ( 'Bio::EnsEMBL::Hive::Cacheable', '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 86
    my $self = shift @_;

    if(@_) {
        $self->{'_condition_analysis_url'} = shift @_;
        if( $self->{'_condition_analysis'} ) {
#            warn "setting condition_analysis_url() in an object that had to_analysis() defined";
            $self->{'_condition_analysis'} = undef;
        }
    } elsif( !$self->{'_condition_analysis_url'} and my $condition_analysis=$self->{'_condition_analysis'} ) {

87 88 89
        my $ref_dba = $self->ctrled_analysis && $self->ctrled_analysis->adaptor && $self->ctrled_analysis->adaptor->db;
        $self->{'_condition_analysis_url'} = $condition_analysis->url( $ref_dba );  # the URL may be shorter if DBA is the same for source and target

90
#        warn "Lazy-loaded condition_analysis_url\n";
91
    }
92

93
    return $self->{'_condition_analysis_url'};
94 95 96
}


97

98
=head2 condition_analysis
Jessica Severin's avatar
Jessica Severin committed
99

100 101 102 103 104
    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
105
  
106
=cut
Jessica Severin's avatar
Jessica Severin committed
107

108
sub condition_analysis {
109 110 111 112 113 114 115
    my ($self,$analysis) = @_;

    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;
116
    }
117

118
        # lazy load the analysis object if I can
119 120
    if( !$self->{'_condition_analysis'} and my $condition_analysis_url = $self->condition_analysis_url ) {

121 122 123
        my $collection = Bio::EnsEMBL::Hive::Analysis->collection();

        if( $collection and $self->{'_condition_analysis'} = $collection->find_one_by('logic_name', $condition_analysis_url) ) {
124 125 126 127 128 129 130
#            warn "Lazy-loading object from 'Analysis' collection\n";
        } elsif(my $adaptor = $self->adaptor) {
#            warn "Lazy-loading object from AnalysisAdaptor\n";
            $self->{'_condition_analysis'} = $adaptor->db->get_AnalysisAdaptor->fetch_by_logic_name_or_url($condition_analysis_url);
        } else {
#            warn "Lazy-loading object from full URL\n";
            $self->{'_condition_analysis'} = Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor->fetch_by_logic_name_or_url($condition_analysis_url);
131
        }
132
    }
133 134

    return $self->{'_condition_analysis'};
135 136
}

Jessica Severin's avatar
Jessica Severin committed
137

138 139
=head2 toString

140 141 142 143
    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
144 145 146

=cut

147 148 149 150
sub toString {
    my $self = shift;

    return join('',
151
            'AnalysisCtrlRule: ',
152
            $self->condition_analysis_url,
153
            ' ---| ',
154 155
            $self->ctrled_analysis->logic_name,
    );
156 157 158 159
}

1;