weirdo 2.1.4__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.4/weirdo.egg-info → weirdo-2.2.0}/PKG-INFO +73 -34
- {weirdo-2.1.4 → weirdo-2.2.0}/README.md +62 -30
- {weirdo-2.1.4 → weirdo-2.2.0}/pyproject.toml +8 -2
- 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.1.4 → weirdo-2.2.0}/scripts/train_modal_long_run.py +0 -8
- 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.4 → 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.4 → weirdo-2.2.0}/weirdo/__init__.py +12 -1
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/api.py +89 -1
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/cli.py +91 -24
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/data_manager.py +96 -72
- weirdo-2.2.0/weirdo/kmer_table.py +285 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/model_manager.py +75 -33
- 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.4 → weirdo-2.2.0}/weirdo/scorers/mlp.py +765 -859
- weirdo-2.2.0/weirdo/scorers/peptide_features.py +871 -0
- weirdo-2.2.0/weirdo/uniprot.py +397 -0
- {weirdo-2.1.4 → weirdo-2.2.0/weirdo.egg-info}/PKG-INFO +73 -34
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo.egg-info/SOURCES.txt +23 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo.egg-info/requires.txt +3 -2
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo.egg-info/top_level.txt +1 -0
- weirdo-2.1.4/MANIFEST.in +0 -1
- weirdo-2.1.4/requirements.txt +0 -4
- weirdo-2.1.4/test/test_data_manager.py +0 -39
- weirdo-2.1.4/test/test_model_downloads.py +0 -96
- {weirdo-2.1.4 → weirdo-2.2.0}/LICENSE +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/setup.cfg +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_amino_acids.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_blosum.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_hamming.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_logic_consistency.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_mlp_scorers.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_ngram.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_pmbec.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_scorers.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/test/test_swissprot_reference.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/amino_acid.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/amino_acid_alphabet.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/amino_acid_properties.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/blosum.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/chou_fasman.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/common.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/distances.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/BLOSUM30 +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/BLOSUM50 +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/BLOSUM62 +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/__init__.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/amino_acid_properties.txt +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/helix_vs_coil.txt +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/helix_vs_strand.txt +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/pmbec.mat +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/matrices/strand_vs_coil.txt +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/peptide_vectorizer.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/pmbec.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/reduced_alphabet.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/residue_contact_energies.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/__init__.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/base.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/config.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/reference.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/registry.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/similarity.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/swissprot.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/scorers/trainable.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo/static_data.py +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo.egg-info/dependency_links.txt +0 -0
- {weirdo-2.1.4 → weirdo-2.2.0}/weirdo.egg-info/entry_points.txt +0 -0
weirdo-2.2.0/MANIFEST.in
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/pirl-unc/weirdo
|
|
@@ -11,13 +11,20 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
20
|
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
15
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.10
|
|
16
22
|
Description-Content-Type: text/markdown
|
|
17
23
|
License-File: LICENSE
|
|
18
24
|
Requires-Dist: numpy<3.0.0,>=2.0.0
|
|
19
|
-
Requires-Dist: pandas>=
|
|
20
|
-
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
|
|
21
28
|
Provides-Extra: dev
|
|
22
29
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
23
30
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -41,17 +48,43 @@ Dynamic: license-file
|
|
|
41
48
|
|
|
42
49
|
**W**idely **E**stimated **I**mmunological **R**ecognition and **D**etection of **O**utliers
|
|
43
50
|
|
|
44
|
-
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.
|
|
45
52
|
|
|
46
53
|
## Overview
|
|
47
54
|
|
|
48
|
-
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:
|
|
49
56
|
|
|
50
|
-
- **Category probabilities**:
|
|
51
|
-
- **
|
|
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).
|
|
52
62
|
|
|
53
63
|
## Quick Start
|
|
54
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
|
+
|
|
55
88
|
```python
|
|
56
89
|
from weirdo.scorers import SwissProtReference, MLPScorer
|
|
57
90
|
|
|
@@ -71,22 +104,16 @@ peptides, labels = ref.get_training_data(
|
|
|
71
104
|
max_samples=200000 # Optional: sample for faster training
|
|
72
105
|
)
|
|
73
106
|
|
|
74
|
-
# 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.
|
|
75
109
|
scorer = MLPScorer(k=8, hidden_layer_sizes=(256, 128, 64))
|
|
76
110
|
scorer.train(peptides, labels, target_categories=categories, epochs=200)
|
|
77
111
|
|
|
78
112
|
# Score new peptides (any length)
|
|
79
113
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
80
|
-
print(df)
|
|
81
114
|
```
|
|
82
115
|
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
peptide human viruses bacteria mammals ... foreignness
|
|
86
|
-
MTMDKSEL 0.82 0.12 0.08 0.79 ... 0.127
|
|
87
|
-
SIINFEKL 0.15 0.73 0.21 0.18 ... 0.802
|
|
88
|
-
NLVPMVATV 0.31 0.68 0.15 0.35 ... 0.660
|
|
89
|
-
```
|
|
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.
|
|
90
117
|
|
|
91
118
|
## Installation
|
|
92
119
|
|
|
@@ -94,14 +121,19 @@ print(df)
|
|
|
94
121
|
pip install weirdo
|
|
95
122
|
```
|
|
96
123
|
|
|
97
|
-
|
|
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:
|
|
98
126
|
```bash
|
|
99
|
-
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)
|
|
100
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.
|
|
101
133
|
|
|
102
134
|
## Training Data
|
|
103
135
|
|
|
104
|
-
WEIRDO
|
|
136
|
+
WEIRDO builds its 8-mer data from UniProtKB/Swiss-Prot (~100M unique k-mers) with `weirdo data download`:
|
|
105
137
|
|
|
106
138
|
| Category | Description |
|
|
107
139
|
|----------|-------------|
|
|
@@ -188,7 +220,7 @@ scorer.train(
|
|
|
188
220
|
### Prediction
|
|
189
221
|
|
|
190
222
|
```python
|
|
191
|
-
# Category probabilities
|
|
223
|
+
# Category probabilities, one independent sigmoid per category
|
|
192
224
|
probs = scorer.predict_proba(['MTMDKSEL'])
|
|
193
225
|
# Shape: (1, n_categories)
|
|
194
226
|
|
|
@@ -196,9 +228,9 @@ probs = scorer.predict_proba(['MTMDKSEL'])
|
|
|
196
228
|
foreign = scorer.foreignness(
|
|
197
229
|
['MTMDKSEL'],
|
|
198
230
|
pathogen_categories=['bacteria', 'viruses'],
|
|
199
|
-
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
|
|
200
233
|
)
|
|
201
|
-
# Returns: max(pathogens) / (max(pathogens) + max(self))
|
|
202
234
|
|
|
203
235
|
# Full DataFrame output (handles variable-length peptides)
|
|
204
236
|
df = scorer.predict_dataframe(['MTMDKSEL', 'SIINFEKL', 'NLVPMVATV'])
|
|
@@ -236,7 +268,7 @@ scorer = load_model('my-foreignness-model')
|
|
|
236
268
|
|
|
237
269
|
```bash
|
|
238
270
|
# Data management
|
|
239
|
-
weirdo data download # Download SwissProt reference
|
|
271
|
+
weirdo data download # Download SwissProt from UniProt and build the reference data
|
|
240
272
|
weirdo data list # Show data status
|
|
241
273
|
|
|
242
274
|
# Model management
|
|
@@ -248,7 +280,9 @@ weirdo models download NAME # Download pretrained weights by name
|
|
|
248
280
|
weirdo models download --url https://.../model.tar.gz --save-as my-model
|
|
249
281
|
|
|
250
282
|
# Scoring
|
|
251
|
-
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
|
|
252
286
|
```
|
|
253
287
|
|
|
254
288
|
## Long-Run Training on Modal
|
|
@@ -257,8 +291,8 @@ Use `scripts/train_modal_long_run.py` to run long remote training and export
|
|
|
257
291
|
weights as a `.tar.gz` archive:
|
|
258
292
|
|
|
259
293
|
```bash
|
|
260
|
-
# One-time setup: seed
|
|
261
|
-
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
|
|
262
296
|
```
|
|
263
297
|
|
|
264
298
|
```bash
|
|
@@ -299,14 +333,19 @@ new package version.
|
|
|
299
333
|
```
|
|
300
334
|
weirdo/
|
|
301
335
|
├── scorers/
|
|
302
|
-
│ ├── mlp.py
|
|
303
|
-
│ ├──
|
|
304
|
-
│ ├──
|
|
305
|
-
│ ├──
|
|
306
|
-
│
|
|
307
|
-
|
|
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
|
|
308
347
|
├── amino_acid_properties.py # 12 AA property dictionaries
|
|
309
|
-
└── api.py
|
|
348
|
+
└── api.py # High-level functions
|
|
310
349
|
```
|
|
311
350
|
|
|
312
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
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "weirdo"
|
|
7
|
-
requires-python = ">=3.
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
8
|
authors = [{name="Alex Rubinsteyn", email="alex.rubinsteyn@unc.edu"}]
|
|
9
9
|
description = "Metrics of immunological foreignness for candidate T-cell epitopes"
|
|
10
10
|
classifiers = [
|
|
@@ -14,6 +14,12 @@ classifiers = [
|
|
|
14
14
|
"Intended Audience :: Science/Research",
|
|
15
15
|
"License :: OSI Approved :: Apache Software License",
|
|
16
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",
|
|
17
23
|
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
18
24
|
]
|
|
19
25
|
readme = "README.md"
|
|
@@ -27,7 +33,7 @@ dependencies = {file = ["requirements.txt"]}
|
|
|
27
33
|
exclude = ["test", "test.*", "examples"]
|
|
28
34
|
|
|
29
35
|
[tool.setuptools.package-data]
|
|
30
|
-
weirdo = ["logging.conf", "matrices/*"]
|
|
36
|
+
weirdo = ["logging.conf", "matrices/*", "pretrained/*/*"]
|
|
31
37
|
|
|
32
38
|
[project.urls]
|
|
33
39
|
"Homepage" = "https://github.com/pirl-unc/weirdo"
|