Mercurial > repos > bimib > cobraxy
comparison COBRAxy/metabolicModel2Tabular.py @ 508:ca98c149ec61 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Wed, 01 Oct 2025 14:21:26 +0000 |
| parents | ffc234ec80db |
| children | 698802db290d |
comparison
equal
deleted
inserted
replaced
| 507:20e135a73cad | 508:ca98c149ec61 |
|---|---|
| 323 target_nomenclature=ARGS.gene_format, | 323 target_nomenclature=ARGS.gene_format, |
| 324 source_nomenclature=source_nomenclature, | 324 source_nomenclature=source_nomenclature, |
| 325 logger=logger | 325 logger=logger |
| 326 ) | 326 ) |
| 327 | 327 |
| 328 # generate data | 328 # generate data using unified function |
| 329 rules = modelUtils.generate_rules(model, asParsed = False) | |
| 330 reactions = modelUtils.generate_reactions(model, asParsed = False) | |
| 331 bounds = modelUtils.generate_bounds(model) | |
| 332 medium = modelUtils.get_medium(model) | |
| 333 objective_function = modelUtils.extract_objective_coefficients(model) | |
| 334 | |
| 335 compartments = modelUtils.generate_compartments(model) | |
| 336 | |
| 337 df_rules = pd.DataFrame(list(rules.items()), columns = ["ReactionID", "GPR"]) | |
| 338 df_reactions = pd.DataFrame(list(reactions.items()), columns = ["ReactionID", "Formula"]) | |
| 339 | |
| 340 # Create DataFrame for translation issues | |
| 341 df_translation_issues = pd.DataFrame([ | |
| 342 {"ReactionID": rxn_id, "TranslationIssues": issues} | |
| 343 for rxn_id, issues in translation_issues.items() | |
| 344 ]) | |
| 345 | |
| 346 df_bounds = bounds.reset_index().rename(columns = {"index": "ReactionID"}) | |
| 347 df_medium = medium.rename(columns = {"reaction": "ReactionID"}) | |
| 348 df_medium["InMedium"] = True | |
| 349 | |
| 350 merged = df_reactions.merge(df_rules, on = "ReactionID", how = "outer") | |
| 351 merged = merged.merge(df_bounds, on = "ReactionID", how = "outer") | |
| 352 merged = merged.merge(objective_function, on = "ReactionID", how = "outer") | |
| 353 if compartments is not None: | |
| 354 merged = merged.merge(compartments, on = "ReactionID", how = "outer") | |
| 355 merged = merged.merge(df_medium, on = "ReactionID", how = "left") | |
| 356 | |
| 357 # Add translation issues column | |
| 358 if not df_translation_issues.empty: | |
| 359 merged = merged.merge(df_translation_issues, on = "ReactionID", how = "left") | |
| 360 merged["TranslationIssues"] = merged["TranslationIssues"].fillna("") | |
| 361 else: | |
| 362 # Add empty TranslationIssues column if no issues found | |
| 363 #merged["TranslationIssues"] = "" | |
| 364 pass | |
| 365 | |
| 366 merged["InMedium"] = merged["InMedium"].fillna(False) | |
| 367 | |
| 368 merged = merged.sort_values(by = "InMedium", ascending = False) | |
| 369 | |
| 370 if not ARGS.out_tabular: | 329 if not ARGS.out_tabular: |
| 371 raise utils.ArgsErr("out_tabular", "output path (--out_tabular) is required when output_format == tabular", ARGS.out_tabular) | 330 raise utils.ArgsErr("out_tabular", "output path (--out_tabular) is required when output_format == tabular", ARGS.out_tabular) |
| 372 save_as_tabular_df(merged, ARGS.out_tabular) | 331 |
| 332 merged = modelUtils.export_model_to_tabular( | |
| 333 model=model, | |
| 334 output_path=ARGS.out_tabular, | |
| 335 translation_issues=translation_issues, | |
| 336 include_objective=True, | |
| 337 save_function=save_as_tabular_df | |
| 338 ) | |
| 373 expected = ARGS.out_tabular | 339 expected = ARGS.out_tabular |
| 374 | 340 |
| 375 # verify output exists and non-empty | 341 # verify output exists and non-empty |
| 376 if not expected or not os.path.exists(expected) or os.path.getsize(expected) == 0: | 342 if not expected or not os.path.exists(expected) or os.path.getsize(expected) == 0: |
| 377 raise utils.DataErr(expected, "Output not created or empty") | 343 raise utils.DataErr(expected, "Output not created or empty") |
