def compdist(fluxvector, expdata=None, options=None, sense=None, extract=True, rmap='Default'): rmap = load.ReactionMapfromXML('reactionmaps.xml', 'Perrenoud', 'SCHUETZR') if extract: fluxvector = extractflux.extractfluxvector(fluxvector, rmap) if expdata == None: expdata = load.ExpFluxesfromXML('expdata.xml', 'Perrenoud', 'Batch', 'aerobe', vector=True) dist = np.linalg.norm(np.array(fluxvector) - np.array(expdata)) return dist
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
experimental_r_id = linkdict['exprxns'][0]['rxid'] token_id = 't_{exprxnid}'.format(exprxnid = experimental_r_id) new_token_reaction = Reaction(token_id) new_token_reaction.name = 'Token exchange reaction for experimental reaction {exprxnid}'.format(exprxnid = experimental_r_id) new_token_reaction.lower_bound = -1000 new_token_reaction.upper_bound = 1000 new_token_metabolite = Metabolite(token_id,name = 'Token metabolite for experimental reaction {exprxnid}'.format(exprxnid = experimental_r_id),compartment='c') new_token_reaction.add_metabolites({new_token_metabolite: -1.0}) model.add_reactions(new_token_reaction) for dictionary in linkdict['modrxns']: modelreaction = model.reactions.get_by_id(dictionary['rxid']) modelreaction.add_metabolites({new_token_metabolite: float(dictionary['coef'])}) return model if __name__ == "__main__": from cobra.io.sbml import create_cobra_model_from_sbml_file from cobra.io.sbml import write_cobra_model_to_sbml_file import loadData as load notokenmodel = create_cobra_model_from_sbml_file('../SBML/SCHUETZR_notokens.xml') notokenmap = load.ReactionMapfromXML('reactionmaps_notokens.xml','Perrenoud','SCHUETZR') tokenmodel = createTokens(notokenmodel,notokenmap) sbml_out_file = 'SCHUETZR_withtokens.xml' sbml_level = 2 sbml_version = 1 write_cobra_model_to_sbml_file(tokenmodel, sbml_out_file, sbml_level,sbml_version, print_time=False)