From 0a01bde091838c6610e09b3cbc05c2b526f5ede3 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Tue, 5 Apr 2022 14:27:21 +0200 Subject: [PATCH] #18 : add support for global variables in custom output on time courses --- basico/task_timecourse.py | 2 +- tests/tellurium_sim.sbml | 47 +++++++++++++++++++++++++++++++ tests/test_parameterestimation.py | 2 +- tests/test_timecourse.py | 19 +++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/tellurium_sim.sbml create mode 100644 tests/test_timecourse.py diff --git a/basico/task_timecourse.py b/basico/task_timecourse.py index 476b1ee..955464a 100644 --- a/basico/task_timecourse.py +++ b/basico/task_timecourse.py @@ -223,7 +223,7 @@ def create_data_handler(output_selection, during=None, after=None, before=None, logging.warning('no object for name {0}'.format(name)) continue - if isinstance(obj, COPASI.CModel): + if obj.getObjectType() != 'Reference': obj = obj.getValueReference() cn = obj.getCN().getString() diff --git a/tests/tellurium_sim.sbml b/tests/tellurium_sim.sbml new file mode 100644 index 0000000..2a31db1 --- /dev/null +++ b/tests/tellurium_sim.sbml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + k1 + + + + + + + + + + + S1 + 1 + + + + + + + 1 + + + + + + + diff --git a/tests/test_parameterestimation.py b/tests/test_parameterestimation.py index 3a8a0d4..ae92b17 100644 --- a/tests/test_parameterestimation.py +++ b/tests/test_parameterestimation.py @@ -62,7 +62,7 @@ def test_get_data(self): @unittest.skipIf(sys.version_info < (3, 6, 0), 'This test requires assertLogs which is not available before') def test_change_bounds(self): basico.set_fit_parameters([{'name': '(R1).k2', 'lower': 1, 'upper': 0.01}]) - with self.assertLogs(level='ERROR') as cm: + with self.assertLogs(level='ERROR') as _: sol = basico.as_dict(basico.run_parameter_estimation()) self.assertTrue(np.isnan(sol['sol'])) diff --git a/tests/test_timecourse.py b/tests/test_timecourse.py new file mode 100644 index 0000000..a5e6089 --- /dev/null +++ b/tests/test_timecourse.py @@ -0,0 +1,19 @@ +import unittest +import basico +import os + +THIS_DIR = os.path.dirname(__file__) + + +class TestTimeCourse(unittest.TestCase): + def setUp(self): + basico.load_model(os.path.join(THIS_DIR, 'tellurium_sim.sbml')) + + def test_custom_output(self): + tc = basico.run_time_course_with_output(['Time', '[S1]', '[S2]', 'Values[k1]'], 0, 5, 5) + self.assertIsNotNone(tc) + self.assertListEqual(tc.columns.to_list(), ['Time', '[S1]', '[S2]', 'Values[k1]']) + + +if __name__ == '__main__': + unittest.main()