DataflowRule.pm 5.84 KB
Newer Older
1 2 3 4 5 6 7 8 9
# Perl module for Bio::EnsEMBL::Hive::DataflowRule
#
# Creator: Jessica Severin <jessica@ebi.ac.uk>
# Date of creation: 22.03.2004
#
# Copyright EMBL-EBI 2000-2004
#
# You may distribute this module under the same terms as perl itself

10
=pod
11 12

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

14 15 16 17 18
  Bio::EnsEMBL::Hive::DataflowRule

=head1 SYNOPSIS

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

20 21 22 23 24 25 26 27 28
  Needed a robust and simpler rule table
  where Analyses in the pipeline can robustly define
  new analyses and rules.  New design has a single table where a 'rule'
  is a simple link from one analysis to another.
  Extended from design of SimpleRule concept to allow the 'to' analysis to
  be specified with a network savy URL like
  mysql://ensadmin:<pass>@ecs2:3361/compara_hive_test?analysis.logic_name='blast_NCBI34'

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

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

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

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

=cut


package Bio::EnsEMBL::Hive::DataflowRule;

use strict;
43 44 45
use Bio::EnsEMBL::Utils::Argument;
use Bio::EnsEMBL::Utils::Exception;
use Bio::EnsEMBL::Hive::URLFactory;
46 47 48 49 50 51 52


=head2 Constructor

  Title   : new
  Usage   : ...DataflowRule->new($analysis);
  Function: Constructor for DataflowRule object
Jessica Severin's avatar
Jessica Severin committed
53
  Returns : Bio::EnsEMBL::Hive::DataflowRule
54 55
  Args    : A Bio::EnsEMBL::Analysis object. Conditions are added later,
            adaptor and dbid only used from the adaptor.
Jessica Severin's avatar
Jessica Severin committed
56
            
57 58 59 60 61
=cut


sub new {
  my ($class,@args) = @_;
62
  my $self = bless {}, $class;
63 64

  my ( $dbID, $adaptor, $fromAnalysis, %fromID, $toAnalysis, $toURL ) =
65
    rearrange( [ qw (DBID ADAPTOR FROM_ANALYSIS FROM_ID TO_ANALYSIS TO_URL) ], @args );
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    
  $self->dbID($dbID) if(defined($dbID));
  $self->adaptor($adaptor) if(defined($adaptor));
  $self->from_analysis($fromAnalysis) if(defined($fromAnalysis));
  $self->to_analysis($toAnalysis ) if(defined($toAnalysis));

  return $self;
}

sub dbID {
  my ( $self, $dbID ) = @_;
  $self->{'_dbID'} = $dbID if defined $dbID;
  return $self->{'_dbID'};
}

sub adaptor {
  my ( $self, $adaptor ) = @_;
  $self->{'_adaptor'} = $adaptor if defined $adaptor;
  return $self->{'_adaptor'};
}


=head2 branch_code
Jessica Severin's avatar
Jessica Severin committed
89

90 91 92 93 94
  Title   : branch_code
  Arg[1]  : (optional) int $code
  Usage   : $self->branch_code($code);
  Function: Get/set method for rules branch_code.
  Returns : integer
Jessica Severin's avatar
Jessica Severin committed
95
  
96
=cut
Jessica Severin's avatar
Jessica Severin committed
97

98 99 100 101 102 103 104 105 106 107
sub branch_code {
  #default branch_code = 1
  my( $self, $value ) = @_;
  $self->{'_branch_code'} = 1 unless(defined($self->{'_branch_code'}));
  $self->{'_branch_code'} = $value if(defined($value));
  return $self->{'_branch_code'};
}


=head2 from_analysis_id
Jessica Severin's avatar
Jessica Severin committed
108

109 110 111 112 113
  Title   : from_analysis_id
  Arg[1]  : (optional) int $dbID
  Usage   : $self->from_analysis_id($dbID);
  Function: Get/set method for the 'from' analysis objects dbID of this rule.
  Returns : integer
Jessica Severin's avatar
Jessica Severin committed
114
  
115
=cut
Jessica Severin's avatar
Jessica Severin committed
116

117 118 119 120 121 122 123 124 125 126 127
sub from_analysis_id {
  my ($self,$analysis_id) = @_;
  if($analysis_id) {
    $self->{'_from_analysis_id'} = $analysis_id;
    $self->{'_from_analysis'} = undef;
  }
  return $self->{'_from_analysis_id'};
}


