Skip to content

Commit 38d6cdd

Browse files
authored
Merge pull request #79 from Noble-Lab/pypi-release
Update for PyPI release
2 parents a6f43d6 + ed757c1 commit 38d6cdd

File tree

13 files changed

+35
-349
lines changed

13 files changed

+35
-349
lines changed

.github/workflows/black.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- name: Setup Python 3.8
10+
- name: Setup Python 3.10
1111
uses: actions/setup-python@v2
1212
with:
13-
python-version: "3.8"
13+
python-version: "3.10"
1414

1515
- name: Run black
1616
uses: psf/black@stable

.github/workflows/tests.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ name: tests
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ main ]
99
pull_request:
10-
branches: [ master ]
11-
schedule:
12-
- cron: "0 0 1 1/1 *" # Run monthly
10+
branches: [ main ]
1311

1412
jobs:
1513
build:
@@ -20,16 +18,16 @@ jobs:
2018

2119
steps:
2220
- uses: actions/checkout@v2
23-
- name: Set up Python 3.8
21+
- name: Set up Python 3.10
2422
uses: actions/setup-python@v2
2523
with:
26-
python-version: "3.8"
24+
python-version: "3.10"
2725

2826
- name: Install dependencies
2927
run: |
3028
python -m pip install --upgrade pip
3129
pip install flake8 pytest pytest-cov wheel
32-
pip install -e .
30+
pip install -e .[dev]
3331
- name: Lint with flake8
3432
run: |
3533
# stop the build if there are Python syntax errors or undefined names
@@ -38,8 +36,8 @@ jobs:
3836
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3937
- name: Run unit and system tests
4038
run: |
41-
pytest --cov=ppx tests/
39+
pytest --cov=casanovo tests/
4240
- name: Upload coverage to codecov
43-
uses: codecov/codecov-action@v1
41+
uses: codecov/codecov-action@v3
4442
with:
4543
fail_ci_if_error: true

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ All notable changes to this project will be documented in this file.
55
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).
66

77
## [Unreleased]
8-
98
### Added
10-
9+
- The first PyPI release! :tada:
10+
- Tests are run on every PR automatically.
11+
- Test code coverage must be maintained or improved with each change.
1112
- Log the active Casanovo configuration.
1213
- Log to both the console and a log file.
1314
- Use all available hardware resources (GPU and CPU).

CONTRIBUTING.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Contributing to casanovo
1+
# Contributing to Casanovo
22

33
First off, thank you for taking the time to contribute.
44

55
The following document provides guidelines for contributing to the
6-
documentation and the code of casanovo. **No contribution is too small!** Even
6+
documentation and the code of Casanovo. **No contribution is too small!** Even
77
fixing a simple typo in the documentation is immensely helpful.
88

99

@@ -20,7 +20,7 @@ There are three exceptions to this:
2020
2. The Vignettes are created from Jupyter notebooks.
2121

2222
3. The Code of Conduct, Release Notes, and this Contributing document are
23-
markdown files that live in the root of the casanovo repository.
23+
markdown files that live in the root of the Casanovo repository.
2424

2525
### Editing most documents
2626

@@ -39,14 +39,14 @@ way.
3939

4040
## Contributing to the code
4141

