def run_tellurium(input_path, output_path): """ Run Combine archive with tellurium and store archive with results. :param input_path: :param output_path: :return: """ print('-' * 80) print('Running tellurium:\n\t', input_path) print('-' * 80) import tellurium import matplotlib matplotlib.use('Agg') tellurium.setDefaultPlottingEngine("matplotlib") filename, extension = os.path.splitext(os.path.basename(input_path)) workingDir = os.path.join(TELLURIUM_DIR, '_te_{}'.format(filename)) if not os.path.exists(workingDir): os.makedirs(workingDir) executeCombineArchive(input_path, workingDir=workingDir, outputDir=workingDir, saveOutputs=True)
def test_single_omex(tmpdir): omex_path = os.path.join(OMEX_TEST_DIR, 'specification/L1V3/L1V3_reading-data-csv-minimal.omex') contents = omex.listContents(omex_path) # print(contents[1]) # TODO print generated code tmp_dir = tempfile.mkdtemp() try: tesedml.executeCombineArchive(omexPath=omex_path, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir)
def test_omex_plot_numl_with_model(tmpdir): results = tesedml.executeCombineArchive(OMEX_PLOT_NUML_WITH_MODEL, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 5 assert "dgDataS1" in dg_dict assert "dgDataTime" in dg_dict assert len(dg_dict["dgDataS1"]) == 200 assert len(dg_dict["dgDataTime"]) == 200
def test_omex_plot_csv(tmpdir): results = tesedml.executeCombineArchive(OMEX_PLOT_CSV, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 2 assert "dgDataS1" in dg_dict assert "dgDataTime" in dg_dict assert len(dg_dict["dgDataS1"]) == 200 assert len(dg_dict["dgDataTime"]) == 200
def test_omex_plot_numl_with_model(tmpdir): results = tesedml.executeCombineArchive(OMEX_PLOT_NUML_WITH_MODEL, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 5 assert "dgDataS1" in dg_dict assert "dgDataTime" in dg_dict assert len(dg_dict["dgDataS1"]) == 200 assert len(dg_dict["dgDataTime"]) == 200
def test_omex_plot_csv(tmpdir): results = tesedml.executeCombineArchive(OMEX_PLOT_CSV, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 2 assert "dgDataS1" in dg_dict assert "dgDataTime" in dg_dict assert len(dg_dict["dgDataS1"]) == 200 assert len(dg_dict["dgDataTime"]) == 200
def test_omex_csv_parameters(tmpdir): results = tesedml.executeCombineArchive(OMEX_CSV_PARAMETERS, workingDir=str(tmpdir)) result = list(results.values())[0] dgs = result['dataGenerators'] dg_dict = list(dgs.values())[0] assert len(dg_dict) == 2 assert "dgDataIndex" in dg_dict assert "dgDataMu" in dg_dict assert len(dg_dict["dgDataIndex"]) == 10 assert len(dg_dict["dgDataMu"]) == 10
def test_omex_csv_parameters(tmpdir): results = tesedml.executeCombineArchive(OMEX_CSV_PARAMETERS, workingDir=str(tmpdir)) result = list(results.values())[0] dgs = result['dataGenerators'] dg_dict = list(dgs.values())[0] assert len(dg_dict) == 2 assert "dgDataIndex" in dg_dict assert "dgDataMu" in dg_dict assert len(dg_dict["dgDataIndex"]) == 10 assert len(dg_dict["dgDataMu"]) == 10
def execute_omex(archive_id, debug=False): """ Execute omex. """ matplotlib.pyplot.switch_backend("Agg") print("*** START RUNNING OMEX ***") results = {} # get archive, raises ObjectDoesNotExist archive = Archive.objects.get(pk=archive_id) omex_path = str(archive.file.path) # execute archive try: tmp_dir = tempfile.mkdtemp() # dictionary of files to data generators te_result = tesedml.executeCombineArchive(omex_path, workingDir=tmp_dir, createOutputs=False) # JSON serializable results (np.array to list) dgs_json = {} for f_tmp, result in te_result.items(): sedml_location = f_tmp.replace(tmp_dir + "/", "") dgs = result['dataGenerators'] # print(sedml_location) for key in dgs: dgs[key] = dgs[key].tolist() # print(key, ':', dgs[key]) dgs_json[sedml_location] = dgs # print("-" * 80) # store results of execution for rendering results['dgs'] = dgs_json # results['code'] = te_result['code'] finally: # cleanup shutil.rmtree(tmp_dir) print("*** FINISHED RUNNING OMEX ***") return results
def test(self=None): """ Test failes if Exception in execution of f. """ if self is not None: print(filePath) tesedml.executeCombineArchive(omexPath=filePath, workingDir=self.test_dir)
def test_omex_jws_adlung2017_fig2gl(tmpdir): results = tesedml.executeCombineArchive(OMEX_CSV_JWS_ADLUNG2017_FIG2G, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 40
def test_repressilator(self): # Get SBML from URN and set for phrasedml urn = "urn:miriam:biomodels.db:BIOMD0000000012" sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn) return_code = phrasedml.setReferencedSBML(urn, sbml_str) assert return_code # valid SBML # <SBML species> # PX - LacI protein # PY - TetR protein # PZ - cI protein # X - LacI mRNA # Y - TetR mRNA # Z - cI mRNA # <SBML parameters> # ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor # ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor phrasedml_str = """ model1 = model "{}" model2 = model model1 with ps_0=1.3E-5, ps_a=0.013 sim1 = simulate uniform(0, 1000, 1000) task1 = run sim1 on model1 task2 = run sim1 on model2 # A simple timecourse simulation plot "Timecourse of repressilator" task1.time vs task1.PX, task1.PZ, task1.PY # Applying preprocessing plot "Timecourse after pre-processing" task2.time vs task2.PX, task2.PZ, task2.PY # Applying postprocessing plot "Timecourse after post-processing" task1.PX/max(task1.PX) vs task1.PZ/max(task1.PZ), \ task1.PY/max(task1.PY) vs task1.PX/max(task1.PX), \ task1.PZ/max(task1.PZ) vs task1.PY/max(task1.PY) """.format(urn) # convert to sedml print(phrasedml_str) sedml_str = phrasedml.convertString(phrasedml_str) if sedml_str is None: print(phrasedml.getLastError()) raise IOError("sedml could not be generated") # run SEDML directly try: tmp_dir = tempfile.mkdtemp() executeSEDML(sedml_str, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir) # create combine archive and execute try: tmp_dir = tempfile.mkdtemp() sedml_location = "repressilator_sedml.xml" sedml_path = os.path.join(tmp_dir, sedml_location) omex_path = os.path.join(tmp_dir, "repressilator.omex") with open(sedml_path, "w") as f: f.write(sedml_str) entries = [ omex.Entry(location=sedml_location, formatKey="sedml", master=True) ] omex.combineArchiveFromEntries(omexPath=omex_path, entries=entries, workingDir=tmp_dir) executeCombineArchive(omex_path, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir)
if sedml_str is None: print(phrasedml.getLastError()) raise IOError("sedml could not be generated") # run SEDML directly try: tmp_dir = tempfile.mkdtemp() executeSEDML(sedml_str, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir) # create combine archive and execute try: tmp_dir = tempfile.mkdtemp() sedml_location = "repressilator_sedml.xml" sedml_path = os.path.join(tmp_dir, sedml_location) omex_path = os.path.join(tmp_dir, "repressilator.omex") with open(sedml_path, "w") as f: f.write(sedml_str) entries = [ omex.Entry(location=sedml_location, formatKey="sedml", master=True) ] omex.combineArchiveFromEntries(omexPath=omex_path, entries=entries, workingDir=tmp_dir) shutil.copy(omex_path, "repressilator.omex") executeCombineArchive(omex_path, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir)
def test_omex_executeCombineArchive(self): tesedml.executeCombineArchive(omexPath=OMEX_SHOWCASE, workingDir=self.test_dir)
print(phrasedml.getLastError()) raise IOError("sedml could not be generated") # run SEDML directly try: tmp_dir = tempfile.mkdtemp() executeSEDML(sedml_str, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir) # create combine archive and execute try: tmp_dir = tempfile.mkdtemp() sedml_location = "repressilator_sedml.xml" sedml_path = os.path.join(tmp_dir, sedml_location) omex_path = os.path.join(tmp_dir, "repressilator.omex") with open(sedml_path, "w") as f: f.write(sedml_str) entries = [ omex.Entry(location=sedml_location, formatKey="sedml", master=True) ] omex.combineArchiveFromEntries(omexPath=omex_path, entries=entries, workingDir=tmp_dir) shutil.copy(omex_path, "repressilator.omex") executeCombineArchive(omex_path, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir)
def test_omex_executeCombineArchive(self): tesedml.executeCombineArchive(omexPath=OMEX_SHOWCASE, workingDir=self.test_dir)
def test_omex_jws_adlung2017_fig2gl(tmpdir): results = tesedml.executeCombineArchive(OMEX_CSV_JWS_ADLUNG2017_FIG2G, workingDir=str(tmpdir)) result = list(results.values())[0] dg_dict = result['dataGenerators'] assert len(dg_dict) == 40
def test_repressilator(self): # Get SBML from URN and set for phrasedml urn = "urn:miriam:biomodels.db:BIOMD0000000012" sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn) return_code = phrasedml.setReferencedSBML(urn, sbml_str) assert return_code # valid SBML # <SBML species> # PX - LacI protein # PY - TetR protein # PZ - cI protein # X - LacI mRNA # Y - TetR mRNA # Z - cI mRNA # <SBML parameters> # ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor # ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor phrasedml_str = """ model1 = model "{}" model2 = model model1 with ps_0=1.3E-5, ps_a=0.013 sim1 = simulate uniform(0, 1000, 1000) task1 = run sim1 on model1 task2 = run sim1 on model2 # A simple timecourse simulation plot "Timecourse of repressilator" task1.time vs task1.PX, task1.PZ, task1.PY # Applying preprocessing plot "Timecourse after pre-processing" task2.time vs task2.PX, task2.PZ, task2.PY # Applying postprocessing plot "Timecourse after post-processing" task1.PX/max(task1.PX) vs task1.PZ/max(task1.PZ), \ task1.PY/max(task1.PY) vs task1.PX/max(task1.PX), \ task1.PZ/max(task1.PZ) vs task1.PY/max(task1.PY) """.format(urn) # convert to sedml print(phrasedml_str) sedml_str = phrasedml.convertString(phrasedml_str) if sedml_str is None: print(phrasedml.getLastError()) raise IOError("sedml could not be generated") # run SEDML directly try: tmp_dir = tempfile.mkdtemp() executeSEDML(sedml_str, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir) # create combine archive and execute try: tmp_dir = tempfile.mkdtemp() sedml_location = "repressilator_sedml.xml" sedml_path = os.path.join(tmp_dir, sedml_location) omex_path = os.path.join(tmp_dir, "repressilator.omex") with open(sedml_path, "w") as f: f.write(sedml_str) entries = [ omex.Entry(location=sedml_location, formatKey="sedml", master=True) ] omex.combineArchiveFromEntries(omexPath=omex_path, entries=entries, workingDir=tmp_dir) executeCombineArchive(omex_path, workingDir=tmp_dir) finally: shutil.rmtree(tmp_dir)