From 965d367dc6e56c637120c2ee75432f860e7ba81c Mon Sep 17 00:00:00 2001 From: rhliang Date: Wed, 13 May 2026 15:39:02 -0700 Subject: [PATCH 1/3] Added some Ruby handling for cases when no matching standards are found for a sequence. --- ruby/lib/hla_algorithm.rb | 11 +++++++++++ src/hla_algorithm/interpret_from_json.py | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ruby/lib/hla_algorithm.rb b/ruby/lib/hla_algorithm.rb index 9ccf95c..f59ba07 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.new() + 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..4916845 100644 --- a/src/hla_algorithm/interpret_from_json.py +++ b/src/hla_algorithm/interpret_from_json.py @@ -44,9 +44,12 @@ 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({"exception": "no matching standards"}) print( HLAResult.build_from_interpretation( interp, hla_alg.tag, hla_alg.last_updated From 237676e2d77940c3de3be3776ccd6b0c693dee43 Mon Sep 17 00:00:00 2001 From: Richard Liang Date: Wed, 13 May 2026 16:16:49 -0700 Subject: [PATCH 2/3] Fixed the "exception" output of interpret_from_json. --- src/hla_algorithm/interpret_from_json.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hla_algorithm/interpret_from_json.py b/src/hla_algorithm/interpret_from_json.py index 4916845..a868445 100644 --- a/src/hla_algorithm/interpret_from_json.py +++ b/src/hla_algorithm/interpret_from_json.py @@ -49,7 +49,9 @@ def main(): hla_input.hla_sequence(), hla_input.threshold ) except HLAAlgorithm.NoMatchingStandards: - print({"exception": "no matching standards"}) + print(json.dumps({"exception": "no matching standards"})) + return + print( HLAResult.build_from_interpretation( interp, hla_alg.tag, hla_alg.last_updated From 96ad58ca896216a4610a20af068cd783183a1b8c Mon Sep 17 00:00:00 2001 From: rhliang Date: Fri, 15 May 2026 11:12:59 -0700 Subject: [PATCH 3/3] Changed the syntax used to raise a NoMatchingStandards exception. --- ruby/lib/hla_algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/lib/hla_algorithm.rb b/ruby/lib/hla_algorithm.rb index f59ba07..7bf1e0e 100644 --- a/ruby/lib/hla_algorithm.rb +++ b/ruby/lib/hla_algorithm.rb @@ -91,7 +91,7 @@ def analyze(seqs, locus='B', threshold=nil) result = JSON.parse(python_stdout) if result.key?('exception') && result['exception'] == 'no matching standards' - raise NoMatchingStandards.new() + raise(NoMatchingStandards) end return HLAResult.new(JSON.parse(python_stdout))