def getGINSimModel(self): if self.model.format == LogicalModel.ZGINML: return ginsim.load(join(settings.MEDIA_ROOT, self.model.file.path)) elif self.model.format == LogicalModel.MABOSS: biolqm_model = self.getBioLQMModel() ginsim_model = biolqm.to_ginsim(biolqm_model) ginsim.service("layout").runLayout(2, ginsim_model) return ginsim_model elif self.model.format == LogicalModel.SBML: biolqm_model = biolqm.load( join(settings.MEDIA_ROOT, self.model.file.path)) for component in biolqm_model.getComponents(): if component.getName() != "": component.setNodeID( re.sub('[^A-Za-z0-9_]+', '', component.getName())) ginsim_model = biolqm.to_ginsim(biolqm_model) ginsim.service("layout").runLayout(2, ginsim_model) return ginsim_model else: raise MethodNowAllowed()
def getSBMLModelFile(self): if self.model.format == LogicalModel.ZGINML: ginsim_model = ginsim.load( join(settings.MEDIA_ROOT, self.model.file.path)) path = tempfile.mkdtemp() tmp_sbml = tempfile.mkstemp(dir=path, suffix='.sbml')[1] biolqm.save(ginsim_model, tmp_sbml, "sbml") return tmp_sbml elif self.model.format == LogicalModel.MABOSS: ginsim_model = self.getBioLQMModel() path = tempfile.mkdtemp() tmp_sbml = tempfile.mkstemp(dir=path, suffix='.sbml')[1] biolqm.save(ginsim_model, tmp_sbml, "sbml") return tmp_sbml elif self.model.format == LogicalModel.SBML: return join(settings.MEDIA_ROOT, self.model.file.path) else: raise MethodNotAllowed()
def get(self, request, project_id, model_id, tag): HasModel.load(self, request, project_id, model_id) try: tagged_version = TaggedLogicalModel.objects.get(model=self.model, tag=tag) ginsim_model = ginsim.load(join(settings.MEDIA_ROOT, tagged_version.file.path)) sbml_filename = join(settings.TMP_ROOT, splitext(basename(tagged_version.file.path))[0] + ".sbml") biolqm.save(ginsim_model, sbml_filename, "sbml") return FileResponse( open(sbml_filename, 'rb'), as_attachment=True, filename=basename(sbml_filename) ) except TaggedLogicalModel.DoesNotExist: raise NotFound
def getBioLQMModel(self): if self.model.format == LogicalModel.MABOSS: maboss_sim = maboss.load( join(settings.MEDIA_ROOT, self.model.bnd_file.path), join(settings.MEDIA_ROOT, self.model.cfg_file.path)) biolqm_model = maboss.to_biolqm(maboss_sim) return biolqm_model elif self.model.format == LogicalModel.ZGINML: ginsim_model = ginsim.load( join(settings.MEDIA_ROOT, self.model.file.path)) return ginsim.to_biolqm(ginsim_model) elif self.model.format == LogicalModel.SBML: biolqm_model = biolqm.load( join(settings.MEDIA_ROOT, self.model.file.path)) return biolqm_model else: raise MethodNotAllowed()
def getMaBoSSModel(self): if self.model.format == LogicalModel.MABOSS: return maboss.load( join(settings.MEDIA_ROOT, self.model.bnd_file.path), join(settings.MEDIA_ROOT, self.model.cfg_file.path)) elif self.model.format == LogicalModel.ZGINML: ginsim_model = ginsim.load(self.model.file.path) return ginsim.to_maboss(ginsim_model) elif self.model.format == LogicalModel.SBML: t0 = time() biolqm_model = biolqm.load(self.model.file.path) t1 = time() print("Loaded sbml with biolqm : %.2gs" % (t1 - t0)) maboss_model = biolqm.to_maboss(biolqm_model) print("Converted to MaBoSS : %.2gs" % (time() - t1)) return maboss_model else: raise MethodNotAllowed()
def post(self, request, project_id, model_id): # print("Entering post function") t0 = time() HasModel.load(self, request, project_id, model_id) t1 = time() # print("Model properties loaded (%.2gs)" % (t1-t0)) if self.model.format == LogicalModel.ZGINML: path = join(settings.MEDIA_ROOT, self.model.file.path) ginsim_model = ginsim.load(path) maboss_model = ginsim.to_maboss(ginsim_model) tmp_bnd_path = join(settings.TMP_ROOT, splitext(basename(self.model.file.path))[0] + ".bnd") bnd_file = open(tmp_bnd_path, 'w') maboss_model.print_bnd(out=bnd_file) bnd_file.close() tmp_cfg_path = join(settings.TMP_ROOT, splitext(basename(self.model.file.path))[0] + ".cfg") cfg_file = open(tmp_cfg_path, 'w') maboss_model.print_cfg(out=cfg_file) cfg_file.close() maboss_simulation = MaBoSSSimulation( project=self.project, model=self.model, name=request.POST['name'], bnd_file=File(open(tmp_bnd_path, 'rb'), name=basename(tmp_bnd_path)), cfg_file=File(open(tmp_cfg_path, 'rb'), name=basename(tmp_cfg_path)), status=MaBoSSSimulation.BUSY ) maboss_simulation.save() remove(tmp_bnd_path) remove(tmp_cfg_path) elif self.model.format == LogicalModel.MABOSS: bnd_path = join(settings.MEDIA_ROOT, self.model.bnd_file.path) cfg_path = join(settings.MEDIA_ROOT, self.model.cfg_file.path) maboss_simulation = MaBoSSSimulation( project=self.project, model=self.model, name=request.POST['name'], bnd_file=File(open(bnd_path, 'rb'), name=basename(bnd_path)), cfg_file=File(open(cfg_path, 'rb'), name=basename(cfg_path)), status=MaBoSSSimulation.BUSY ) maboss_simulation.save() maboss_model = maboss.load(bnd_path, cfg_path) elif self.model.format == LogicalModel.SBML: maboss_model = self.getMaBoSSModel() tmp_bnd_path = join(settings.TMP_ROOT, splitext(basename(self.model.file.path))[0] + ".bnd") bnd_file = open(tmp_bnd_path, 'w') maboss_model.print_bnd(out=bnd_file) bnd_file.close() tmp_cfg_path = join(settings.TMP_ROOT, splitext(basename(self.model.file.path))[0] + ".cfg") cfg_file = open(tmp_cfg_path, 'w') maboss_model.print_cfg(out=cfg_file) cfg_file.close() maboss_simulation = MaBoSSSimulation( project=self.project, model=self.model, name=request.POST['name'], bnd_file=File(open(tmp_bnd_path, 'rb'), name=basename(tmp_bnd_path)), cfg_file=File(open(tmp_cfg_path, 'rb'), name=basename(tmp_cfg_path)), status=MaBoSSSimulation.BUSY ) maboss_simulation.save() remove(tmp_bnd_path) remove(tmp_cfg_path) else: return HttpResponse(status=500) # t2 = time() # print("Model loaded (%.2gs)" % (t2-t1)) cfg_settings = loads(request.POST['settings']) maboss_model.param.update(cfg_settings) maboss_model.param['thread_count'] = 6 maboss_model.param['time_tick'] = float(maboss_model.param['max_time'])/100 mutations = loads(request.POST['mutations']) for var, mutation in mutations.items(): maboss_model.mutate(var, mutation) maboss_model.network.set_output( [key for key, value in loads(request.POST['outputVariables']).items() if value] ) for var, istate in parseIstates(request.POST['initialStates']).items(): maboss_model.network.set_istate(var, istate) maboss_simulation.update_model(maboss_model) server_host = request.POST.get('serverHost') server_port = request.POST.get('serverPort') thread = Thread(target=run_simulation, args=(maboss_model, maboss_simulation.id, server_host, server_port)) # t3 = time() # print("Thread built (%.2gs)" % (t3-t2)) thread.start() return Response({'simulation_id': maboss_simulation.id}, status=status.HTTP_200_OK)
# Author: CoLoMoTo # Affiliation: CoLoMoTo # Aim: Export a GINsim model into NuSMV-compatible format. # Date: 20/07/2017 # Example of a CL # python3 ginsim_export_as_NuSMV.py model.zginml ./model.smv import sys import ginsim import biolqm from shutil import copyfile # Load a model model = ginsim.load(sys.argv[1]) # Convert model to NuSMV s = ginsim.to_nusmv(model) # Export converted model copyfile(s.input_smv, sys.argv[2])