def compdistcomplete(rawfluxvector,model, debug = False): if debug: print('compdistcomplete: Calculating distance...') import loadData as load import extractflux #print 'Loading experimental data...' expdata = load.ExpFluxesfromXML('expdata.xml','Perrenoud','Batch','aerobe') #print 'Loading reaction map...' rmap = load.ReactionMapfromXML('reactionmaps.xml','Perrenoud','SCHUETZR') tup = zip([reaction.id for reaction in model.reactions],rawfluxvector,) # rawfluxdict = {reactionid:fluxvalue for reactionid,fluxvalue in tup} extractfluxdict = extractflux.extractfluxdict(rawfluxdict,rmap) fluxvector = [] fluxvalues = [] for key in extractfluxdict: if (key in expdata): fluxvector.append(extractfluxdict[key]) fluxvalues.append(float(expdata[key])) dist = np.linalg.norm(np.array(fluxvector)-np.array(fluxvalues)) return dist
cobramodel = create_cobra_model_from_sbml_file('../SBML/SCHUETZR.xml') import loadData as load rmap = load.ReactionMapfromXML('reactionmaps.xml','Perrenoud','SCHUETZR') optreq = 0.0 fluxvalues = load.ExpFluxesfromXML('expdata.xml','Perrenoud','Batch','aerobe') gurobimodel = QPmindist(cobramodel,fluxvalues,rmap,optreq) QPsolutionvector = getgurobisolutionvector(gurobimodel) QPsolutiondict = getgurobisolutiondict(gurobimodel) QPFBAobjval = computeFBAobjval(QPsolutionvector,cobramodel) import extractflux extractfluxdict = extractflux.extractfluxdict(QPsolutiondict,rmap) import fluxreport #fluxreport.fluxreport(extractedfluxes,fluxvalarray) import compdist dist = compdist.compdistdict(extractfluxdict) #print 'Optimality requirement:',optreq print 'Optreq = 0:' print 'compdist distance:',dist #print 'gurobimomdel gurobi objective value:',gurobimodel.ObjVal import math #print 'square root of gurobi objective value:',math.sqrt(gurobimodel.ObjVal) print "QP solution FBA objective value:",QPFBAobjval
#print exp_errordict[key] #print uncertfrac_dict[key] #print uncertfrac_dict #print "%s %15.1f %15.1f %15.1f %15.1f %15.1f" % (key,float(fluxdict[key]),float(expfluxdict[key]),float(diff_dict[key]),float(exp_errordict[key]),float(uncertfrac_dict[key])) #Commenting out above line for the moment, as not sure how the Pythn 3 syntax for this is. return diff_dict #TEST CODE START: if __name__ == "__main__": from cobra.io.sbml import read_sbml_model SCHUETZR = read_sbml_model('../SBML/SCHUETZR.xml') solution = SCHUETZR.optimize() #FBAresult = solution.x_dict #x_dict is deprecated. Use "fluxes" instead. FBAresult = solution.fluxes import extractflux rmap = load.ReactionMapfromXML('reactionmaps.xml', 'Perrenoud', 'SCHUETZR') expfluxes = load.ExpFluxesfromXML('expdata.xml', 'Perrenoud', 'Batch', 'aerobe') fluxresult = extractflux.extractfluxdict(FBAresult, rmap) t = fluxreport(fluxresult) #TEST CODE END.
import loadData as load rmap = load.ReactionMapfromXML('reactionmaps.xml', 'Perrenoud', 'SCHUETZR') optreq = 0.0 fluxvalues = load.ExpFluxesfromXML('expdata.xml', 'Perrenoud', 'Batch', 'aerobe') gurobimodel = QPmindist(cobramodel, fluxvalues, rmap, optreq) QPsolutionvector = getgurobisolutionvector(gurobimodel) QPsolutiondict = getgurobisolutiondict(gurobimodel) QPFBAobjval = computeFBAobjval(QPsolutionvector, cobramodel) import extractflux extractfluxdict = extractflux.extractfluxdict(QPsolutiondict, rmap) import fluxreport #fluxreport.fluxreport(extractedfluxes,fluxvalarray) import compdist dist = compdist.compdistdict(extractfluxdict) #print 'Optimality requirement:',optreq print('Optreq = 0:') print('compdist distance:', dist) #print 'gurobimomdel gurobi objective value:',gurobimodel.ObjVal import math #print 'square root of gurobi objective value:',math.sqrt(gurobimodel.ObjVal) print("QP solution FBA objective value:", QPFBAobjval)