comparison COBRAxy/tabular2MetabolicModel.py @ 498:df90f40a156c draft

Uploaded
author francesco_lapi
date Tue, 30 Sep 2025 16:13:08 +0000
parents 7a413a5ec566
children
comparison
equal deleted inserted replaced
497:36838126cc07 498:df90f40a156c
38 help="Model format (SBML, JSON, MATLAB, YAML)") 38 help="Model format (SBML, JSON, MATLAB, YAML)")
39 39
40 40
41 parser.add_argument("--output", type=str, required=True, 41 parser.add_argument("--output", type=str, required=True,
42 help="Output model file path") 42 help="Output model file path")
43
44 43
45 parser.add_argument("--tool_dir", type=str, default=os.path.dirname(__file__), 44 parser.add_argument("--tool_dir", type=str, default=os.path.dirname(__file__),
46 help="Tool directory (passed from Galaxy as $__tool_directory__)") 45 help="Tool directory (passed from Galaxy as $__tool_directory__)")
47 46
48 47
84 logging.info('Created missing output directory: %s', out_dir) 83 logging.info('Created missing output directory: %s', out_dir)
85 except Exception as e: 84 except Exception as e:
86 logging.exception('Cannot create output directory: %s', out_dir) 85 logging.exception('Cannot create output directory: %s', out_dir)
87 86
88 model = modelUtils.build_cobra_model_from_csv(ARGS.input) 87 model = modelUtils.build_cobra_model_from_csv(ARGS.input)
88
89
90 logging.info('Created model with name: %s (ID: %s)', model.name, model.id)
89 91
90 # Save model in requested format 92 # Save model in requested format - Galaxy handles the filename
91 if ARGS.format == "sbml": 93 if ARGS.format == "sbml":
92 cobra.io.write_sbml_model(model, ARGS.output) 94 cobra.io.write_sbml_model(model, ARGS.output)
93 elif ARGS.format == "json": 95 elif ARGS.format == "json":
94 cobra.io.save_json_model(model, ARGS.output) 96 cobra.io.save_json_model(model, ARGS.output)
95 elif ARGS.format == "mat": 97 elif ARGS.format == "mat":
96 cobra.io.save_matlab_model(model, ARGS.output) 98 cobra.io.save_matlab_model(model, ARGS.output)
97 elif ARGS.format == "yaml": 99 elif ARGS.format == "yaml":
98 cobra.io.save_yaml_model(model, ARGS.output) 100 cobra.io.save_yaml_model(model, ARGS.output)
99 else: 101 else:
100 logging.error('Unknown format requested: %s', ARGS.format) 102 logging.error('Unknown format requested: %s', ARGS.format)
101 print(f"ERROR: Unknown format: {ARGS.format}") 103 raise ValueError(f"Unknown format: {ARGS.format}")
102 104
103 105
104 logging.info('Model successfully written to %s (format=%s)', ARGS.output, ARGS.format) 106 logging.info('Model successfully written to %s (format=%s)', ARGS.output, ARGS.format)
107 print(f"Model created successfully in {ARGS.format.upper()} format")
105 108
106 except Exception: 109 except Exception as e:
107 # Log full traceback to the out_log so Galaxy users/admins can see what happened 110 # Log full traceback to the out_log so Galaxy users/admins can see what happened
108 logging.exception('Unhandled exception in fromCSVtoCOBRA') 111 logging.exception('Unhandled exception in fromCSVtoCOBRA')
112 print(f"ERROR: {str(e)}")
113 raise
109 114
110 115
111 if __name__ == '__main__': 116 if __name__ == '__main__':
112 main() 117 main()