From 4837737d4e8ca6acbc6f7f3ea0cecd6d903e5c96 Mon Sep 17 00:00:00 2001 From: Melih Yilmaz <32707537+melihyilmaz@users.noreply.github.com> Date: Tue, 15 Nov 2022 14:31:27 -0800 Subject: [PATCH] Add option to dekonize peptide into AA list (#22) * 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 --- .github/workflows/docs.yml | 4 ++-- .github/workflows/lint.yml | 8 ++++---- .github/workflows/publish.yml | 4 ++-- .github/workflows/tests.yml | 16 ++++++---------- CHANGELOG.md | 4 ++++ depthcharge/components/transformers.py | 12 +++++++++--- tests/unit_tests/test_denovo.py | 2 +- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f27d6cd..ce22324 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b5ad20c..3a58fcd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dea50c1..2b70c8c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 72fb8a2..8277720 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,3 @@ -# 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: @@ -8,8 +5,6 @@ on: branches: [ main ] pull_request: branches: [ main ] - schedule: - - cron: "0 0 1 1/1 *" # Run monthly jobs: build: @@ -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: | @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c138e..df7a7bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/depthcharge/components/transformers.py b/depthcharge/components/transformers.py index 34b701d..09aa0e4 100644 --- a/depthcharge/components/transformers.py +++ b/depthcharge/components/transformers.py @@ -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: @@ -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): diff --git a/tests/unit_tests/test_denovo.py b/tests/unit_tests/test_denovo.py index e81b75a..718ccc0 100644 --- a/tests/unit_tests/test_denovo.py +++ b/tests/unit_tests/test_denovo.py @@ -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"