Analysis.pm 6.59 KB
Newer Older
1 2 3 4
=pod 

=head1 NAME

5
    Bio::EnsEMBL::Hive::Analysis
6 7 8 9 10 11 12 13 14 15

=head1 DESCRIPTION

    An Analysis object represents a "stage" of the Hive pipeline that groups together
    all jobs that share the same module and the same common parameters.

    Individual Jobs are said to "belong" to an Analysis.

    Control rules unblock when their condition Analyses are done.

16 17
=head1 LICENSE

18
    Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
19 20 21 22 23 24 25 26 27 28

    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

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

=cut

35

36 37 38
package Bio::EnsEMBL::Hive::Analysis;

use strict;
39 40

use Bio::EnsEMBL::Utils::Argument ('rearrange');
41

42 43
use Bio::EnsEMBL::Hive::Utils ('stringify');

44 45 46 47 48 49 50 51 52
use base (  'Bio::EnsEMBL::Storable',       # inherit dbID(), adaptor() and new() methods
         );
 

sub new {
    my $class = shift @_;

    my $self = $class->SUPER::new( @_ );    # deal with Storable stuff

53 54
    my ($logic_name, $module, $parameters, $resource_class_id, $failed_job_tolerance, $max_retry_count, $can_be_empty, $priority, $meadow_type, $analysis_capacity) =
         rearrange([qw(logic_name module parameters resource_class_id failed_job_tolerance max_retry_count can_be_empty priority meadow_type analysis_capacity) ], @_);
55 56 57 58 59 60 61 62 63

    $self->logic_name($logic_name)                      if($logic_name);
    $self->module($module)                              if($module);
    $self->parameters($parameters)                      if($parameters);
    $self->resource_class_id($resource_class_id)        if($resource_class_id);
    $self->failed_job_tolerance($failed_job_tolerance)  if($failed_job_tolerance);
    $self->max_retry_count($max_retry_count)            if($max_retry_count);
    $self->can_be_empty($can_be_empty)                  if($can_be_empty);
    $self->priority($priority)                          if($priority);
64
    $self->meadow_type($meadow_type)                    if($meadow_type);
65
    $self->analysis_capacity($analysis_capacity)        if( defined($analysis_capacity) );
66 67 68 69 70 71

    return $self;
}


sub logic_name {
72 73
    my $self = shift;
    $self->{'_logic_name'} = shift if(@_);
74 75 76 77 78
    return $self->{'_logic_name'};
}


sub module {
79 80
    my $self = shift;
    $self->{'_module'} = shift if(@_);
81 82 83 84 85
    return $self->{'_module'};
}


sub parameters {
86
    my $self = shift;
87 88 89 90
    if(@_) {
        my $parameters = shift @_;
        $self->{'_parameters'} = ref($parameters) ? stringify($parameters) : $parameters;
    }
91 92 93 94
    return $self->{'_parameters'};
}


95
sub resource_class_id {
96 97 98 99
    my $self = shift;
    $self->{'_resource_class_id'} = shift if(@_);
    return $self->{'_resource_class_id'};
}
100 101


102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
sub failed_job_tolerance {
    my $self = shift;
    $self->{'_failed_job_tolerance'} = shift if(@_);
    $self->{'_failed_job_tolerance'} = 0 unless(defined($self->{'_failed_job_tolerance'}));
    return $self->{'_failed_job_tolerance'};
}


sub max_retry_count {
    my $self = shift;
    $self->{'_max_retry_count'} = shift if(@_);
    $self->{'_max_retry_count'} = 3 unless(defined($self->{'_max_retry_count'}));
    return $self->{'_max_retry_count'};
}


sub can_be_empty {
    my $self = shift;
    $self->{'_can_be_empty'} = shift if(@_);
    $self->{'_can_be_empty'} = 0 unless(defined($self->{'_can_be_empty'}));
    return $self->{'_can_be_empty'};
}


sub priority {
    my $self = shift;
    $self->{'_priority'} = shift if(@_);
    $self->{'_priority'} = 0 unless(defined($self->{'_priority'}));
    return $self->{'_priority'};
131 132 133
}


134 135 136 137 138 139 140
sub meadow_type {
    my $self = shift;
    $self->{'_meadow_type'} = shift if(@_);
    return $self->{'_meadow_type'};
}


141 142 143 144 145 146 147
sub analysis_capacity {
    my $self = shift;
    $self->{'_analysis_capacity'} = shift if(@_);
    return $self->{'_analysis_capacity'};
}


148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
sub get_compiled_module_name {
    my $self = shift;

    my $runnable_module_name = $self->module
        or die "Analysis '".$self->logic_name."' does not have its 'module' defined";

    eval "require $runnable_module_name";
    die "The runnable module '$runnable_module_name' cannot be loaded or compiled:\n$@" if($@);
    die "Problem accessing methods in '$runnable_module_name'. Please check that it inherits from Bio::EnsEMBL::Hive::Process and is named correctly.\n"
        unless($runnable_module_name->isa('Bio::EnsEMBL::Hive::Process'));

    return $runnable_module_name;
}


163 164 165 166 167 168 169 170 171 172 173 174 175 176
=head2 process

  Arg [1]    : none
  Example    : $process = $analysis->process;
  Description: construct a Process object from the $analysis->module name
  Returntype : Bio::EnsEMBL::Hive::Process subclass 
  Exceptions : none
  Caller     : general

=cut

sub process {
    my $self = shift;

177
    my $runnable_object = $self->get_compiled_module_name->new( -analysis => $self );
178

179
    return $runnable_object;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
}


=head2 url

  Arg [1]    : none
  Example    : $url = $analysis->url;
  Description: Constructs a URL string for this database connection
               Follows the general URL rules.
  Returntype : string of format
               mysql://<user>:<pass>@<host>:<port>/<dbname>/analysis?logic_name=<name>
  Exceptions : none
  Caller     : general

=cut

sub url {
    my $self = shift;

    return undef unless($self->adaptor);

    return $self->adaptor->db->dbc->url . '/analysis?logic_name=' . $self->logic_name;
}


=head2 stats

  Arg [1]    : none
  Example    : $stats = $analysis->stats;
  Description: returns the AnalysisStats object associated with this Analysis
               object.  Does not cache, but pull from database by using the
               Analysis objects adaptor->db.
  Returntype : Bio::EnsEMBL::Hive::AnalysisStats object
  Exceptions : none
  Caller     : general

=cut

sub stats {
    my $self = shift;

    # Not cached internally since we want it to always be in sync with the database.
    # Otherwise the user application would need to be aware of the sync state and send explicit 'sync' calls.

    my $stats = $self->adaptor->db->get_AnalysisStatsAdaptor->fetch_by_analysis_id($self->dbID);
    return $stats;
}


sub toString {
    my $self = shift @_;

    return (ref($self).': '.join(', ', map { $_.'="'.$self->$_().'"' } qw(dbID logic_name module parameters) ));
}

1;