10 to understand how
this particular example pipeline is configured and ran.
14 'Bio::EnsEMBL::Hive::Examples::LongMult::RunnableDB::PartMultiply' has a separate task of multiplying
'a_multiplier' by the given
'digit',
15 then it passes its partial product on.
19 See the NOTICE file distributed with
this work
for additional information
20 regarding copyright ownership.
22 Licensed under the Apache License, Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
23 You may obtain a copy of the License at
27 Unless required by applicable law or agreed to in writing, software distributed under the License
28 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 See the License
for the specific language governing permissions and limitations under the License.
33 Please subscribe to the Hive mailing list: http:
38 package Bio::EnsEMBL::Hive::Examples::LongMult::RunnableDB::PartMultiply;
43 use base (
'Bio::EnsEMBL::Hive::Process');
48 Description : Implements param_defaults()
interface method of
Bio::EnsEMBL::Hive::Process that defines module defaults for parameters.
55 'take_time' => 0, # how much time
run() method will spend in sleeping state
62 Description : Implements fetch_input()
interface method of
Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
63 Here we have nothing to fetch.
72 Description : Implements
run()
interface method of
Bio::EnsEMBL::Hive::Process that is used to perform the
main bulk of the job (minus input and output).
73 The only thing we do here is make a call to the recursive function that will compute the product.
75 param('a_multiplier'): The first long number (a string of digits - doesn't have to fit a register).
77 param('digit'): A decimal digit that is a part of the second multiplier.
79 param('take_time'): How much time to spend sleeping (seconds).
83 sub run { # call the recursive function that will compute the stuff
86 my $a_multiplier = $self->param_required('a_multiplier');
87 my $digit = $self->param_required('digit');
89 $self->param('product', _rec_multiply($a_multiplier, $digit, 0) || 0);
91 sleep( $self->param('take_time') );
96 Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
97 Dataflows the intermediate results down branch 1, which will be routed into 'partial_product' accumulator.
101 sub write_output { # but this time we have something to store
104 $self->dataflow_output_id( {
105 'product' => $self->param('product')
111 Description: this is a
private function (not a method) that performs recursive multiplication of a long number by a digit with a carry.
116 my ($a_multiplier, $digit, $carry) = @_;
119 unless($a_multiplier) {
120 return ($carry ||
'');
124 if($a_multiplier=~/^(\d*)(\d)$/) {
125 my ($prefix, $last_digit) = ($1, $2);
127 my $this_product = $last_digit*$digit+$carry;
128 my $this_result = $this_product % 10;
129 my $this_carry = int($this_product / 10);
131 return _rec_multiply($prefix, $digit, $this_carry).$this_result;
133 die
"'a_multiplier' has to be a decimal number";