def __prepareProblem(self, lp): """Prepares the lp construct for analysis Transposes the stoichiometric matrix S_ij -> S^T Columns(Reactions) become rows and rows(Metabolites) become columns Previous column, now row bounds are set to 0 Previous row, now column bounds are set to > 0 """ oldProb = Metabolism(lp) biomR = [r for r in oldProb.getColumnIDs() if re.search(".*.*", r, re.IGNORECASE)][0] print biomR oldProb.deleteReactionsFromStoich([biomR]) oldProb.eraseHistory() newProb = Metabolism(glp_create_prob()) for elem in range(1, oldProb.getNumCols() + 1): columnsDict = dict() identifier = glp_get_col_name(oldProb.lp, elem) colCoefList = oldProb.getColumnCoef(elem) columnsDict[identifier] = (0, 0, colCoefList) newProb.addRows(columnsDict) for elem in range(1, oldProb.getNumRows() + 1): rowsDict = dict() identifier = glp_get_row_name(oldProb.lp, elem) rowCoefList = oldProb.getRowCoef(elem) rowsDict[identifier] = (0, 10000, rowCoefList) newProb.addColumns(rowsDict) newProb.eraseHistory() return newProb.lp
lp = Metabolism(ImportCplex('../../ifba/models/iAF1260template_minimalMed_noCarb.lp')) print len(lp.getColumnIDs()) lp.modifyColumnBounds({'R("MglcDb_Transp")':(0, 20), 'R("Mo2b_Transp")':(-20, 20)}) lp.modifyColumnBounds({'R("R_Ec_biomass_iAF1260_core_59p81M")': (1., 100.)}) lp.eraseHistory() if os.path.exists('blocked.pcl'): blocked = pickle.load(open('blocked.pcl')) else: # blocked = Variability(lp).getBlocked(['R("R_Ec_biomass_iAF1260_core_59p81M")', 'R("R_AGPR")']) blocked = Variability(lp).getBlocked() sys.exit() pickle.dump(blocked, open('blocked.pcl', 'w')) print blocked print len(blocked) lp.deleteReactionsFromStoich(blocked) lp.eraseHistory() ids = list(set(lp.getColumnIDs()) - set(lp.getTransporters())) print ids print len(ids) lp.addNegativeColumnSwitches(ids) # lp.addNegativeColumnSwitches(['R("Mo2b_Transp")']) lp.modifyColumnBounds({'R("R_Ec_biomass_iAF1260_core_59p81M")': (1., 100.)}) binColumns = lp.getColumnsOfType('binary') objDict = dict() for i in binColumns: objDict[i] = 1. lp.setObjective(objDict) WriteCplex(lp, 'debug.lp') lp.toggleVerbosity() lp.fba()