Skip to content

Commit 4d0dfc5

Browse files
committed
- replace NaN values in condition columns with their model value
1 parent 890ed0a commit 4d0dfc5

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

copasi_petab_importer/convert_petab.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,26 @@ def create_mapping(self, experiments, petab):
600600
continue
601601
obj_map.setRole(num_cols + i, role)
602602

603-
def generate_copasi_data(self, petab):
603+
def update_conditions(self, petab):
604+
# go through all columns of the condition table
605+
# and replace potential NaN entries with the value from the model
606+
# ignore the first column (conditionId)
607+
for col in petab.condition_data.columns[1:]:
608+
if petab.condition_data[col].isna().any():
609+
for i in range(petab.condition_data.shape[0]):
610+
if np.isnan(petab.condition_data.loc[i, col]):
611+
obj = dm.findObjectByDisplayName(str('Values[' + col + ']'))
612+
if obj is None:
613+
obj = dm.findObjectByDisplayName(col)
614+
if obj is not None:
615+
if isinstance(obj, COPASI.CMetab):
616+
value = obj.getInitialConcentration()
617+
else:
618+
value = obj.getInitialValue()
619+
petab.condition_data.loc[i, col] = value
604620

621+
def generate_copasi_data(self, petab):
622+
self.update_conditions(petab)
605623
self.experiments = self.get_experiments(petab)
606624
self.write_experiments(self.experiments, petab)
607625
self.create_mapping(self.experiments, petab)

test/test_importer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
except ImportError:
1717
petab_tests_available = False
1818

19+
1920
class TestConverter(unittest.TestCase):
2021
def test_copasi_version(self):
2122
self.assertGreater(int(COPASI.CVersion.VERSION.getVersionDevel()), 214,
@@ -45,6 +46,7 @@ def test_import_bruno(self):
4546
converter.convert()
4647

4748
self.assertTrue(os.path.exists(converter.experimental_data_file))
49+
4850
@unittest.skipIf(not os.path.exists(_BENCHMARK_DIR), 'benchmarks not available')
4951
def test_import_bachmann(self):
5052
petab_dir = os.path.join(_BENCHMARK_DIR, 'Bachmann_MSB2011')
@@ -58,6 +60,7 @@ def test_import_bachmann(self):
5860
converter.convert()
5961

6062
self.assertTrue(os.path.exists(converter.experimental_data_file))
63+
6164
@unittest.skipUnless(petab_tests_available, 'petabtests need to be installed to run this')
6265
def test_petabtest_import(self):
6366
cases = [c for c in glob.glob(str(petabtests.CASES_DIR) + '/*/*.yaml') if '0' in c and 'solution' not in c]

0 commit comments

Comments
 (0)