def get_cobra_model(self): if self.kegg_org is not None: model = BiomodelMongo.objects(organism=self.kegg_org).first() else: model = BiomodelMongo.objects(name=self.name).first() # try to load the cobra model cobra_model = None try: cobra_model = cobra.io._from_dict(model.cobra_model) except Exception as e: logging.error(e) return cobra_model
def insert_model(xml_model): import cobra.io import json sbml_model = cobra.io.read_sbml_model(xml_model) # cobra.io.save_json_model(sbml_model, 'test.json') # d = json.loads(open('test.json').read().encode('utf-8')) d = cobra.io._to_dict(sbml_model) infos = retrieve_kegg_org_id(xml_model) if infos is None: logging.warn('No infos found') return False kegg_org_id, model_name = infos['kegg_org_id'], infos['model_name'] if kegg_org_id is None or model_name is None: return False biomodel = BiomodelMongo(name=model_name, organism=kegg_org_id, cobra_model=d) biomodel.save() return True
def test_read_models(): m = BiomodelMongo.objects(organism='sse').first() import cobra.io import json try: # s = json.dumps(m.cobra_model).encode('utf-8') # with open('test.json', 'w') as f: # f.write(s) sbml_model = cobra.io._from_dict(m.cobra_model) #sbml_model = cobra.io.load_json_model('test.json') except Exception as e: print "Got an exception:", e return None print "NOTES:", sbml_model.reactions[1].notes return sbml_model