comparison COBRAxy/fromCSVtoCOBRA_beta.py @ 454:3654c08668f1 draft

Uploaded
author francesco_lapi
date Thu, 11 Sep 2025 21:02:09 +0000
parents 51f794fff930
children 4e2bc80764b6
comparison
equal deleted inserted replaced
453:51f794fff930 454:3654c08668f1
59 59
60 try: 60 try:
61 # Basic sanity checks 61 # Basic sanity checks
62 if not os.path.exists(ARGS.input): 62 if not os.path.exists(ARGS.input):
63 logging.error('Input file not found: %s', ARGS.input) 63 logging.error('Input file not found: %s', ARGS.input)
64 print(f"ERROR: Input file not found: {ARGS.input}", file=sys.stderr)
65 sys.exit(2)
66 64
67 out_dir = os.path.dirname(os.path.abspath(ARGS.output)) 65 out_dir = os.path.dirname(os.path.abspath(ARGS.output))
68 if out_dir and not os.path.isdir(out_dir): 66 if out_dir and not os.path.isdir(out_dir):
69 try: 67 try:
70 os.makedirs(out_dir, exist_ok=True) 68 os.makedirs(out_dir, exist_ok=True)
71 logging.info('Created missing output directory: %s', out_dir) 69 logging.info('Created missing output directory: %s', out_dir)
72 except Exception as e: 70 except Exception as e:
73 logging.exception('Cannot create output directory: %s', out_dir) 71 logging.exception('Cannot create output directory: %s', out_dir)
74 print(f"ERROR: Cannot create output directory: {out_dir}", file=sys.stderr)
75 sys.exit(3)
76 72
77 # Build the model from the CSV (NOTE: use ARGS.input here) 73 # Build the model from the CSV (NOTE: use ARGS.input here)
78 model = modelUtils.build_cobra_model_from_csv(ARGS.input) 74 model = modelUtils.build_cobra_model_from_csv(ARGS.input)
79 75
80 # Save model in requested format 76 # Save model in requested format
86 cobra.io.save_matlab_model(model, ARGS.output) 82 cobra.io.save_matlab_model(model, ARGS.output)
87 elif ARGS.format == "yaml": 83 elif ARGS.format == "yaml":
88 cobra.io.save_yaml_model(model, ARGS.output) 84 cobra.io.save_yaml_model(model, ARGS.output)
89 else: 85 else:
90 logging.error('Unknown format requested: %s', ARGS.format) 86 logging.error('Unknown format requested: %s', ARGS.format)
91 print(f"ERROR: Unknown format: {ARGS.format}", file=sys.stderr) 87 print(f"ERROR: Unknown format: {ARGS.format}")
92 sys.exit(4) 88
93 89
94 logging.info('Model successfully written to %s (format=%s)', ARGS.output, ARGS.format) 90 logging.info('Model successfully written to %s (format=%s)', ARGS.output, ARGS.format)
95 91
96 except Exception: 92 except Exception:
97 # Log full traceback to the out_log so Galaxy users/admins can see what happened 93 # Log full traceback to the out_log so Galaxy users/admins can see what happened
98 logging.exception('Unhandled exception in fromCSVtoCOBRA') 94 logging.exception('Unhandled exception in fromCSVtoCOBRA')
99 traceback.print_exc(file=sys.stderr)
100 sys.exit(1)
101 95
102 96
103 if __name__ == '__main__': 97 if __name__ == '__main__':
104 main() 98 main()