Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ruby/lib/hla_algorithm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def initialize(raw_result)


class HLAAlgorithm
class Error < RuntimeError
end

class NoMatchingStandards < Error
end

Comment on lines +49 to +54
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer these outside the class and called HLARuntimeError and HLANoMatchingStandardsError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about this, but the style in the code was just mimicking the code in the docs:

https://docs.ruby-lang.org/en/3.3/Exception.html#class-Exception-label-Custom+Exceptions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, keep it as-is. Although I think I'd be more comfortable if the base exception wasn't just called "Error".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this a little more, I think your suggestion is perhaps more Pythonic and works better in a language with stricter namespacing than Ruby.

def initialize(
hla_std_path=nil,
hla_freq_path=nil
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions src/hla_algorithm/interpret_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading