Skip to content

Commit

Permalink
Add option to dekonize peptide into AA list (#22)
Browse files Browse the repository at this point in the history
* Add option to dekonize peptide into AA list

* Bump workflow versions

* Add Codecov token

* Return list from detokenize by default

* Fix my lazy docstring

* Fix broken test

* Bump changelog

Co-authored-by: William Fondrie <[email protected]>
  • Loading branch information
melihyilmaz and wfondrie authored Nov 15, 2022
1 parent 23683c0 commit 4837737
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.9
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"

- name: Install flake8
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 0 1 1/1 *" # Run monthly

jobs:
build:
Expand All @@ -19,11 +14,11 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"

- name: Install dependencies
run: |
Expand All @@ -36,6 +31,7 @@ jobs:
pytest --cov=depthcharge tests/
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2022-11-15
### Changed
- The `detokenize()` method now returns a list instead of a string.

## [0.0.1] - 2022-09-29
### Added
- This if the first release! All changes from this point forward will be
Expand Down
12 changes: 9 additions & 3 deletions depthcharge/components/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,17 @@ def tokenize(self, sequence, partial=False):
return tokens

def detokenize(self, tokens):
"""Transform tokens back into a peptide sequence
"""Transform tokens back into a peptide sequence.
Parameters
----------
tokens : torch.Tensor of shape (n_amino_acids)
tokens : torch.Tensor of shape (n_amino_acids,)
The token for each amino acid in the peptide sequence.
Returns
-------
list of str
The amino acids in the peptide sequence.
"""
sequence = [self._idx2aa.get(i.item(), "") for i in tokens]
if "$" in sequence:
Expand All @@ -199,7 +205,7 @@ def detokenize(self, tokens):
if self.reverse:
sequence = list(reversed(sequence))

return "".join(sequence)
return sequence

@property
def vocab_size(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_denovo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def test_denovo_model(tmp_path, mgf_small):

# Predict
pred = trainer.predict(model, loaders.train_dataloader())
assert pred[0][0][0][0] == "$LESLLEK"
assert "".join(pred[0][0][0][0]) == "$LESLLEK"

0 comments on commit 4837737

Please sign in to comment.