def _getFitParameters(list_of_dicts, key): # Load rows of data x = _loadRow('doublingTime', list_of_dicts) y = _loadRow(key, list_of_dicts) # Save and strip units y_units = 1 x_units = 1 if units.hasUnit(y): y_units = units.getUnit(y) y = y.asNumber(y_units) if units.hasUnit(x): x_units = units.getUnit(x) x = x.asNumber(x_units) # Sort data for spine fitting (must be ascending order) idx_order = x.argsort() x = x[idx_order] y = y[idx_order] # Generate fit parameters = interpolate.splrep(x, y) if np.sum(np.absolute(interpolate.splev(x, parameters) - y)) / y.size > 1.: raise Exception( "Fitting {} with 3d spline, residuals are huge!".format(key)) return { 'parameters': parameters, 'x_units': x_units, 'y_units': y_units, 'dtype': y.dtype }
def _loadRow(key, list_of_dicts): if units.hasUnit(list_of_dicts[0][key]): row_units = units.getUnit(list_of_dicts[0][key]) return row_units * np.array( [x[key].asNumber(row_units) for x in list_of_dicts]) else: return np.array([x[key] for x in list_of_dicts])
def __init__(self, concDict, equilibriumReactions, nutrientData): self.units = units.getUnit(concDict.values()[0]) self.defaultConcentrationsDict = dict((key, concDict[key].asNumber(self.units)) for key in concDict) self.nutrient_data = nutrientData # factor of internal amino acid increase if maino acids present in nutrients self.moleculeScaleFactors = { "L-ALPHA-ALANINE[c]": 2., "ARG[c]": 2., "ASN[c]": 2., "L-ASPARTATE[c]": 2., "CYS[c]": 2., "GLT[c]": 1.1, "GLN[c]": 2., "GLY[c]": 2., "HIS[c]": 2., "ILE[c]": 2., "LEU[c]": 2., "LYS[c]": 2., "MET[c]": 2., "PHE[c]": 2., "PRO[c]": 2., "SER[c]": 2., "THR[c]": 2., "TRP[c]": 2., "TYR[c]": 2., "L-SELENOCYSTEINE[c]": 2., "VAL[c]": 2., } self.moleculeSetAmounts = self._addMoleculeAmounts(equilibriumReactions, self.defaultConcentrationsDict)
def _buildTrnaData(self, raw_data, sim_data): growth_rate_unit = units.getUnit(raw_data.trnaData.trna_growth_rates[0]['growth rate']) self._trna_growth_rates = growth_rate_unit * np.array([x['growth rate'].asNumber() for x in raw_data.trnaData.trna_growth_rates]) trna_ratio_to_16SrRNA_by_growth_rate = [] for gr in self._trna_growth_rates: # This is a little crazy... trna_ratio_to_16SrRNA_by_growth_rate.append([x['ratio to 16SrRNA'] for x in getattr(raw_data.trnaData, "trna_ratio_to_16SrRNA_" + str(gr.asNumber()).replace('.','p'))]) self._trna_ratio_to_16SrRNA_by_growth_rate = np.array(trna_ratio_to_16SrRNA_by_growth_rate) self._trna_ids = [x['rna id'] for x in raw_data.trnaData.trna_ratio_to_16SrRNA_0p4]
def _calculateGrowthRateDependentDnaMass(self, doubling_time): C_PERIOD = self.c_period D_PERIOD = self.d_period CD_PERIOD = C_PERIOD + D_PERIOD if doubling_time < D_PERIOD: raise Exception, "Can't have doubling time shorter than cytokinesis time!" doubling_time_unit = units.getUnit(doubling_time) # TODO: If you really care, this should be a loop. # It is optimized to run quickly over the range of T_d # and C and D periods that we have. return self.chromosomeSequenceMass * (1 + 1 * (np.maximum(0. * doubling_time_unit, CD_PERIOD - doubling_time) / C_PERIOD) + 2 * (np.maximum(0. * doubling_time_unit, CD_PERIOD - 2 * doubling_time) / C_PERIOD) + 4 * (np.maximum(0. * doubling_time_unit, CD_PERIOD - 4 * doubling_time) / C_PERIOD) )
def __setitem__(self, key, value): if units_pkg.hasUnit(value): try: self.units[key].matchUnits(value) except unum.IncompatibleUnitsError: raise Exception, 'Units do not match!\n' self.struct_array[key] = value.asNumber() self.units[key] = units_pkg.getUnit(value) elif type(value) == list or type(value) == np.ndarray: if units_pkg.hasUnit(self.units[key]): raise Exception, 'Units do not match! Quantity has units your input does not!\n' self.struct_array[key] = value self.units[key] = None else: raise Exception, 'Cant assign data-type other than unum datatype or list/numpy array!\n'