Skip to content

Commit

Permalink
Fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wfondrie committed May 10, 2024
1 parent 7d022f3 commit 931c37c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion depthcharge/tokenizers/peptides.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def detokenize(
tokens=tokens,
join=join,
trim_start_token=trim_start_token,
trim_stop_token=trim_start_token,
trim_stop_token=trim_stop_token,
)

if self.reverse:
Expand Down
22 changes: 22 additions & 0 deletions tests/unit_tests/test_tokenizers/test_peptides.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,25 @@ def test_almost_compliant_proform():
"""Test initializing with a peptide without an expicit mass sign."""
tokenizer = PeptideTokenizer.from_proforma("[10]-EDITHR")
assert "[+10.000000]-" in tokenizer.residues


@pytest.mark.parametrize(
("start", "stop", "expected"),
[
(True, True, "ACD"),
(True, False, "ACD$E"),
(False, True, "?ACD"),
(False, False, "?ACD$E"),
],
)
def test_trim(start, stop, expected):
"""Test that the start and stop tokens can be trimmed."""
tokenizer = PeptideTokenizer(start_token="?")
tokens = torch.tensor([[2, 3, 4, 5, 1, 6]])
out = tokenizer.detokenize(
tokens,
trim_start_token=start,
trim_stop_token=stop,
)

assert out[0] == expected

0 comments on commit 931c37c

Please sign in to comment.