From 36cf7219972d8dbe694ba18ec52d7387a0c42a4c Mon Sep 17 00:00:00 2001
From: Peter Schubert <Peter.Schubert@hhu.de>
Date: Sat, 28 Jan 2023 16:07:22 +0100
Subject: [PATCH] value info in targets sheet corrected

---
 rbaxdf/model/rba_macromolecules.py | 12 ++++++++++--
 rbaxdf/model/rba_model.py          |  3 +++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/rbaxdf/model/rba_macromolecules.py b/rbaxdf/model/rba_macromolecules.py
index b5f9f09..4beb103 100644
--- a/rbaxdf/model/rba_macromolecules.py
+++ b/rbaxdf/model/rba_macromolecules.py
@@ -53,9 +53,17 @@ class RbaMacromolecules:
         tree.write(file_name)
 
     def to_df(self):
-        df_comp = pd.DataFrame([item.to_dict() for item in self.components.values()])
+
+        if len(self.components) > 0:
+            df_comp = pd.DataFrame([item.to_dict() for item in self.components.values()])
+        else:
+            df_comp = pd.DataFrame(columns=['component', 'name', 'type', 'weight'])
         df_comp.set_index('component', inplace=True)
-        df_mm = pd.DataFrame([item.to_dict() for item in self.macromolecules.values()])
+
+        if len(self.macromolecules) > 0:
+            df_mm = pd.DataFrame([item.to_dict() for item in self.macromolecules.values()])
+        else:
+            df_mm = pd.DataFrame(columns=['id', 'compartment'])
         df_mm.set_index('id', inplace=True)
         cols = ['compartment'] + df_comp.index.to_list()
         df = pd.concat((df_comp.T, df_mm)).reindex(columns=cols)
diff --git a/rbaxdf/model/rba_model.py b/rbaxdf/model/rba_model.py
index 67430dc..593401c 100644
--- a/rbaxdf/model/rba_model.py
+++ b/rbaxdf/model/rba_model.py
@@ -81,9 +81,12 @@ class RbaModel:
         for idx, row in m_dict['densities'].iterrows():
             first_value = row['targetValue'].split('=')[1]
             m_dict['densities'].at[idx, 'value_info'] = self.parameters.get_value_info(first_value)
+        # we temporarily create a unique index for table update
+        m_dict['targets'].reset_index(inplace=True)
         for idx, row in m_dict['targets'].iterrows():
             first_value = row['targetValue'].split('=')[1]
             m_dict['targets'].at[idx, 'value_info'] = self.parameters.get_value_info(first_value)
+        m_dict['targets'].set_index('targetGroup', inplace=True)
 
         with pd.ExcelWriter(xlsx_name) as writer:
             for name, df in m_dict.items():
-- 
GitLab