AnalysisCtrlRule.pm 6.69 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 20 21 22 23 24 25 26 27 28
    Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

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

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

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

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

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

=cut


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

44
use strict;
45 46
use Scalar::Util ('weaken');

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

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

53
=head2 new
54 55 56 57 58 59

  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
60
  
61 62 63
=cut

sub new {
64 65
    my $class   = shift @_;
    my $self    = bless {}, $class;
66
  
67 68 69 70 71 72 73 74 75 76 77 78
    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;
79 80 81
}

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

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

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


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

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

103 104 105 106 107 108 109 110 111 112 113
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
114

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

123 124 125 126 127 128 129 130 131 132 133
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
134

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

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

  # setter mode
  if( defined $analysis ) {
148
    unless ($analysis->isa('Bio::EnsEMBL::Hive::Analysis')) {
149
      throw(
150
        "ctrled_analysis arg must be a [Bio::EnsEMBL::Hive::Analysis]".
151 152 153 154 155 156 157 158 159 160 161
        "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))
  {
162
    $self->{'_ctrled_analysis'} = $self->adaptor->db->get_AnalysisAdaptor->fetch_by_dbID($self->ctrled_analysis_id);
163 164 165 166 167 168
  }
  return $self->{'_ctrled_analysis'};
}


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

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

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

  if( defined $analysis ) {
182
    unless ($analysis->isa('Bio::EnsEMBL::Hive::Analysis')) {
183
      throw(
184
        "condition_analysis arg must be a [Bio::EnsEMBL::Hive::Analysis]".
185 186 187 188 189 190 191 192 193 194 195 196 197 198
        "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)) {
199
    $analysis =  Bio::EnsEMBL::Hive::URLFactory->fetch($self->condition_analysis_url);
200 201 202 203 204 205 206 207 208 209
    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
210

211 212 213 214 215 216
=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
217 218 219

=cut

220 221 222 223 224 225 226 227 228 229 230
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,
    );
231 232
}

233

234 235 236 237
1;