def main(): here = os.path.dirname(os.path.realpath(__file__)) input_path_tecrdb = os.path.join(here, INPUT_PATH_TECRDB) input_path_compounds = os.path.join(here, INPUT_PATH_COMPOUNDS) input_path_microspecies = os.path.join(here, INPUT_PATH_MICROSPECIES) tecrdb = pd.read_csv(input_path_tecrdb, index_col=0).loc[filter_tecrdb] stoichiometry = get_stoichiometry(tecrdb) cids = stoichiometry['compound_id'].unique() rids = stoichiometry['reaction_id'].unique() compounds = ( pd.read_csv(input_path_compounds, index_col=0) .loc[lambda df: df['compound_id'].isin(cids)] ) microspecies = ( pd.read_csv(input_path_microspecies, index_col=0) .loc[lambda df: df['compound_id'].isin(cids)] ) pkas, pkmgs = ( microspecies .groupby(['compound_id', n])[[pk, "name"]].first() .dropna() .reset_index() for n, pk in [('nh', 'pka'), ('nmg', 'pkmg')] ) stan_codes = get_stan_codes(stoichiometry) stan_input = get_stan_input( tecrdb, stoichiometry, microspecies, compounds, pkas, pkmgs, stan_codes ) pkas.to_csv(os.path.join(here, OUTPUT_PATH_PKAS)) compounds.to_csv(os.path.join(here, OUTPUT_PATH_COMPOUNDS)) tecrdb.to_csv(os.path.join(here, OUTPUT_PATH_TECRDB)) jsondump(os.path.join(here, OUTPUT_PATH_STAN_CODES), stan_codes) jsondump(os.path.join(here, OUTPUT_PATH_JSON), stan_input) rdump(os.path.join(here, OUTPUT_PATH_R), stan_input)
def test_roundtrip_metric(self): dfile = os.path.join(DATAFILES_PATH, 'metric_diag.data.R') data_dict_1 = rload(dfile) self.assertEqual(data_dict_1['inv_metric'].shape, (3,)) dfile_tmp = os.path.join(DATAFILES_PATH, 'tmp.data.R') rdump(dfile_tmp, data_dict_1) data_dict_2 = rload(dfile_tmp) self.assertTrue('inv_metric' in data_dict_2) for i, x in enumerate(data_dict_2['inv_metric']): self.assertEqual(x, data_dict_2['inv_metric'][i]) os.remove(dfile_tmp)
def write_rdump(self, dict: Dict) -> None: rdump(self._data_file, dict)