weirdo 2.1.3__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- weirdo-2.2.0/MANIFEST.in +2 -0
- {weirdo-2.1.3/weirdo.egg-info → weirdo-2.2.0}/PKG-INFO +75 -51
- {weirdo-2.1.3 → weirdo-2.2.0}/README.md +62 -30
- weirdo-2.2.0/pyproject.toml +67 -0
- weirdo-2.2.0/requirements.txt +5 -0
- weirdo-2.2.0/scripts/category_data.py +346 -0
- weirdo-2.2.0/scripts/category_eval.py +291 -0
- weirdo-2.2.0/scripts/category_headroom.py +231 -0
- weirdo-2.2.0/scripts/check_released_model.py +36 -0
- weirdo-2.2.0/scripts/train_category_predictor.py +398 -0
- weirdo-2.2.0/scripts/train_modal_long_run.py +274 -0
- weirdo-2.2.0/test/test_bundled_models.py +187 -0
- weirdo-2.2.0/test/test_category_data.py +299 -0
- weirdo-2.2.0/test/test_category_eval.py +191 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_cli_logic.py +17 -2
- weirdo-2.2.0/test/test_data_manager.py +144 -0
- weirdo-2.2.0/test/test_kmer_table.py +169 -0
- weirdo-2.2.0/test/test_mlp_sigmoid_head.py +342 -0
- weirdo-2.2.0/test/test_model_downloads.py +127 -0
- weirdo-2.2.0/test/test_peptide_features.py +224 -0
- weirdo-2.2.0/test/test_pretrained_category_model.py +96 -0
- weirdo-2.2.0/test/test_released_model.py +144 -0
- weirdo-2.2.0/test/test_train_category_predictor.py +135 -0
- weirdo-2.2.0/test/test_uniprot.py +261 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/__init__.py +12 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/api.py +89 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/cli.py +91 -24
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/data_manager.py +96 -72
- weirdo-2.2.0/weirdo/kmer_table.py +285 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/model_manager.py +75 -34
- weirdo-2.2.0/weirdo/pretrained/swissprot-categories/config.json +20 -0
- weirdo-2.2.0/weirdo/pretrained/swissprot-categories/manifest.json +104 -0
- weirdo-2.2.0/weirdo/pretrained/swissprot-categories/metadata.json +1424 -0
- weirdo-2.2.0/weirdo/pretrained/swissprot-categories/model.pt +0 -0
- weirdo-2.2.0/weirdo/released.py +251 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/base.py +1 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/config.py +1 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/mlp.py +765 -859
- weirdo-2.2.0/weirdo/scorers/peptide_features.py +871 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/reference.py +1 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/similarity.py +1 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/trainable.py +1 -3
- weirdo-2.2.0/weirdo/uniprot.py +397 -0
- {weirdo-2.1.3 → weirdo-2.2.0/weirdo.egg-info}/PKG-INFO +75 -51
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo.egg-info/SOURCES.txt +25 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo.egg-info/requires.txt +4 -3
- weirdo-2.2.0/weirdo.egg-info/top_level.txt +6 -0
- weirdo-2.1.3/MANIFEST.in +0 -1
- weirdo-2.1.3/requirements.txt +0 -4
- weirdo-2.1.3/setup.py +0 -100
- weirdo-2.1.3/test/test_data_manager.py +0 -39
- weirdo-2.1.3/test/test_model_downloads.py +0 -96
- weirdo-2.1.3/weirdo.egg-info/top_level.txt +0 -1
- {weirdo-2.1.3 → weirdo-2.2.0}/LICENSE +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/setup.cfg +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_amino_acids.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_blosum.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_hamming.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_logic_consistency.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_mlp_scorers.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_ngram.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_pmbec.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_scorers.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/test/test_swissprot_reference.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/amino_acid.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/amino_acid_alphabet.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/amino_acid_properties.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/blosum.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/chou_fasman.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/common.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/distances.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/BLOSUM30 +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/BLOSUM50 +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/BLOSUM62 +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/__init__.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/amino_acid_properties.txt +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/helix_vs_coil.txt +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/helix_vs_strand.txt +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/pmbec.mat +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/matrices/strand_vs_coil.txt +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/peptide_vectorizer.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/pmbec.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/reduced_alphabet.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/residue_contact_energies.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/__init__.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/registry.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/scorers/swissprot.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo/static_data.py +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo.egg-info/dependency_links.txt +0 -0
- {weirdo-2.1.3 → weirdo-2.2.0}/weirdo.egg-info/entry_points.txt +0 -0
weirdo-2.2.0/MANIFEST.in
ADDED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: weirdo
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Metrics of immunological foreignness for candidate T-cell epitopes
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
License: Apache-2.0
|
|
5
|
+
Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
|
|
6
|
+
Project-URL: Homepage, https://github.com/pirl-unc/weirdo
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/pirl-unc/weirdo/issues
|
|
9
8
|
Classifier: Development Status :: 4 - Beta
|
|
10
9
|
Classifier: Environment :: Console
|
|
11
10
|
Classifier: Operating System :: OS Independent
|
|
12
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
20
|
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.10
|
|
20
22
|
Description-Content-Type: text/markdown
|
|
21
23
|
License-File: LICENSE
|
|
22
24
|
Requires-Dist: numpy<3.0.0,>=2.0.0
|
|
23
|
-
Requires-Dist: pandas
|
|
24
|
-
Requires-Dist: scikit-learn<2.0.0,>=1.
|
|
25
|
+
Requires-Dist: pandas>=2.2.0
|
|
26
|
+
Requires-Dist: scikit-learn<2.0.0,>=1.7.0
|
|
27
|
+
Requires-Dist: datacache>=1.24.0
|
|
25
28
|
Provides-Extra: dev
|
|
26
29
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
27
30
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
28
|
-
Requires-Dist:
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
29
32
|
Requires-Dist: sphinx>=5.0.0; extra == "dev"
|
|
30
33
|
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "dev"
|
|
31
34
|
Requires-Dist: sphinx-autodoc-typehints>=1.0.0; extra == "dev"
|
|
@@ -34,18 +37,7 @@ Provides-Extra: docs
|
|
|
34
37
|
Requires-Dist: sphinx>=5.0.0; extra == "docs"
|
|
35
38
|
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
|
|
36
39
|
Requires-Dist: sphinx-autodoc-typehints>=1.0.0; extra == "docs"
|
|
37
|
-
Dynamic: author
|
|
38
|
-
Dynamic: author-email
|
|
39
|
-
Dynamic: classifier
|
|
40
|
-
Dynamic: description
|
|
41
|
-
Dynamic: description-content-type
|
|
42
|
-
Dynamic: home-page
|
|
43
|
-
Dynamic: license
|
|
44
40
|
Dynamic: license-file
|
|
45
|
-
Dynamic: provides-extra
|
|
46
|
-
Dynamic: requires-dist
|
|
47
|
-
Dynamic: requires-python
|
|
48
|
-
Dynamic: summary
|
|
49
41
|
|
|
50
42
|
[](https://github.com/pirl-unc/weirdo/actions/workflows/tests.yml)
|
|
51
43
|
[](https://github.com/pirl-unc/weirdo/actions/workflows/docs.yml)
|
|
@@ -56,17 +48,43 @@ Dynamic: summary
|
|
|
56
48
|
|
|
57
49
|
**W**idely **E**stimated **I**mmunological **R**ecognition and **D**etection of **O**utliers
|
|
58
50
|
|
|
59
|
-
A Python library for
|
|
51
|
+
A Python library that predicts, for any peptide, the probability that it occurs in proteins of each of ten species categories, and summarizes them as a pathogen-versus-mammalian foreignness score.
|
|
60
52
|
|
|
61
53
|
## Overview
|
|
62
54
|
|
|
63
|
-
WEIRDO trains a multi-layer perceptron (MLP) on k-mer presence data from SwissProt to predict organism category membership
|
|
55
|
+
WEIRDO trains a multi-layer perceptron (MLP) on k-mer presence data from SwissProt to predict organism category membership, and ships a trained model, `swissprot-categories`. Given any peptide of 8 residues or more, it outputs:
|
|
64
56
|
|
|
65
|
-
- **Category probabilities**:
|
|
66
|
-
- **
|
|
57
|
+
- **Category probabilities**: one independent sigmoid output for each of ten categories (archaea, bacteria, fungi, human, invertebrates, mammals, plants, rodents, vertebrates, viruses), the probability that the peptide occurs in SwissProt proteins of that category. The outputs are close to calibrated but only weakly informative: on protein families not seen in training the mean AUC is about 0.6.
|
|
58
|
+
- **Pathogen and self values**: the largest probability among the pathogen categories (bacteria, viruses) and among the mammalian categories (human, rodents, mammals).
|
|
59
|
+
- **Foreignness score**: `max(pathogen) / (max(pathogen) + max(self))`. The combination is a parameter: `combine="sum"` compares the summed probabilities instead (the expected number of categories in each group that contain the peptide), and `combine` also accepts your own function. Five categories (archaea, fungi, invertebrates, plants, vertebrates) are in neither default group; pass `pathogen_categories` / `self_categories` to change the groups.
|
|
60
|
+
|
|
61
|
+
[docs/category-predictor.md](docs/category-predictor.md) explains what the numbers mean, how the model was evaluated and what its limits are. A typical peptide scores about 0.81 on the foreignness scale (peptides found only in mammalian proteins: median 0.76; only in bacteria/viruses: 0.84), so compare a score with those reference distributions rather than with 0.5. Nothing here has been shown to predict T-cell immunogenicity. The bundled weights derive from UniProtKB/Swiss-Prot sequences (CC BY 4.0).
|
|
67
62
|
|
|
68
63
|
## Quick Start
|
|
69
64
|
|
|
65
|
+
```python
|
|
66
|
+
from weirdo import predict_categories
|
|
67
|
+
|
|
68
|
+
predict_categories(['SIINFEKL', 'NLVPMVATV', 'GILGFVFTL'])
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
peptide archaea bacteria fungi human invertebrates mammals plants rodents vertebrates viruses pathogen_max self_max foreignness
|
|
73
|
+
SIINFEKL 0.077 0.389 0.141 0.044 0.158 0.025 0.102 0.048 0.026 0.057 0.389 0.048 0.891
|
|
74
|
+
NLVPMVATV 0.026 0.461 0.100 0.092 0.069 0.047 0.116 0.106 0.040 0.027 0.461 0.106 0.813
|
|
75
|
+
GILGFVFTL 0.045 0.435 0.118 0.083 0.076 0.041 0.112 0.093 0.038 0.031 0.435 0.093 0.823
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`predict_categories(peptides, combine="sum")` gives `pathogen_sum` and `self_sum` columns instead.
|
|
79
|
+
|
|
80
|
+
Individual outputs stay close to the base rates (the two viral epitopes get a virus probability of about 0.03); see [docs/category-predictor.md](docs/category-predictor.md).
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
weirdo score SIINFEKL NLVPMVATV GILGFVFTL
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Training your own model
|
|
87
|
+
|
|
70
88
|
```python
|
|
71
89
|
from weirdo.scorers import SwissProtReference, MLPScorer
|
|
72
90
|
|
|
@@ -86,22 +104,16 @@ peptides, labels = ref.get_training_data(
|
|
|
86
104
|
max_samples=200000 # Optional: sample for faster training
|
|
87
105
|
)
|
|
88
106
|
|
|
89
|
-
# Train the MLP
|
|
107
|
+
# Train the MLP: binary multi-label targets use one sigmoid per category and
|
|
108
|
+
# binary cross-entropy, so predict_proba returns probabilities.
|
|
90
109
|
scorer = MLPScorer(k=8, hidden_layer_sizes=(256, 128, 64))
|
|
91
110
|
scorer.train(peptides, labels, target_categories=categories, epochs=200)
|
|
92
111
|
|
|
93
112
|
# Score new peptides (any length)
|
|
94
113
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
95
|
-
print(df)
|
|
96
114
|
```
|
|
97
115
|
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
peptide human viruses bacteria mammals ... foreignness
|
|
101
|
-
MTMDKSEL 0.82 0.12 0.08 0.79 ... 0.127
|
|
102
|
-
SIINFEKL 0.15 0.73 0.21 0.18 ... 0.802
|
|
103
|
-
NLVPMVATV 0.31 0.68 0.15 0.35 ... 0.660
|
|
104
|
-
```
|
|
116
|
+
Early stopping needs validation peptides that are not near-duplicates of the training ones (overlapping 8-mers of one protein share 7 residues); pass `val_peptides` / `val_labels` built from different protein families. `scripts/train_category_predictor.py` does this and was used to train the bundled model.
|
|
105
117
|
|
|
106
118
|
## Installation
|
|
107
119
|
|
|
@@ -109,14 +121,19 @@ print(df)
|
|
|
109
121
|
pip install weirdo
|
|
110
122
|
```
|
|
111
123
|
|
|
112
|
-
|
|
124
|
+
The bundled model needs no extra data. To train your own model or use the SwissProt reference
|
|
125
|
+
scorers, build the reference data from UniProt:
|
|
113
126
|
```bash
|
|
114
|
-
weirdo data download
|
|
127
|
+
weirdo data download swissprot-sequences # ~670 MB from UniProt, builds a ~230 MB table
|
|
128
|
+
weirdo data download # also builds the 8-mer table (several GB, some minutes)
|
|
115
129
|
```
|
|
130
|
+
The files are fetched with [datacache](https://github.com/openvax/datacache) from UniProt's FTP site
|
|
131
|
+
(`WEIRDO_UNIPROT_URL` selects a mirror), checked against the sizes and MD5s UniProt lists and kept
|
|
132
|
+
in `~/.weirdo/downloads/uniprot/release-<version>/`, so they are downloaded once per UniProt release.
|
|
116
133
|
|
|
117
134
|
## Training Data
|
|
118
135
|
|
|
119
|
-
WEIRDO
|
|
136
|
+
WEIRDO builds its 8-mer data from UniProtKB/Swiss-Prot (~100M unique k-mers) with `weirdo data download`:
|
|
120
137
|
|
|
121
138
|
| Category | Description |
|
|
122
139
|
|----------|-------------|
|
|
@@ -203,7 +220,7 @@ scorer.train(
|
|
|
203
220
|
### Prediction
|
|
204
221
|
|
|
205
222
|
```python
|
|
206
|
-
# Category probabilities
|
|
223
|
+
# Category probabilities, one independent sigmoid per category
|
|
207
224
|
probs = scorer.predict_proba(['MTMDKSEL'])
|
|
208
225
|
# Shape: (1, n_categories)
|
|
209
226
|
|
|
@@ -211,9 +228,9 @@ probs = scorer.predict_proba(['MTMDKSEL'])
|
|
|
211
228
|
foreign = scorer.foreignness(
|
|
212
229
|
['MTMDKSEL'],
|
|
213
230
|
pathogen_categories=['bacteria', 'viruses'],
|
|
214
|
-
self_categories=['human', 'mammals', 'rodents']
|
|
231
|
+
self_categories=['human', 'mammals', 'rodents'],
|
|
232
|
+
combine='max', # default: max(pathogens) / (max(pathogens) + max(self)); 'sum' adds the probabilities
|
|
215
233
|
)
|
|
216
|
-
# Returns: max(pathogens) / (max(pathogens) + max(self))
|
|
217
234
|
|
|
218
235
|
# Full DataFrame output (handles variable-length peptides)
|
|
219
236
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
@@ -251,7 +268,7 @@ scorer = load_model('my-foreignness-model')
|
|
|
251
268
|
|
|
252
269
|
```bash
|
|
253
270
|
# Data management
|
|
254
|
-
weirdo data download # Download SwissProt reference
|
|
271
|
+
weirdo data download # Download SwissProt from UniProt and build the reference data
|
|
255
272
|
weirdo data list # Show data status
|
|
256
273
|
|
|
257
274
|
# Model management
|
|
@@ -263,7 +280,9 @@ weirdo models download NAME # Download pretrained weights by name
|
|
|
263
280
|
weirdo models download --url https://.../model.tar.gz --save-as my-model
|
|
264
281
|
|
|
265
282
|
# Scoring
|
|
266
|
-
weirdo score
|
|
283
|
+
weirdo score MTMDKSEL SIINFEKL # bundled swissprot-categories model
|
|
284
|
+
weirdo score --combine sum MTMDKSEL # compare summed instead of maximal probabilities
|
|
285
|
+
weirdo score --model my-model MTMDKSEL # a model you trained
|
|
267
286
|
```
|
|
268
287
|
|
|
269
288
|
## Long-Run Training on Modal
|
|
@@ -272,8 +291,8 @@ Use `scripts/train_modal_long_run.py` to run long remote training and export
|
|
|
272
291
|
weights as a `.tar.gz` archive:
|
|
273
292
|
|
|
274
293
|
```bash
|
|
275
|
-
# One-time setup: seed
|
|
276
|
-
modal volume put weirdo-data-cache
|
|
294
|
+
# One-time setup: seed the SwissProt CSV (built by `weirdo data download`) into the Modal data volume
|
|
295
|
+
modal volume put weirdo-data-cache ~/.weirdo/downloads/swissprot-8mers.csv downloads/swissprot-8mers.csv --force
|
|
277
296
|
```
|
|
278
297
|
|
|
279
298
|
```bash
|
|
@@ -314,14 +333,19 @@ new package version.
|
|
|
314
333
|
```
|
|
315
334
|
weirdo/
|
|
316
335
|
├── scorers/
|
|
317
|
-
│ ├── mlp.py
|
|
318
|
-
│ ├──
|
|
319
|
-
│ ├──
|
|
320
|
-
│ ├──
|
|
321
|
-
│
|
|
322
|
-
|
|
336
|
+
│ ├── mlp.py # MLPScorer (sigmoid heads, foreignness)
|
|
337
|
+
│ ├── peptide_features.py # The 592 peptide features (vectorised)
|
|
338
|
+
│ ├── swissprot.py # SwissProtReference (training data)
|
|
339
|
+
│ ├── config.py # Presets and configuration
|
|
340
|
+
│ ├── registry.py # Scorer registry
|
|
341
|
+
│ └── trainable.py # TrainableScorer base class
|
|
342
|
+
├── pretrained/ # Models that ship in the package (weights up to 5 MB)
|
|
343
|
+
├── uniprot.py # Download SwissProt from UniProt (datacache), build sequences
|
|
344
|
+
├── kmer_table.py # Build the SwissProt k-mer reference table
|
|
345
|
+
├── data_manager.py # ~/.weirdo reference data
|
|
346
|
+
├── model_manager.py # Save/load trained models
|
|
323
347
|
├── amino_acid_properties.py # 12 AA property dictionaries
|
|
324
|
-
└── api.py
|
|
348
|
+
└── api.py # High-level functions
|
|
325
349
|
```
|
|
326
350
|
|
|
327
351
|
## Citation
|
|
@@ -7,17 +7,43 @@
|
|
|
7
7
|
|
|
8
8
|
**W**idely **E**stimated **I**mmunological **R**ecognition and **D**etection of **O**utliers
|
|
9
9
|
|
|
10
|
-
A Python library for
|
|
10
|
+
A Python library that predicts, for any peptide, the probability that it occurs in proteins of each of ten species categories, and summarizes them as a pathogen-versus-mammalian foreignness score.
|
|
11
11
|
|
|
12
12
|
## Overview
|
|
13
13
|
|
|
14
|
-
WEIRDO trains a multi-layer perceptron (MLP) on k-mer presence data from SwissProt to predict organism category membership
|
|
14
|
+
WEIRDO trains a multi-layer perceptron (MLP) on k-mer presence data from SwissProt to predict organism category membership, and ships a trained model, `swissprot-categories`. Given any peptide of 8 residues or more, it outputs:
|
|
15
15
|
|
|
16
|
-
- **Category probabilities**:
|
|
17
|
-
- **
|
|
16
|
+
- **Category probabilities**: one independent sigmoid output for each of ten categories (archaea, bacteria, fungi, human, invertebrates, mammals, plants, rodents, vertebrates, viruses), the probability that the peptide occurs in SwissProt proteins of that category. The outputs are close to calibrated but only weakly informative: on protein families not seen in training the mean AUC is about 0.6.
|
|
17
|
+
- **Pathogen and self values**: the largest probability among the pathogen categories (bacteria, viruses) and among the mammalian categories (human, rodents, mammals).
|
|
18
|
+
- **Foreignness score**: `max(pathogen) / (max(pathogen) + max(self))`. The combination is a parameter: `combine="sum"` compares the summed probabilities instead (the expected number of categories in each group that contain the peptide), and `combine` also accepts your own function. Five categories (archaea, fungi, invertebrates, plants, vertebrates) are in neither default group; pass `pathogen_categories` / `self_categories` to change the groups.
|
|
19
|
+
|
|
20
|
+
[docs/category-predictor.md](docs/category-predictor.md) explains what the numbers mean, how the model was evaluated and what its limits are. A typical peptide scores about 0.81 on the foreignness scale (peptides found only in mammalian proteins: median 0.76; only in bacteria/viruses: 0.84), so compare a score with those reference distributions rather than with 0.5. Nothing here has been shown to predict T-cell immunogenicity. The bundled weights derive from UniProtKB/Swiss-Prot sequences (CC BY 4.0).
|
|
18
21
|
|
|
19
22
|
## Quick Start
|
|
20
23
|
|
|
24
|
+
```python
|
|
25
|
+
from weirdo import predict_categories
|
|
26
|
+
|
|
27
|
+
predict_categories(['SIINFEKL', 'NLVPMVATV', 'GILGFVFTL'])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
peptide archaea bacteria fungi human invertebrates mammals plants rodents vertebrates viruses pathogen_max self_max foreignness
|
|
32
|
+
SIINFEKL 0.077 0.389 0.141 0.044 0.158 0.025 0.102 0.048 0.026 0.057 0.389 0.048 0.891
|
|
33
|
+
NLVPMVATV 0.026 0.461 0.100 0.092 0.069 0.047 0.116 0.106 0.040 0.027 0.461 0.106 0.813
|
|
34
|
+
GILGFVFTL 0.045 0.435 0.118 0.083 0.076 0.041 0.112 0.093 0.038 0.031 0.435 0.093 0.823
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`predict_categories(peptides, combine="sum")` gives `pathogen_sum` and `self_sum` columns instead.
|
|
38
|
+
|
|
39
|
+
Individual outputs stay close to the base rates (the two viral epitopes get a virus probability of about 0.03); see [docs/category-predictor.md](docs/category-predictor.md).
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
weirdo score SIINFEKL NLVPMVATV GILGFVFTL
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Training your own model
|
|
46
|
+
|
|
21
47
|
```python
|
|
22
48
|
from weirdo.scorers import SwissProtReference, MLPScorer
|
|
23
49
|
|
|
@@ -37,22 +63,16 @@ peptides, labels = ref.get_training_data(
|
|
|
37
63
|
max_samples=200000 # Optional: sample for faster training
|
|
38
64
|
)
|
|
39
65
|
|
|
40
|
-
# Train the MLP
|
|
66
|
+
# Train the MLP: binary multi-label targets use one sigmoid per category and
|
|
67
|
+
# binary cross-entropy, so predict_proba returns probabilities.
|
|
41
68
|
scorer = MLPScorer(k=8, hidden_layer_sizes=(256, 128, 64))
|
|
42
69
|
scorer.train(peptides, labels, target_categories=categories, epochs=200)
|
|
43
70
|
|
|
44
71
|
# Score new peptides (any length)
|
|
45
72
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
46
|
-
print(df)
|
|
47
73
|
```
|
|
48
74
|
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
peptide human viruses bacteria mammals ... foreignness
|
|
52
|
-
MTMDKSEL 0.82 0.12 0.08 0.79 ... 0.127
|
|
53
|
-
SIINFEKL 0.15 0.73 0.21 0.18 ... 0.802
|
|
54
|
-
NLVPMVATV 0.31 0.68 0.15 0.35 ... 0.660
|
|
55
|
-
```
|
|
75
|
+
Early stopping needs validation peptides that are not near-duplicates of the training ones (overlapping 8-mers of one protein share 7 residues); pass `val_peptides` / `val_labels` built from different protein families. `scripts/train_category_predictor.py` does this and was used to train the bundled model.
|
|
56
76
|
|
|
57
77
|
## Installation
|
|
58
78
|
|
|
@@ -60,14 +80,19 @@ print(df)
|
|
|
60
80
|
pip install weirdo
|
|
61
81
|
```
|
|
62
82
|
|
|
63
|
-
|
|
83
|
+
The bundled model needs no extra data. To train your own model or use the SwissProt reference
|
|
84
|
+
scorers, build the reference data from UniProt:
|
|
64
85
|
```bash
|
|
65
|
-
weirdo data download
|
|
86
|
+
weirdo data download swissprot-sequences # ~670 MB from UniProt, builds a ~230 MB table
|
|
87
|
+
weirdo data download # also builds the 8-mer table (several GB, some minutes)
|
|
66
88
|
```
|
|
89
|
+
The files are fetched with [datacache](https://github.com/openvax/datacache) from UniProt's FTP site
|
|
90
|
+
(`WEIRDO_UNIPROT_URL` selects a mirror), checked against the sizes and MD5s UniProt lists and kept
|
|
91
|
+
in `~/.weirdo/downloads/uniprot/release-<version>/`, so they are downloaded once per UniProt release.
|
|
67
92
|
|
|
68
93
|
## Training Data
|
|
69
94
|
|
|
70
|
-
WEIRDO
|
|
95
|
+
WEIRDO builds its 8-mer data from UniProtKB/Swiss-Prot (~100M unique k-mers) with `weirdo data download`:
|
|
71
96
|
|
|
72
97
|
| Category | Description |
|
|
73
98
|
|----------|-------------|
|
|
@@ -154,7 +179,7 @@ scorer.train(
|
|
|
154
179
|
### Prediction
|
|
155
180
|
|
|
156
181
|
```python
|
|
157
|
-
# Category probabilities
|
|
182
|
+
# Category probabilities, one independent sigmoid per category
|
|
158
183
|
probs = scorer.predict_proba(['MTMDKSEL'])
|
|
159
184
|
# Shape: (1, n_categories)
|
|
160
185
|
|
|
@@ -162,9 +187,9 @@ probs = scorer.predict_proba(['MTMDKSEL'])
|
|
|
162
187
|
foreign = scorer.foreignness(
|
|
163
188
|
['MTMDKSEL'],
|
|
164
189
|
pathogen_categories=['bacteria', 'viruses'],
|
|
165
|
-
self_categories=['human', 'mammals', 'rodents']
|
|
190
|
+
self_categories=['human', 'mammals', 'rodents'],
|
|
191
|
+
combine='max', # default: max(pathogens) / (max(pathogens) + max(self)); 'sum' adds the probabilities
|
|
166
192
|
)
|
|
167
|
-
# Returns: max(pathogens) / (max(pathogens) + max(self))
|
|
168
193
|
|
|
169
194
|
# Full DataFrame output (handles variable-length peptides)
|
|
170
195
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
@@ -202,7 +227,7 @@ scorer = load_model('my-foreignness-model')
|
|
|
202
227
|
|
|
203
228
|
```bash
|
|
204
229
|
# Data management
|
|
205
|
-
weirdo data download # Download SwissProt reference
|
|
230
|
+
weirdo data download # Download SwissProt from UniProt and build the reference data
|
|
206
231
|
weirdo data list # Show data status
|
|
207
232
|
|
|
208
233
|
# Model management
|
|
@@ -214,7 +239,9 @@ weirdo models download NAME # Download pretrained weights by name
|
|
|
214
239
|
weirdo models download --url https://.../model.tar.gz --save-as my-model
|
|
215
240
|
|
|
216
241
|
# Scoring
|
|
217
|
-
weirdo score
|
|
242
|
+
weirdo score MTMDKSEL SIINFEKL # bundled swissprot-categories model
|
|
243
|
+
weirdo score --combine sum MTMDKSEL # compare summed instead of maximal probabilities
|
|
244
|
+
weirdo score --model my-model MTMDKSEL # a model you trained
|
|
218
245
|
```
|
|
219
246
|
|
|
220
247
|
## Long-Run Training on Modal
|
|
@@ -223,8 +250,8 @@ Use `scripts/train_modal_long_run.py` to run long remote training and export
|
|
|
223
250
|
weights as a `.tar.gz` archive:
|
|
224
251
|
|
|
225
252
|
```bash
|
|
226
|
-
# One-time setup: seed
|
|
227
|
-
modal volume put weirdo-data-cache
|
|
253
|
+
# One-time setup: seed the SwissProt CSV (built by `weirdo data download`) into the Modal data volume
|
|
254
|
+
modal volume put weirdo-data-cache ~/.weirdo/downloads/swissprot-8mers.csv downloads/swissprot-8mers.csv --force
|
|
228
255
|
```
|
|
229
256
|
|
|
230
257
|
```bash
|
|
@@ -265,14 +292,19 @@ new package version.
|
|
|
265
292
|
```
|
|
266
293
|
weirdo/
|
|
267
294
|
├── scorers/
|
|
268
|
-
│ ├── mlp.py
|
|
269
|
-
│ ├──
|
|
270
|
-
│ ├──
|
|
271
|
-
│ ├──
|
|
272
|
-
│
|
|
273
|
-
|
|
295
|
+
│ ├── mlp.py # MLPScorer (sigmoid heads, foreignness)
|
|
296
|
+
│ ├── peptide_features.py # The 592 peptide features (vectorised)
|
|
297
|
+
│ ├── swissprot.py # SwissProtReference (training data)
|
|
298
|
+
│ ├── config.py # Presets and configuration
|
|
299
|
+
│ ├── registry.py # Scorer registry
|
|
300
|
+
│ └── trainable.py # TrainableScorer base class
|
|
301
|
+
├── pretrained/ # Models that ship in the package (weights up to 5 MB)
|
|
302
|
+
├── uniprot.py # Download SwissProt from UniProt (datacache), build sequences
|
|
303
|
+
├── kmer_table.py # Build the SwissProt k-mer reference table
|
|
304
|
+
├── data_manager.py # ~/.weirdo reference data
|
|
305
|
+
├── model_manager.py # Save/load trained models
|
|
274
306
|
├── amino_acid_properties.py # 12 AA property dictionaries
|
|
275
|
-
└── api.py
|
|
307
|
+
└── api.py # High-level functions
|
|
276
308
|
```
|
|
277
309
|
|
|
278
310
|
## Citation
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "weirdo"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
authors = [{name="Alex Rubinsteyn", email="alex.rubinsteyn@unc.edu"}]
|
|
9
|
+
description = "Metrics of immunological foreignness for candidate T-cell epitopes"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"License :: OSI Approved :: Apache Software License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
24
|
+
]
|
|
25
|
+
readme = "README.md"
|
|
26
|
+
dynamic = ["version", "dependencies"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.dynamic]
|
|
29
|
+
version = {attr = "weirdo.__version__"}
|
|
30
|
+
dependencies = {file = ["requirements.txt"]}
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
exclude = ["test", "test.*", "examples"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
weirdo = ["logging.conf", "matrices/*", "pretrained/*/*"]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
"Homepage" = "https://github.com/pirl-unc/weirdo"
|
|
40
|
+
"Bug Tracker" = "https://github.com/pirl-unc/weirdo/issues"
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
weirdo = "weirdo.cli:run"
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = [
|
|
47
|
+
"pytest>=7.0.0",
|
|
48
|
+
"pytest-cov>=4.0.0",
|
|
49
|
+
"ruff>=0.4.0",
|
|
50
|
+
"sphinx>=5.0.0",
|
|
51
|
+
"sphinx-rtd-theme>=1.0.0",
|
|
52
|
+
"sphinx-autodoc-typehints>=1.0.0",
|
|
53
|
+
"tqdm>=4.0.0",
|
|
54
|
+
]
|
|
55
|
+
docs = [
|
|
56
|
+
"sphinx>=5.0.0",
|
|
57
|
+
"sphinx-rtd-theme>=1.0.0",
|
|
58
|
+
"sphinx-autodoc-typehints>=1.0.0",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint]
|
|
62
|
+
select = ["E", "F"]
|
|
63
|
+
ignore = ["F821", "E501", "F841", "E731", "E741"]
|
|
64
|
+
|
|
65
|
+
[tool.ruff.lint.per-file-ignores]
|
|
66
|
+
"__init__.py" = ["F401"]
|
|
67
|
+
"test/*" = ["F401"]
|