ensembl-hive  2.8.1
LongMultWf_conf.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  # initialize the database and build the graph in it (it will also print the value of EHIVE_URL) :
11 
12  # optionally also seed it with your specific values:
13  seed_pipeline.pl -url $EHIVE_URL -logic_name take_b_apart -input_id '{ "a_multiplier" => "12345678", "b_multiplier" => "3359559666" }'
14 
15  # run the pipeline:
16  beekeeper.pl -url $EHIVE_URL -loop
17 
18 =head1 DESCRIPTION
19 
20  This is the PipeConfig file for the long multiplication pipeline example.
21  The main point of this pipeline is to provide an example of how to write Hive Runnables and link them together into a pipeline.
22 
23  Please refer to Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf module to understand the interface implemented here.
24 
25  The setting. let's assume we are given two loooooong numbers to multiply. reeeeally long.
26  soooo long that they do not fit into registers of the cpu and should be multiplied digit-by-digit.
27  For the purposes of this example we also assume this task is very computationally intensive and has to be done in parallel.
28 
29  The long multiplication pipeline consists of three "analyses" (types of tasks):
30  'take_b_apart', 'part_multiply' and 'add_together' that we use to examplify various features of the Hive.
31 
32  * A 'take_b_apart' job takes in two string parameters, 'a_multiplier' and 'b_multiplier',
33  takes the second one apart into digits, finds what _different_ digits are there,
34  creates several jobs of the 'part_multiply' analysis and one job of 'add_together' analysis.
35 
36  * A 'part_multiply' job takes in 'a_multiplier' and 'digit', multiplies them and accumulates the result in 'partial_product' accumulator.
37 
38  * An 'add_together' job waits for the first two analyses to complete,
39  takes in 'a_multiplier', 'b_multiplier' and 'partial_product' hash and produces the final result in 'final_result' table.
40 
41  Please see the implementation details in Runnable modules themselves.
42 
43 =head1 LICENSE
44 
45  See the NOTICE file distributed with this work for additional information
46  regarding copyright ownership.
47 
48  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
49  You may obtain a copy of the License at
50 
51  http://www.apache.org/licenses/LICENSE-2.0
52 
53  Unless required by applicable law or agreed to in writing, software distributed under the License
54  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55  See the License for the specific language governing permissions and limitations under the License.
56 
57 =head1 CONTACT
58 
59  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
60 
61 =cut
62 
63 
65 
66 use strict;
67 use warnings;
68 
69 use base ('Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf'); # All Hive databases configuration files should inherit from HiveGeneric, directly or indirectly
70 use Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf; # Allow this particular config to use conditional dataflow and INPUT_PLUS
71 
72 
73 =head2 pipeline_create_commands
74 
75  Description : Implements pipeline_create_commands() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that lists the commands that will create and set up the Hive database.
76  In addition to the standard creation of the database and populating it with Hive tables and procedures it also creates two pipeline-specific tables used by Runnables to communicate.
77 
78 =cut
79 
80 sub pipeline_create_commands {
81  my ($self) = @_;
82  return [
83  @{$self->SUPER::pipeline_create_commands}, # inheriting database and hive tables' creation
84 
85  # additional tables needed for long multiplication pipeline's operation:
86  $self->db_cmd('CREATE TABLE final_result (a_multiplier varchar(255) NOT NULL, b_multiplier varchar(255) NOT NULL, result varchar(255) NOT NULL, PRIMARY KEY (a_multiplier, b_multiplier))'),
87  $self->db_cmd('CREATE TABLE intermediate_result (a_multiplier varchar(255) NOT NULL, digit char(1) NOT NULL, partial_product varchar(255) NOT NULL, PRIMARY KEY (a_multiplier, digit))'),
88 
89 # 'rm -f foreign_db',
90 
91 # $self->db_cmd('CREATE TABLE intermediate_result (a_multiplier varchar(255) NOT NULL, digit char(1) NOT NULL, partial_product varchar(255) NOT NULL, PRIMARY KEY (a_multiplier, digit))', 'sqlite:
92  ];
93 }
94 
95 
96 =head2 pipeline_wide_parameters
97 
98  Description : Interface method that should return a hash of pipeline_wide_parameter_name->pipeline_wide_parameter_value pairs.
99  The value doesn't have to be a scalar, can be any Perl structure now (will be stringified and de-stringified automagically).
100  Please see existing PipeConfig modules for examples.
101 
102 =cut
103 
104 sub pipeline_wide_parameters {
105  my ($self) = @_;
106  return {
107  %{$self->SUPER::pipeline_wide_parameters}, # here we inherit anything from the base class
108 
109  'take_time' => 1,
110  };
111 }
112 
113 
114 =head2 pipeline_analyses
115 
116  Description : Implements pipeline_analyses() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that defines the structure of the pipeline: analyses, jobs, rules, etc.
117  Here it defines three analyses:
118  * 'take_b_apart' that is auto-seeded with a pair of jobs (to check the commutativity of multiplication).
119  Each job will dataflow (create more jobs) via branch #2 into 'part_multiply' and via branch #1 into 'add_together'.
120 
121  * 'part_multiply' with jobs fed from take_b_apart#2.
122  It multiplies input parameters 'a_multiplier' and 'digit' and dataflows 'partial_product' parameter into branch #1.
123 
124  * 'add_together' with jobs fed from take_b_apart#1.
125  It adds together results of partial multiplication computed by 'part_multiply'.
126  These results are accumulated in 'partial_product' hash.
127  Until the hash is complete the corresponding 'add_together' job is blocked by a semaphore.
128 
129 =cut
130 
131 sub pipeline_analyses {
132  my ($self) = @_;
133  return [
134  { -logic_name => 'take_b_apart',
136  -meadow_type=> 'LOCAL', # do not bother the farm with such a simple task (and get it done faster)
137  -analysis_capacity => 2, # use per-analysis limiter
138  -input_ids => [
139  { 'a_multiplier' => '9650156169', 'b_multiplier' => '327358788' },
140  { 'a_multiplier' => '327358788', 'b_multiplier' => '9650156169' },
141  ],
142  -flow_into => {
143  # A WHEN block is not a hash, so multiple occurences of each condition (including ELSE) is permitted.
144  2 => WHEN(
145  '#digit#>1' => { 'part_multiply' => INPUT_PLUS() }, # make parent job's parameters available to the kids
146  ),
147  1 => [ 'add_together' ],
148  },
149  },
150 
151  { -logic_name => 'part_multiply',
152  -module => 'Bio::EnsEMBL::Hive::Examples::LongMult::RunnableDB::PartMultiply',
153  -analysis_capacity => 4, # use per-analysis limiter
154  -flow_into => {
155  1 => {
156  '?table_name=intermediate_result' => INPUT_PLUS( { 'partial_product' => '#product#' } ),
157  },
158  },
159  -can_be_empty => 1,
160  },
161 
162  { -logic_name => 'add_together',
163  -module => 'Bio::EnsEMBL::Hive::Examples::LongMult::RunnableDB::AddTogether',
164  -parameters => {
165  'intermediate_table_url' => '?table_name=intermediate_result',
166  },
167  -wait_for => [ 'part_multiply' ],
168  -flow_into => {
169  1 => [ '?table_name=final_result' ],
170  },
171  },
172  ];
173 }
174 
175 1;
176 
Bio::EnsEMBL::Hive::Examples::LongMult::RunnableDB::DigitFactory
Definition: DigitFactory.pm:25
Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultWf_conf
Definition: LongMultWf_conf.pm:47
main
public main()
Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf
Definition: HiveGeneric_conf.pm:54