=head2 to_analysis_url
Jessica Severin's avatar
Jessica Severin committed
128

129 130 131 132 133
  Title   : to_analysis_url
  Arg[1]  : (optional) string $url
  Usage   : $self->to_analysis_url($url);
  Function: Get/set method for the 'to' analysis objects URL for this rule
  Returns : string
Jessica Severin's avatar
Jessica Severin committed
134
  
135
=cut
Jessica Severin's avatar
Jessica Severin committed
136

137 138 139 140 141 142 143 144 145 146 147
sub to_analysis_url {
  my ($self,$url) = @_;
  if($url) {
    $self->{'_to_analysis_url'} = $url;
    $self->{'_to_analysis'} = undef;
  }
  return $self->{'_to_analysis_url'};
}


=head2 from_analysis
Jessica Severin's avatar
Jessica Severin committed
148

149 150 151 152 153
  Title   : from_analysis
  Usage   : $self->from_analysis($anal);
  Function: Get/set method for the condition analysis object of this rule.
  Returns : Bio::EnsEMBL::Analysis
  Args    : Bio::EnsEMBL::Analysis
Jessica Severin's avatar
Jessica Severin committed
154
  
155
=cut
Jessica Severin's avatar
Jessica Severin committed
156

157 158 159 160 161 162
sub from_analysis {
  my ($self,$analysis) = @_;

  # setter mode
  if( defined $analysis ) {
    unless ($analysis->isa('Bio::EnsEMBL::Analysis')) {
163
      throw(
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        "from_analysis arg must be a [Bio::EnsEMBL::Analysis]".
        "not a [$analysis]");
    }
    $self->{'_from_analysis'} = $analysis;
    $self->{'_from_analysis_id'} = $analysis->dbID;
  }
  
  # lazy load the analysis object if I can
  if(!defined($self->{'_from_analysis'})
     and defined($self->from_analysis_id)
     and defined($self->adaptor))
  {
    $self->{'_from_analysis'} =
      $self->adaptor->db->get_AnalysisAdaptor->fetch_by_dbID($self->from_analysis_id);
  }
  return $self->{'_from_analysis'};
}


=head2 to_analysis
Jessica Severin's avatar
Jessica Severin committed
184

185 186 187 188 189
  Title   : to_analysis
  Usage   : $self->to_analysis($anal);
  Function: Get/set method for the goal analysis object of this rule.
  Returns : Bio::EnsEMBL::Analysis
  Args    : Bio::EnsEMBL::Analysis
Jessica Severin's avatar
Jessica Severin committed
190
  
191
=cut
Jessica Severin's avatar
Jessica Severin committed
192

193 194 195 196 197
sub to_analysis {
  my ($self,$analysis) = @_;

  if( defined $analysis ) {
    unless ($analysis->isa('Bio::EnsEMBL::Analysis')) {
198
      throw(
199 200 201 202
        "to_analysis arg must be a [Bio::EnsEMBL::Analysis]".
        "not a [$analysis]");
    }
    $self->{'_to_analysis'} = $analysis;
Jessica Severin's avatar
Jessica Severin committed
203 204 205

    #if the 'from' and 'to' share the same adaptor, then use a simple logic_name
    #for the URL rather than a full network distributed URL
206 207 208 209 210
    if($self->from_analysis and ($self->from_analysis->adaptor == $analysis->adaptor)) {
      $self->{'_to_analysis_url'} = $analysis->logic_name;
    } else {
      $self->{'_to_analysis_url'} = $analysis->url;
    }
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 237
  }
  # lazy load the analysis object if I can
  if(!defined($self->{'_to_analysis'}) and defined($self->to_analysis_url)) {
    my $analyis =  Bio::EnsEMBL::Hive::URLFactory->fetch($self->to_analysis_url);
    unless($analysis) {
      $analysis =
        $self->adaptor->db->get_AnalysisAdaptor->fetch_by_logic_name($self->to_analysis_url);
    }
    $self->{'_to_analysis'} = $analysis;
      
  }
  return $self->{'_to_analysis'};
}

sub print_rule {
  my $self = shift;
  print("DataflowRule dbID=", $self->dbID,
        "  from_id=", $self->from_analysis_id,
        "  to_url=", $self->to_analysis_url,
        "  branch=", $self->branch_code,
        "\n");
}

1;