Coverage for /home/kale/research/software/libraries/dirty_water/dirty_water/reaction.py : 77%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3
self.load_std_reagents(std_reagents)
return 'Reaction()'
else:
def num_reactions(self):
def num_reactions(self, num_reactions):
def extra_master_mix(self):
def extra_master_mix(self, percent):
def scale(self):
def volume(self):
def volume(self, volume): ratio = volume / self.volume for reagent in self: reagent.std_volume *= ratio
def volume_unit(self):
def volume_str(self):
def reagent_table(self):
""" Eliminate columns the user doesn't want to see. """ del cols[3] del cols[2]
# Figure out how big the table should be.
"Reagent", "Conc", "Each Rxn", "Master Mix", ) '', '', self.volume_str, self['master mix'].volume_str, ) lambda x: x.name, lambda x: x.stock_conc_str, lambda x: x.volume_str, lambda x: x.scaled_volume_str, ) max(map(len, [title, footer] + [getter(x) for x in self])) for title, footer,getter in zip(column_titles, column_footers, column_getters) ] '{{:{}{}}}'.format(column_alignments[i], column_widths[i]) for i in range(len(column_titles)) )
# Print the table
row_template.format(*column_titles), rule, ] + [ row_template.format( *[getter(reagent) for getter in column_getters]) for reagent in self ] rule, row_template.format(*column_footers), ]
lines = std_reagents.strip().split('\n')
# Examine the second line of the table to determine where each column # starts and stops.
column_slices = [ slice(x.start(), x.end()) for x in re.finditer('[-=]+', lines[1]) ] if len(column_slices) != 4: raise UserInputError("Expected to find 4 columns, delineated by '=' or '-' in the second line.")
def split_columns(line): return tuple(line[x].strip() for x in column_slices)
# Parse standard concentrations and volumes from each line in the # table.
def parse_amount(x, unit_required=True): try: amount, unit = x.split() return float(amount), unit except ValueError: if unit_required: raise else: return x or None
for line in lines[2:]: reagent, stock_conc, volume, master_mix = split_columns(line) self[reagent].std_stock_conc = parse_amount(stock_conc, False) self[reagent].std_volume = parse_amount(volume) self[reagent].master_mix = (master_mix == 'yes')
return 'Reagent({0.name})'.format(self)
return '{0.volume_str} {0.name}'.format(self)
def std_stock_conc(self):
def std_stock_conc(self, conc): else:
def std_conc(self): return self.std_stock_conc * self.std_volume / self.reaction.volume
def std_volume(self):
def std_volume(self, volume): else:
def stock_conc(self):
def stock_conc(self, stock_conc): if not isinstance(self.std_stock_conc, numbers.Real): raise UserInputError("The 'std_stock_conc' for '{}' isn't numeric, so 'stock_conc' can't be changed.".format(self.name)) self._stock_conc = float(stock_conc)
def stock_conc_str(self): else:
def conc(self): return self._conc or self.std_conc
def conc(self, conc): if not isinstance(self.std_stock_conc, numbers.Real): raise UserInputError("The 'std_stock_conc' for '{}' isn't numeric, so 'conc' can't be changed.".format(self.name)) self._conc = float(conc)
def volume(self): # It isn't possible to calculate std_conc for reagents for which # std_stock_conc is a string (i.e. '10x') or left undefined (i.e. # water). So don't calculate a new volume if std_volume will do. else: return self.reaction.volume * self.conc / self.stock_conc
def volume_str(self):
def scaled_volume_str(self): else: round_to_pipet(self.volume * self.reaction.scale), self.volume_unit)
def volume(self):
from warnings import warn warn("Reaction volume exceeds {}".format(self.reaction.volume_str))
def volume(self):
def volume_unit(self):
def volume_unit(self, unit):
|