ensembl-hive-python3  2.4
AddTogether.py
Go to the documentation of this file.
1 
2 import eHive
3 
4 import time
5 
7  """Runnable that adds up all the partial-multiplications from PartMultiply"""
8 
9  def param_defaults(self):
10  return {
11  'take_time' : 0,
12  'partial_product' : {}
13  }
14 
15 
16  def fetch_input(self):
17  a_multiplier = self.param_required('a_multiplier')
18  partial_product = self.param('partial_product')
19  print(partial_product)
20 
21  partial_product['1'] = str(a_multiplier)
22  partial_product['0'] = '0'
23 
24 
25  def run(self):
26  b_multiplier = self.param_required('b_multiplier')
27  partial_product = self.param('partial_product')
28  self.param('result', add_together(b_multiplier, partial_product))
29  time.sleep( self.param('take_time') )
30 
31  def write_output(self):
32  self.dataflow( { 'result': self.param('result') }, 1)
33 
34 
35 
36 def add_together(b_multiplier, partial_product):
37 
38  b_multiplier = str(b_multiplier)
39  accu = [0] * (1 + len(b_multiplier) + len(partial_product['1']))
40 
41  for (i,b_digit) in enumerate(reversed(b_multiplier)):
42  product = str(partial_product[b_digit])
43  for (j,p_digit) in enumerate(reversed(product)):
44  accu[i+j] += int(p_digit)
45 
46  carry = 0
47  for i in range(len(accu)):
48  val = carry + accu[i]
49  accu[i] = val % 10
50  carry = val // 10
51 
52  return ''.join(str(_) for _ in reversed(accu)).lstrip('0')
53 
54 1;
def param_required(self, param_name)
Returns the value of the parameter "param_name" or raises an exception if anything wrong happens or t...
Definition: Process.py:245
Runnable that adds up all the partial-multiplications from PartMultiply.
Definition: AddTogether.py:8
def add_together(b_multiplier, partial_product)
Definition: AddTogether.py:37
This is the counterpart of GuestProcess.
Definition: Process.py:51
def param(self, param_name, args)
When called as a setter: sets the value of the parameter "param_name".
Definition: Process.py:259
def dataflow(self, output_ids, branch_name_or_code=1)
Dataflows the output_id(s) on a given branch (default 1).
Definition: Process.py:215