diff --git a/rbaxdf/model/rba_macromolecules.py b/rbaxdf/model/rba_macromolecules.py index b5f9f09ace8f1c63d7cb8b7ae513e0fdbfb37893..4beb10347db54bdba2fec9e7d85f5de6abfb28ad 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 67430dc298b3d9b5dea43ca068e5aae948ca21b7..593401c1cb742ec934580f4da19e9df9c9be81cf 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():