AnalysisCtrlRule.pm 6.84 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
Matthieu Muffato's avatar
Matthieu Muffato committed
20
    Copyright [2016-2018] 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 47
use Scalar::Util ('weaken');

48 49 50
use Bio::EnsEMBL::Utils::Argument ('rearrange');
use Bio::EnsEMBL::Utils::Exception ('throw');

51 52 53
use Bio::EnsEMBL::Hive::URLFactory;
use Bio::EnsEMBL::Hive::Extensions;

54
=head2 new
55 56 57 58 59 60

  Title   : new
  Usage   : ...AnalysisCtrlRule->new;
  Function: Constructor for empty AnalysisCtrlRule object
  Returns : Bio::EnsEMBL::Hive::AnalysisCtrlRule
  Args    : none
Jessica Severin's avatar
Jessica Severin committed
61
  
62 63 64
=cut

sub new {
65 66
    my $class   = shift @_;
    my $self    = bless {}, $class;
67
  
68 69 70 71 72 73 74 75 76 77 78 79
    my ( $dbID, $adaptor, $condition_analysis_url, $ctrled_analysis_id ) =
    rearrange( [ qw (DBID ADAPTOR CONDITION_ANALYSIS_URL CTRLED_ANALYSIS_ID) ], @_ );

        # database persistence:
    $self->dbID( $dbID )                            if(defined($dbID));
    $self->adaptor( $adaptor )                      if(defined($adaptor));

        # simple scalars:
    $self->condition_analysis_url( $condition_analysis_url )    if(defined($condition_analysis_url));
    $self->ctrled_analysis_id( $ctrled_analysis_id )            if(defined($ctrled_analysis_id));

    return $self;
80 81 82
}

sub adaptor {
83 84 85 86 87 88 89 90
    my $self = shift @_;

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

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


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

96 97
  Arg[1]  : (optional) int $dbID
  Usage   : $self->ctrled_analysis_id($dbID);
Jessica Severin's avatar
Jessica Severin committed
98 99
  Function: Get/set method for the analysis which will be BLOCKED until all
            of its condition analyses are 'DONE'. Specified as a dbID.
100
  Returns : integer
Jessica Severin's avatar
Jessica Severin committed
101
  
102
=cut
Jessica Severin's avatar
Jessica Severin committed
103

104 105 106 107 108 109 110 111 112 113 114
sub ctrled_analysis_id {
  my ($self,$analysis_id) = @_;
  if($analysis_id) {
    $self->{'_ctrled_analysis_id'} = $analysis_id;
    $self->{'_ctrled_analysis'} = undef;
  }
  return $self->{'_ctrled_analysis_id'};
}


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

116 117
  Arg[1]  : (optional) string $url
  Usage   : $self->condition_analysis_url($url);
Jessica Severin's avatar
Jessica Severin committed
118 119
  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.
120
  Returns : string
Jessica Severin's avatar
Jessica Severin committed
121
  
122
=cut
Jessica Severin's avatar
Jessica Severin committed
123

124 125 126 127 128 129 130 131 132 133 134
sub condition_analysis_url {
  my ($self,$url) = @_;
  if($url) {
    $self->{'_condition_analysis_url'} = $url;
    $self->{'_condition_analysis'} = undef;
  }
  return $self->{'_condition_analysis_url'};
}


=head2 ctrled_analysis
Jessica Severin's avatar
Jessica Severin committed
135

136
  Arg[1]  : (optional) Bio::EnsEMBL::Hive::Analysis object
137
  Usage   : $self->ctrled_analysis($anal);
Jessica Severin's avatar
Jessica Severin committed
138 139
  Function: Get/set method for the analysis which will be BLOCKED until all
            of its condition analyses are 'DONE'
140
  Returns : Bio::EnsEMBL::Hive::Analysis
Jessica Severin's avatar
Jessica Severin committed
141
  
142
=cut
Jessica Severin's avatar
Jessica Severin committed
143

144 145 146 147 148
sub ctrled_analysis {
  my ($self,$analysis) = @_;

  # setter mode
  if( defined $analysis ) {
149
    unless ($analysis->isa('Bio::EnsEMBL::Hive::Analysis')) {
150
      throw(
151
        "ctrled_analysis arg must be a [Bio::EnsEMBL::Hive::Analysis]".
152 153 154 155 156 157 158 159 160 161 162
        "not a [$analysis]");
    }
    $self->{'_ctrled_analysis'} = $analysis;
    $self->{'_ctrled_analysis_id'} = $analysis->dbID;
  }
  
  # lazy load the analysis object if I can
  if(!defined($self->{'_ctrled_analysis'})
     and defined($self->ctrled_analysis_id)
     and defined($self->adaptor))
  {
163
    $self->{'_ctrled_analysis'} = $self->adaptor->db->get_AnalysisAdaptor->fetch_by_dbID($self->ctrled_analysis_id);
164 165 166 167 168 169
  }
  return $self->{'_ctrled_analysis'};
}


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

171
  Arg[1]  : (optional) Bio::EnsEMBL::Hive::Analysis object
172
  Usage   : $self->condition_analysis($anal);
Jessica Severin's avatar
Jessica Severin committed
173 174
  Function: Get/set method for the analysis which must be 'DONE' in order for
            the controlled analysis to be un-BLOCKED
175
  Returns : Bio::EnsEMBL::Hive::Analysis
Jessica Severin's avatar
Jessica Severin committed
176
  
177
=cut
Jessica Severin's avatar
Jessica Severin committed
178

179 180 181 182
sub condition_analysis {
  my ($self,$analysis) = @_;

  if( defined $analysis ) {
183
    unless ($analysis->isa('Bio::EnsEMBL::Hive::Analysis')) {
184
      throw(
185
        "condition_analysis arg must be a [Bio::EnsEMBL::Hive::Analysis]".
186 187 188 189 190 191 192 193 194 195 196 197 198 199
        "not a [$analysis]");
    }
    $self->{'_condition_analysis'} = $analysis;

    #if the 'condition' and 'ctrled' share the same adaptor, then use a simple logic_name
    #for the URL rather than a full network distributed URL
    if($self->ctrled_analysis and ($self->ctrled_analysis->adaptor == $analysis->adaptor)) {
      $self->{'_condition_analysis_url'} = $analysis->logic_name;
    } else {
      $self->{'_condition_analysis_url'} = $analysis->url;
    }
  }
  # lazy load the analysis object if I can
  if(!defined($self->{'_condition_analysis'}) and defined($self->condition_analysis_url)) {
200
    $analysis =  Bio::EnsEMBL::Hive::URLFactory->fetch($self->condition_analysis_url);
201 202 203 204 205 206 207 208 209 210
    unless($analysis) {
      $analysis =
        $self->adaptor->db->get_AnalysisAdaptor->fetch_by_logic_name($self->condition_analysis_url);
    }
    $self->{'_condition_analysis'} = $analysis;
      
  }
  return $self->{'_condition_analysis'};
}

Jessica Severin's avatar
Jessica Severin committed
211

212 213 214 215 216 217
=head2 toString

  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
218 219 220

=cut

221 222 223 224 225 226 227 228 229 230 231
sub toString {
    my $self = shift;

    return join('',
            'AnalysisCtrlRule',
#            '(dbID=', ($self->dbID || '?'), ')',   # this object doesn't have a dbID
            ': ',
            $self->condition_analysis_url,
            ' -| ',
            $self->ctrled_analysis->logic_name,
    );
232 233
}

234

235 236 237 238
1;