Skip to content

Commit

Permalink
aa_match test cases, minor aa_match refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilferrit committed Sep 24, 2024
1 parent e9bb5ec commit 60524af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions casanovo/denovo/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def aa_match(
Boolean flag to indicate whether the two peptide sequences fully match.
"""
if peptide1 is None and peptide2 is None:
return np.array([], dtype=bool), False
elif (peptide1 is None) != (peptide2 is None):
return np.empty(0, dtype=bool), False
elif peptide1 is None or peptide2 is None:
peptide = peptide1 if peptide2 is None else peptide2
return np.array([False] * len(peptide)), False
return np.zeros(len(peptide), dtype=bool), False
elif mode == "best":
return aa_match_prefix_suffix(
peptide1, peptide2, aa_dict, cum_mass_threshold, ind_mass_threshold
Expand Down
17 changes: 16 additions & 1 deletion tests/unit_tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import unittest
import unittest.mock

import depthcharge.masses
import einops
import github
import numpy as np
Expand All @@ -24,7 +25,7 @@
from casanovo import utils
from casanovo.data import ms_io
from casanovo.data.datasets import SpectrumDataset, AnnotatedSpectrumDataset
from casanovo.denovo.evaluate import aa_match_batch, aa_match_metrics
from casanovo.denovo.evaluate import aa_match_batch, aa_match_metrics, aa_match
from casanovo.denovo.model import Spec2Pep, _aa_pep_score
from depthcharge.data import SpectrumIndex, AnnotatedSpectrumIndex

Expand Down Expand Up @@ -846,6 +847,20 @@ def test_eval_metrics():
assert 26 / 40 == pytest.approx(aa_recall)
assert 26 / 41 == pytest.approx(aa_precision)

aa_matches, pep_match = aa_match(
None, None, depthcharge.masses.PeptideMass().masses
)

assert aa_matches.shape == (0,)
assert not pep_match

aa_matches, pep_match = aa_match(
"PEPTIDE", None, depthcharge.masses.PeptideMass().masses
)

assert np.array_equal(aa_matches, np.zeros(len("PEPTIDE"), dtype=bool))
assert not pep_match


def test_spectrum_id_mgf(mgf_small, tmp_path):
"""Test that spectra from MGF files are specified by their index."""
Expand Down

0 comments on commit 60524af

Please sign in to comment.