Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_to_bounds.py @ 508:ca98c149ec61 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Wed, 01 Oct 2025 14:21:26 +0000 |
| parents | 20e135a73cad |
| children |
comparison
equal
deleted
inserted
replaced
| 507:20e135a73cad | 508:ca98c149ec61 |
|---|---|
| 171 try: | 171 try: |
| 172 if file_format == 'tabular' or file_format == 'csv': | 172 if file_format == 'tabular' or file_format == 'csv': |
| 173 # Special handling for tabular format using utils functions | 173 # Special handling for tabular format using utils functions |
| 174 filepath = os.path.join(output_folder, f"{filename}.csv") | 174 filepath = os.path.join(output_folder, f"{filename}.csv") |
| 175 | 175 |
| 176 rules = modelUtils.generate_rules(model, asParsed = False) | 176 # Use unified function for tabular export |
| 177 reactions = modelUtils.generate_reactions(model, asParsed = False) | 177 merged = modelUtils.export_model_to_tabular( |
| 178 bounds = modelUtils.generate_bounds(model) | 178 model=model, |
| 179 medium = modelUtils.get_medium(model) | 179 output_path=filepath, |
| 180 | 180 include_objective=True |
| 181 compartments = modelUtils.generate_compartments(model) | 181 ) |
| 182 | |
| 183 df_rules = pd.DataFrame(list(rules.items()), columns = ["ReactionID", "GPR"]) | |
| 184 df_reactions = pd.DataFrame(list(reactions.items()), columns = ["ReactionID", "Formula"]) | |
| 185 df_bounds = bounds.reset_index().rename(columns = {"index": "ReactionID"}) | |
| 186 df_medium = medium.rename(columns = {"reaction": "ReactionID"}) | |
| 187 df_medium["InMedium"] = True | |
| 188 | |
| 189 merged = df_reactions.merge(df_rules, on = "ReactionID", how = "outer") | |
| 190 merged = merged.merge(df_bounds, on = "ReactionID", how = "outer") | |
| 191 # Add compartments only if they exist | |
| 192 if compartments is not None: | |
| 193 merged = merged.merge(compartments, on = "ReactionID", how = "outer") | |
| 194 | |
| 195 merged = merged.merge(df_medium, on = "ReactionID", how = "left") | |
| 196 merged["InMedium"] = merged["InMedium"].fillna(False) | |
| 197 merged = merged.sort_values(by = "InMedium", ascending = False) | |
| 198 | |
| 199 merged.to_csv(filepath, sep="\t", index=False) | |
| 200 | 182 |
| 201 else: | 183 else: |
| 202 # Standard COBRA formats | 184 # Standard COBRA formats |
| 203 filepath = os.path.join(output_folder, f"{filename}.{file_format}") | 185 filepath = os.path.join(output_folder, f"{filename}.{file_format}") |
| 204 | 186 |
