Skip to content

Commit

Permalink
AnnotatedSpectrumIndex type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilferrit committed Aug 14, 2024
1 parent 31cc133 commit 695c739
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
14 changes: 13 additions & 1 deletion casanovo/denovo/model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,19 @@ def _get_index(

Index = AnnotatedSpectrumIndex if annotated else SpectrumIndex
valid_charge = np.arange(1, self.config.max_charge + 1)
return Index(index_fname, filenames, valid_charge=valid_charge)

try:
return Index(index_fname, filenames, valid_charge=valid_charge)
except TypeError as e:
if Index == AnnotatedSpectrumIndex:
raise TypeError(
"Error creating annotated spectrum index. "
"This may be the result of having an unannotated MGF file "
"present in the validation peak file path list.\n"
f"Original error message: {e}"
)

raise e

Check warning on line 434 in casanovo/denovo/model_runner.py

View check run for this annotation

Codecov / codecov/patch

casanovo/denovo/model_runner.py#L434

Added line #L434 was not covered by tests

def _get_strategy(self) -> Union[str, DDPStrategy]:
"""Get the strategy for the Trainer.
Expand Down
19 changes: 10 additions & 9 deletions tests/unit_tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,21 @@ def test_evaluate(
assert result_file.is_file()
result_file.unlink()

# Test evaluation with unannotated peak files
# NOTE: Depth Charge raises a TypeError exception when an unannotated
# peak file is in the peak file list when initializing a
# AnnotatedSpectrumIndex
# TODO: Reexamine after Depth Charge v0.4 release
exception_string = (
"Error creating annotated spectrum index. "
"This may be the result of having an unannotated MGF file "
"present in the validation peak file path list.\n"
)

with pytest.raises(FileNotFoundError):
with ModelRunner(config, model_filename=str(model_file)) as runner:
runner.predict([mzml_small], result_file, evaluate=True)

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=exception_string):
with ModelRunner(config, model_filename=str(model_file)) as runner:
runner.predict([mgf_small_unannotated], result_file, evaluate=True)

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=exception_string):
with ModelRunner(config, model_filename=str(model_file)) as runner:
runner.predict(
[mgf_small_unannotated, mzml_small], result_file, evaluate=True
Expand All @@ -230,7 +231,7 @@ def test_evaluate(
assert result_file.is_file()
result_file.unlink()

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=exception_string):
with ModelRunner(config, model_filename=str(model_file)) as runner:
runner.predict(
[mgf_small, mgf_small_unannotated], result_file, evaluate=True
Expand All @@ -239,7 +240,7 @@ def test_evaluate(
assert result_file.is_file()
result_file.unlink()

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=exception_string):
with ModelRunner(config, model_filename=str(model_file)) as runner:
runner.predict(
[mgf_small, mgf_small_unannotated, mzml_small],
Expand Down

0 comments on commit 695c739

Please sign in to comment.