diff --git a/rptools/rpscore/__init__.py b/rptools/rpscore/__init__.py index 8cfff74..2548fad 100644 --- a/rptools/rpscore/__init__.py +++ b/rptools/rpscore/__init__.py @@ -4,6 +4,8 @@ @author: Joan Hérisson, Jean_Loup Faulon """ -from rptools.rpscore.rpScore import ( - predict_score +from rptools.rpscore.rpscore import ( + predict_score, + ThermoError, + FBAError ) diff --git a/rptools/rpscore/__main__.py b/rptools/rpscore/__main__.py index 201d11c..7c90f00 100644 --- a/rptools/rpscore/__main__.py +++ b/rptools/rpscore/__main__.py @@ -6,13 +6,13 @@ Logger, getLogger ) -from os import ( - path as os_path, - makedirs +from os import path as os_path +from .rpscore import ( + predict_score, + ThermoError, + FBAError ) -from tempfile import NamedTemporaryFile -from rptools.rpscore import predict_score -from rptools.rpscore.Args import add_arguments +from .Args import add_arguments from rptools.rplibs import rpPathway from rptools import build_args_parser @@ -47,13 +47,20 @@ def entry_point(): logger=logger ) - score = predict_score( - pathway=pathway, - # data_train_file=args.data_train_file, - # models_path=models_path, - no_of_rxns_thres=args.no_of_rxns_thres, - logger=logger - ) + try: + score = predict_score( + pathway=pathway, + # data_train_file=args.data_train_file, + # models_path=models_path, + no_of_rxns_thres=args.no_of_rxns_thres, + logger=logger + ) + except ThermoError as e: + logger.error(e) + exit(1) + except FBAError as e: + logger.error(e) + exit(2) # if len(pathways) > 1: # if not os_path.exists(args.outdir): diff --git a/rptools/rpscore/rpScore.py b/rptools/rpscore/rpScore.py index 998dd03..4029f81 100644 --- a/rptools/rpscore/rpScore.py +++ b/rptools/rpscore/rpScore.py @@ -44,6 +44,14 @@ ) +class ThermoError(Exception): + pass + + +class FBAError(Exception): + pass + + ############################################################################################## def feature_template_df(no_of_rxns_thres): @@ -481,16 +489,12 @@ def format_files( if pathway.get_thermo_dGm_prime(): data['dfG_prime_m'] = pathway.get_thermo_dGm_prime()['value'] else: - logger.error('No thermodynamics data available') - logger.error('Exiting...') - sys_exit(1) + raise ThermoError('No thermodynamics data available') if pathway.get_fba(): data['FBA'] = ';'.join(pathway.get_fba().keys()) data['FBA Flux'] = ';'.join([str(v['value']) for v in pathway.get_fba().values()]) else: - logger.error('No FBA data available') - logger.error('Exiting...') - sys_exit(2) + raise FBAError('No FBA data available') pathways_fp.write( ','.join( [str(data.get(c, '')) for c in columns]