Skip to content

Commit

Permalink
chore(rpscore): handle errors differently
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Oct 16, 2023
1 parent 49859fb commit d924a48
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
6 changes: 4 additions & 2 deletions rptools/rpscore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
33 changes: 20 additions & 13 deletions rptools/rpscore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
16 changes: 10 additions & 6 deletions rptools/rpscore/rpScore.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
)


class ThermoError(Exception):
pass


class FBAError(Exception):
pass


##############################################################################################

def feature_template_df(no_of_rxns_thres):
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit d924a48

Please sign in to comment.