diff --git a/ruby/lib/hla_algorithm.rb b/ruby/lib/hla_algorithm.rb index 9ccf95c..7bf1e0e 100644 --- a/ruby/lib/hla_algorithm.rb +++ b/ruby/lib/hla_algorithm.rb @@ -46,6 +46,12 @@ def initialize(raw_result) class HLAAlgorithm + class Error < RuntimeError + end + + class NoMatchingStandards < Error + end + def initialize( hla_std_path=nil, hla_freq_path=nil @@ -83,6 +89,11 @@ def analyze(seqs, locus='B', threshold=nil) raise error_msg end + result = JSON.parse(python_stdout) + if result.key?('exception') && result['exception'] == 'no matching standards' + raise(NoMatchingStandards) + end + return HLAResult.new(JSON.parse(python_stdout)) end end diff --git a/src/hla_algorithm/interpret_from_json.py b/src/hla_algorithm/interpret_from_json.py index bc91616..a868445 100644 --- a/src/hla_algorithm/interpret_from_json.py +++ b/src/hla_algorithm/interpret_from_json.py @@ -44,9 +44,14 @@ def main(): hla_input.hla_std_path, hla_input.hla_freq_path, ) - interp: HLAInterpretation = hla_alg.interpret( - hla_input.hla_sequence(), hla_input.threshold - ) + try: + interp: HLAInterpretation = hla_alg.interpret( + hla_input.hla_sequence(), hla_input.threshold + ) + except HLAAlgorithm.NoMatchingStandards: + print(json.dumps({"exception": "no matching standards"})) + return + print( HLAResult.build_from_interpretation( interp, hla_alg.tag, hla_alg.last_updated