42-
We welcome contributions to the source code of casanovo---particularly
43-
ones that address discussed [issues](https://github.com/Noble-Lab/casanovo/issues).
42+
We welcome contributions to the source code of Casanovo---particularly
43+
ones that address discussed [issues](https://github.com/Noble-Lab/Casanovo/issues).
4444

45-
Contributions to casanovo follow a standard GitHub contribution workflow:
45+
Contributions to Casanovo follow a standard GitHub contribution workflow:
4646

47-
1. Create your own fork of the casanovo repository on GitHub.
47+
1. Create your own fork of the Casanovo repository on GitHub.
4848

49-
2. Clone your forked casanovo repository to work on locally.
49+
2. Clone your forked Casanovo repository to work on locally.
5050

5151
3. Create a new branch with a descriptive name for your changes:
5252

@@ -59,19 +59,19 @@ git checkout -b fix_x
5959
5. Add, commit, and push your changes to your forked repository.
6060

6161
6. On the GitHub page for you forked repository, click "Pull request" to propose
62-
adding your changes to casanovo.
62+
adding your changes to Casanovo.
6363

6464
7. We'll review, discuss, and help you make any revisions that are required. If
65-
all goes well, your changes will be added to casanovo
65+
all goes well, your changes will be added to Casanovo
6666
in the next release!
6767

6868

6969
### Python code style
7070

71-
The casanovo project follows the [PEP 8
71+
The Casanovo project follows the [PEP 8
7272
guidelines](https://www.python.org/dev/peps/pep-0008/) for Python code style.
7373
More specifically, we use [black](https://black.readthedocs.io/en/stable/) to
74-
format code and lint Python code in casanovo.
74+
format code and lint Python code in Casanovo.
7575

7676
We highly recommend setting up a pre-commit hook for black. This will run black
7777
on all of the Python source files before the changes can be committed. Because
@@ -90,7 +90,7 @@ pip install black pre-commit
9090
conda -c conda-forge black pre-commit
9191
```
9292

93-
2. Navigate to your local copy of the casanovo repository and activate the hook:
93+
2. Navigate to your local copy of the Casanovo repository and activate the hook:
9494
```bash
9595
pre-commit install
9696
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The base environment most likely will not work.
5252
Install Casanovo as a Python package from this repository (requires 3.8 ≥ [Python version] > 3.10 , dependencies will be installed automatically as needed):
5353

5454
```
55-
pip install git+https://github.com/Noble-Lab/casanovo.git#egg=casanovo
55+
pip install casanovo
5656
```
5757

5858
Once installed, Casanovo can be used with a simple command line interface.

casanovo/casanovo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ def main(
163163
}
164164
# Add extra configuration options and scale by the number of GPUs.
165165
n_gpus = torch.cuda.device_count()
166-
config["n_workers"] = len(psutil.Process().cpu_affinity()) // n_gpus
167-
config["train_batch_size"] = config["train_batch_size"] // n_gpus
166+
config["n_workers"] = len(psutil.Process().cpu_affinity())
167+
if n_gpus > 1:
168+
config["n_workers"] = config["n_workers"] // n_gpus
169+
config["train_batch_size"] = config["train_batch_size"] // n_gpus
168170

169171
pl.utilities.seed.seed_everything(seed=config["random_seed"], workers=True)
170172

casanovo/denovo/model.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytorch_lightning as pl
99
import torch
1010
from depthcharge.components import ModelMixin, PeptideDecoder, SpectrumEncoder
11-
from depthcharge.models.embed.model import PairedSpectrumEncoder
1211

1312
from . import evaluate
1413
from ..data import ms_io
@@ -85,9 +84,7 @@ def __init__(
8584
n_layers: int = 1,
8685
dropout: float = 0.0,
8786
dim_intensity: Optional[int] = None,
88-
custom_encoder: Optional[
89-
Union[SpectrumEncoder, PairedSpectrumEncoder]
90-
] = None,
87+
custom_encoder: Optional[SpectrumEncoder] = None,
9188
max_length: int = 100,
9289
residues: Union[Dict[str, float], str] = "canonical",
9390
max_charge: int = 5,
@@ -106,10 +103,7 @@ def __init__(
106103

107104
# Build the model.
108105
if custom_encoder is not None:
109-
if isinstance(custom_encoder, PairedSpectrumEncoder):
110-
self.encoder = custom_encoder.encoder
111-
else:
112-
self.encoder = custom_encoder
106+
self.encoder = custom_encoder
113107
else:
114108
self.encoder = SpectrumEncoder(
115109
dim_model=dim_model,

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
name = Casanovo
2+
name = casanovo
33
author = Melih Yilmaz
44
author_email = melih@cs.washington.edu
55
description = De Novo Mass Spectrometry Peptide Sequencing with a Transformer Model
@@ -22,7 +22,7 @@ packages = find:
2222
python_requires = >=3.8
2323
install_requires =
2424
click
25-
depthcharge-ms @ git+https://github.com/wfondrie/depthcharge@3dda29053ab479fa31fa1309f65f285d04481c1e
25+
depthcharge-ms>=0.0.1
2626
numpy
2727
pandas
2828
psutil

tests/conftest.py

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
"""Fixtures used for testing
2-
3-
We need:
4-
- To set the PPX_DATA_DIR environment variable to a temporary directory
5-
- A mock GET response from PRIDE
6-
- A mock GET response from ProteomeXchange
7-
- A mock FTP server response from PRIDE
8-
- A mock FTP server response from MassIVE
9-
"""
10-
import json
11-
import socket
12-
import ftplib
13-
1+
"""Setup tests for casanovo"""
142
import pytest
15-
import requests
16-
import ppx
173

184
from pyteomics.mass import calculate_mass
195
import numpy as np
206

21-
# Pytest fixtures added here can be used as parameters for testing methods
22-
237

248
@pytest.fixture
259
def mgf_small(tmp_path):
@@ -29,7 +13,6 @@ def mgf_small(tmp_path):
2913
return _create_mgf(peptides, mgf_file)
3014

3115

32-
# Utility Funcs
3316
def _create_mgf(peptides, mgf_file, random_state=42):
3417
"""Create a fake MGF file from one or more peptides.
3518
Parameters
@@ -90,117 +73,3 @@ def _create_mgf_entry(peptide, charge=2):
9073
"END IONS",
9174
]
9275
return "\n".join(mgf)
93-
94-
95-
# Set the PPX_DATA_DIRECTORY --------------------------------------------------
96-
@pytest.fixture(autouse=True)
97-
def ppx_data_dir(monkeypatch, tmp_path):
98-
"""Set the PPX_DATA_DIR environment variable"""
99-
monkeypatch.setenv("PPX_DATA_DIR", str(tmp_path))
100-
ppx.set_data_dir()
101-
102-
103-
# PRIDE projects/<accession>/files endpoint -----------------------------------
104-
class MockPrideFilesResponse:
105-
"""A mock of the PRIDE files REST response"""
106-
107-
status_code = 200
108-
109-
@staticmethod
110-
def json():
111-
with open("tests/data/pride_files_response.json") as ref:
112-
out = json.load(ref)
113-
114-
return out
115-
116-
117-
@pytest.fixture
118-
def mock_pride_files_response(monkeypatch):
119-
"""Patch requests.get() to use a local file."""
120-
121-
def mock_get(*args, **kwargs):
122-
return MockPrideFilesResponse()
123-
124-
monkeypatch.setattr(requests, "get", mock_get)
125-
126-
127-
# PRIDE projects/<accession? endpoint -----------------------------------------
128-
class MockPrideProjectResponse:
129-
"""A mock of the PRIDE projects REST response"""
130-
131-
status_code = 200
132-
133-
@staticmethod
134-
def json():
135-
with open("tests/data/pride_project_response.json") as ref:
136-
out = json.load(ref)
137-
138-
return out
139-
140-
141-
@pytest.fixture
142-
def mock_pride_project_response(monkeypatch):
143-
"""Patch requests.get() to use a local file."""
144-
145-
def mock_get(*args, **kwargs):
146-
return MockPrideProjectResponse()
147-
148-
monkeypatch.setattr(requests, "get", mock_get)
149-
150-
151-
# MassIVE FTP server ----------------------------------------------------------
152-
class MockMassiveFtpResponse:
153-
"""A mock of the MassIVE FTP server response"""
154-
155-
@staticmethod
156-
def dir(fun):
157-
with open("tests/data/massive_ftp_response.txt") as ref:
158-
[fun(line) for line in ref]
159-
160-
161-
def mock_massive_ftp_response(monkeypatch):
162-
"""Patch ftplib to use a local file as a response"""
163-
164-
def null(*args, **kwargs):
165-
pass
166-
167-
def mock_dir(fun):
168-
with open("tests/data/massive_ftp_response.txt") as ref:
169-
[fun(line) for line in ref]
170-
171-
monkeypatch.setattr(ftplib.FTP, "login", null)
172-
monkeypatch.setattr(ftplib.FTP, "cwd", null)
173-
monkeypatch.setattr(ftplib.FTP, "dir", mock_dir)
174-
175-
176-
# Mock up local files ---------------------------------------------------------
177-
@pytest.fixture
178-
def local_files(tmp_path):
179-
"""Create some files to test local file detection"""
180-
local_dirs = [tmp_path / f"test_dir{i}" for i in range(10)]
181-
local_files = []
182-
for local_dir in local_dirs:
183-
local_dir.mkdir()
184-
files = [
185-
local_dir / "test_file.mzML",
186-
local_dir / "test_file.txt",
187-
]
188-
local_files += files
189-
for local_file in files:
190-
local_file.touch()
191-
192-
local_files.append(tmp_path / "test_file.mzML")
193-
local_files[-1].touch()
194-
return local_files, local_dirs
195-
196-
197-
# Block internet --------------------------------------------------------------
198-
@pytest.fixture
199-
def block_internet(monkeypatch):
200-
"""Turn off internet access"""
201-
202-
class Blocker(socket.socket):
203-
def __init__(self, *args, **kwargs):
204-
raise OSError("Network call blocked")
205-
206-
monkeypatch.setattr(socket, "socket", Blocker)

tests/system_tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)