pepdata 1.2.4__tar.gz → 1.3.5__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.
- pepdata-1.3.5/PKG-INFO +106 -0
- pepdata-1.3.5/README.md +79 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/amino_acid.py +1 -1
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/amino_acid_alphabet.py +8 -6
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/alleles.py +4 -7
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/mhc.py +8 -6
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/tcell.py +7 -3
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/peptide_vectorizer.py +34 -3
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/pmbec.py +1 -1
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/version.py +1 -1
- pepdata-1.3.5/pepdata.egg-info/PKG-INFO +106 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata.egg-info/SOURCES.txt +1 -4
- pepdata-1.3.5/pepdata.egg-info/requires.txt +4 -0
- pepdata-1.3.5/pepdata.egg-info/top_level.txt +1 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pyproject.toml +4 -1
- {pepdata-1.2.4 → pepdata-1.3.5}/requirements.txt +1 -5
- pepdata-1.3.5/tests/test_amino_acids.py +55 -0
- pepdata-1.3.5/tests/test_blosum.py +83 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/tests/test_iedb_alleles.py +20 -1
- pepdata-1.3.5/tests/test_iedb_cache_lifecycle.py +57 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/tests/test_iedb_mhc.py +19 -0
- pepdata-1.3.5/tests/test_ngram.py +119 -0
- pepdata-1.3.5/tests/test_pmbec.py +31 -0
- pepdata-1.2.4/PKG-INFO +0 -86
- pepdata-1.2.4/README.md +0 -55
- pepdata-1.2.4/pepdata/iedb/memoize.py +0 -47
- pepdata-1.2.4/pepdata.egg-info/PKG-INFO +0 -86
- pepdata-1.2.4/pepdata.egg-info/requires.txt +0 -8
- pepdata-1.2.4/pepdata.egg-info/top_level.txt +0 -5
- pepdata-1.2.4/scripts/check_docs_examples.py +0 -33
- pepdata-1.2.4/scripts/check_docs_links.py +0 -54
- pepdata-1.2.4/tests/conftest.py +0 -23
- pepdata-1.2.4/tests/test_amino_acids.py +0 -25
- pepdata-1.2.4/tests/test_blosum.py +0 -17
- pepdata-1.2.4/tests/test_ngram.py +0 -61
- pepdata-1.2.4/tests/test_pmbec.py +0 -7
- {pepdata-1.2.4 → pepdata-1.3.5}/LICENSE.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/MANIFEST.in +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/__init__.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/amino_acid_properties.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/blosum.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/chou_fasman.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/common.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/__init__.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/columns.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/iedb/common.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/BLOSUM30 +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/BLOSUM50 +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/BLOSUM62 +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/__init__.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/amino_acid_properties.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/helix_vs_coil.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/helix_vs_strand.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/pmbec.mat +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/matrices/strand_vs_coil.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/reduced_alphabet.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/residue_contact_energies.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata/static_data.py +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/pepdata.egg-info/dependency_links.txt +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/setup.cfg +0 -0
- {pepdata-1.2.4 → pepdata-1.3.5}/tests/test_iedb_tcell.py +0 -0
pepdata-1.3.5/PKG-INFO
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pepdata
|
|
3
|
+
Version: 1.3.5
|
|
4
|
+
Summary: Immunological peptide datasets and amino acid properties
|
|
5
|
+
Author-email: Alex Rubinsteyn <alex.rubinsteyn@mssm.edu>
|
|
6
|
+
Project-URL: Homepage, https://github.com/openvax/pepdata
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/openvax/pepdata/issues
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE.txt
|
|
22
|
+
Requires-Dist: numpy<3.0.0,>=2.0.0
|
|
23
|
+
Requires-Dist: pandas<4,>=3
|
|
24
|
+
Requires-Dist: scikit-learn>=0.14.1
|
|
25
|
+
Requires-Dist: datacache>=0.4.4
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
[](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
|
|
29
|
+
[](https://openvax.github.io/pepdata/)
|
|
30
|
+
[](https://pypi.org/project/pepdata/)
|
|
31
|
+
|
|
32
|
+
# pepdata
|
|
33
|
+
|
|
34
|
+
pepdata ships amino-acid property tables and pairwise residue matrices
|
|
35
|
+
(BLOSUM, PMBEC, contact energies), turns peptide sequences into n-gram feature
|
|
36
|
+
vectors, and loads MHC-binding and T-cell assay tables from the
|
|
37
|
+
[IEDB](https://www.iedb.org/). It is the [OpenVax](https://github.com/openvax)
|
|
38
|
+
library for peptide-level reference data. It does not predict MHC binding; for
|
|
39
|
+
that, see [mhctools](https://github.com/openvax/mhctools) and
|
|
40
|
+
[mhcflurry](https://github.com/openvax/mhcflurry).
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
python -m pip install pepdata
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
pepdata needs Python 3.11 or later. Property tables and matrices ship with the
|
|
49
|
+
package and work offline. The IEDB tables are downloaded on first use and
|
|
50
|
+
cached by [datacache](https://github.com/openvax/datacache).
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from pepdata.amino_acid_properties import hydropathy
|
|
56
|
+
|
|
57
|
+
peptide = "ACD"
|
|
58
|
+
print([hydropathy[residue] for residue in peptide])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
[1.8, 2.5, -3.5]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Each property table is a dictionary from single-letter residue to value. Use
|
|
66
|
+
uppercase canonical residue letters; a missing letter raises `KeyError`.
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
The [documentation](https://openvax.github.io/pepdata/) has two guides and an
|
|
71
|
+
API reference:
|
|
72
|
+
|
|
73
|
+
1. [Residue and pairwise tables](https://openvax.github.io/pepdata/guides/properties/):
|
|
74
|
+
property dictionaries, BLOSUM and other matrices, alphabets.
|
|
75
|
+
2. [Peptide features and IEDB tables](https://openvax.github.io/pepdata/guides/datasets/):
|
|
76
|
+
n-gram vectors and the MHC-binding and T-cell assay loaders.
|
|
77
|
+
3. [API reference](https://openvax.github.io/pepdata/reference/).
|
|
78
|
+
|
|
79
|
+
| Task | Module or object |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| Single-residue properties | `pepdata.amino_acid_properties` |
|
|
82
|
+
| BLOSUM substitution matrices | `pepdata.blosum` |
|
|
83
|
+
| PMBEC and contact tables | `pepdata.pmbec`, `pepdata.residue_contact_energies` |
|
|
84
|
+
| Residue alphabets | `pepdata.amino_acid_alphabet`, `pepdata.reduced_alphabet` |
|
|
85
|
+
| N-gram features | `pepdata.PeptideVectorizer` |
|
|
86
|
+
| MHC-binding assay tables | `pepdata.iedb.mhc` |
|
|
87
|
+
| T-cell assay tables | `pepdata.iedb.tcell` |
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
python -m pip install -e . pytest pytest-cov ruff
|
|
93
|
+
./lint.sh # ruff check
|
|
94
|
+
./test.sh # pytest with coverage
|
|
95
|
+
python -m pip install -r requirements-docs.txt
|
|
96
|
+
./docs.sh # mkdocs build --strict, then a rendered-link check
|
|
97
|
+
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The development installer uses `python` from the active environment. Set
|
|
101
|
+
`PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
|
|
102
|
+
additional arguments are passed to pip.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
|
pepdata-1.3.5/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
|
|
2
|
+
[](https://openvax.github.io/pepdata/)
|
|
3
|
+
[](https://pypi.org/project/pepdata/)
|
|
4
|
+
|
|
5
|
+
# pepdata
|
|
6
|
+
|
|
7
|
+
pepdata ships amino-acid property tables and pairwise residue matrices
|
|
8
|
+
(BLOSUM, PMBEC, contact energies), turns peptide sequences into n-gram feature
|
|
9
|
+
vectors, and loads MHC-binding and T-cell assay tables from the
|
|
10
|
+
[IEDB](https://www.iedb.org/). It is the [OpenVax](https://github.com/openvax)
|
|
11
|
+
library for peptide-level reference data. It does not predict MHC binding; for
|
|
12
|
+
that, see [mhctools](https://github.com/openvax/mhctools) and
|
|
13
|
+
[mhcflurry](https://github.com/openvax/mhcflurry).
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python -m pip install pepdata
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
pepdata needs Python 3.11 or later. Property tables and matrices ship with the
|
|
22
|
+
package and work offline. The IEDB tables are downloaded on first use and
|
|
23
|
+
cached by [datacache](https://github.com/openvax/datacache).
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from pepdata.amino_acid_properties import hydropathy
|
|
29
|
+
|
|
30
|
+
peptide = "ACD"
|
|
31
|
+
print([hydropathy[residue] for residue in peptide])
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
[1.8, 2.5, -3.5]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Each property table is a dictionary from single-letter residue to value. Use
|
|
39
|
+
uppercase canonical residue letters; a missing letter raises `KeyError`.
|
|
40
|
+
|
|
41
|
+
## Documentation
|
|
42
|
+
|
|
43
|
+
The [documentation](https://openvax.github.io/pepdata/) has two guides and an
|
|
44
|
+
API reference:
|
|
45
|
+
|
|
46
|
+
1. [Residue and pairwise tables](https://openvax.github.io/pepdata/guides/properties/):
|
|
47
|
+
property dictionaries, BLOSUM and other matrices, alphabets.
|
|
48
|
+
2. [Peptide features and IEDB tables](https://openvax.github.io/pepdata/guides/datasets/):
|
|
49
|
+
n-gram vectors and the MHC-binding and T-cell assay loaders.
|
|
50
|
+
3. [API reference](https://openvax.github.io/pepdata/reference/).
|
|
51
|
+
|
|
52
|
+
| Task | Module or object |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| Single-residue properties | `pepdata.amino_acid_properties` |
|
|
55
|
+
| BLOSUM substitution matrices | `pepdata.blosum` |
|
|
56
|
+
| PMBEC and contact tables | `pepdata.pmbec`, `pepdata.residue_contact_energies` |
|
|
57
|
+
| Residue alphabets | `pepdata.amino_acid_alphabet`, `pepdata.reduced_alphabet` |
|
|
58
|
+
| N-gram features | `pepdata.PeptideVectorizer` |
|
|
59
|
+
| MHC-binding assay tables | `pepdata.iedb.mhc` |
|
|
60
|
+
| T-cell assay tables | `pepdata.iedb.tcell` |
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
python -m pip install -e . pytest pytest-cov ruff
|
|
66
|
+
./lint.sh # ruff check
|
|
67
|
+
./test.sh # pytest with coverage
|
|
68
|
+
python -m pip install -r requirements-docs.txt
|
|
69
|
+
./docs.sh # mkdocs build --strict, then a rendered-link check
|
|
70
|
+
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The development installer uses `python` from the active environment. Set
|
|
74
|
+
`PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
|
|
75
|
+
additional arguments are passed to pip.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
|
|
@@ -25,7 +25,7 @@ class AminoAcid(object):
|
|
|
25
25
|
return (
|
|
26
26
|
("AminoAcid(full_name='%s', short_name='%s', letter='%s', "
|
|
27
27
|
"contains=%s)") % (
|
|
28
|
-
self.
|
|
28
|
+
self.full_name, self.short_name, self.letter, self.contains))
|
|
29
29
|
|
|
30
30
|
def __repr__(self):
|
|
31
31
|
return str(self)
|
|
@@ -106,9 +106,9 @@ amino_acid_letter_indices = {
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
amino_acid_letter_pairs = [
|
|
109
|
-
|
|
110
|
-
for y in
|
|
111
|
-
for x in
|
|
109
|
+
x + y
|
|
110
|
+
for y in extended_amino_acid_letters
|
|
111
|
+
for x in extended_amino_acid_letters
|
|
112
112
|
]
|
|
113
113
|
|
|
114
114
|
|
|
@@ -128,7 +128,8 @@ def index_to_short_name(idx):
|
|
|
128
128
|
return extended_amino_acids[idx].short_name
|
|
129
129
|
|
|
130
130
|
def index_to_letter(idx):
|
|
131
|
-
|
|
131
|
+
"""Return the one-letter code at an index in the extended alphabet."""
|
|
132
|
+
return extended_amino_acids[idx].letter
|
|
132
133
|
|
|
133
134
|
def letter_to_index(x):
|
|
134
135
|
"""
|
|
@@ -144,10 +145,11 @@ def letter_to_short_name(x):
|
|
|
144
145
|
return index_to_short_name(letter_to_index(x))
|
|
145
146
|
|
|
146
147
|
def peptide_to_short_amino_acid_names(xs):
|
|
147
|
-
|
|
148
|
+
"""Return three-letter names in sequence order; unknown letters raise KeyError."""
|
|
149
|
+
return [letter_to_short_name(x) for x in xs]
|
|
148
150
|
|
|
149
151
|
def dict_to_amino_acid_matrix(d, alphabet=canonical_amino_acids):
|
|
150
|
-
n_aa = len(
|
|
152
|
+
n_aa = len(alphabet)
|
|
151
153
|
result_matrix = np.zeros((n_aa, n_aa), dtype="float32")
|
|
152
154
|
for i, aa_row in enumerate(alphabet):
|
|
153
155
|
d_row = d[aa_row.letter]
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
# limitations under the License.
|
|
12
12
|
|
|
13
13
|
from collections import namedtuple
|
|
14
|
-
import
|
|
15
|
-
import xml
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import xml.etree.ElementTree
|
|
16
16
|
|
|
17
17
|
from .common import cache
|
|
18
|
-
from .memoize import memoize
|
|
19
18
|
|
|
20
19
|
ALLELE_XML_FILENAME = "MhcAlleleNames.xml"
|
|
21
20
|
ALLELE_XML_URL = "http://www.iedb.org/doc/MhcAlleleNameList.zip"
|
|
@@ -30,12 +29,12 @@ def local_path(force_download=False):
|
|
|
30
29
|
force=force_download)
|
|
31
30
|
|
|
32
31
|
def delete():
|
|
33
|
-
"""
|
|
32
|
+
"""Remove the local XML export; missing files are ignored."""
|
|
34
33
|
path = cache.local_path(
|
|
35
34
|
filename=ALLELE_XML_FILENAME,
|
|
36
35
|
url=ALLELE_XML_URL,
|
|
37
36
|
decompress=ALLELE_XML_DECOMPRESS)
|
|
38
|
-
|
|
37
|
+
Path(path).unlink(missing_ok=True)
|
|
39
38
|
|
|
40
39
|
Allele = namedtuple("Allele", [
|
|
41
40
|
"name",
|
|
@@ -45,7 +44,6 @@ Allele = namedtuple("Allele", [
|
|
|
45
44
|
"synonyms"
|
|
46
45
|
])
|
|
47
46
|
|
|
48
|
-
@memoize
|
|
49
47
|
def load_alleles():
|
|
50
48
|
"""Parses the IEDB MhcAlleleName XML file and returns a list of Allele
|
|
51
49
|
namedtuple objects containing information about that each allele's HLA
|
|
@@ -89,7 +87,6 @@ def load_alleles():
|
|
|
89
87
|
result.append(allele_object)
|
|
90
88
|
return result
|
|
91
89
|
|
|
92
|
-
@memoize
|
|
93
90
|
def load_alleles_dict():
|
|
94
91
|
"""Create a dictionary mapping each unique allele name to a namedtuple
|
|
95
92
|
containing information about that alleles class, locus, species, &c.
|
|
@@ -14,10 +14,10 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import logging
|
|
16
16
|
import os
|
|
17
|
+
from pathlib import Path
|
|
17
18
|
|
|
18
19
|
import pandas as pd
|
|
19
20
|
|
|
20
|
-
from .memoize import memoize
|
|
21
21
|
from .common import bad_amino_acids, cache
|
|
22
22
|
|
|
23
23
|
|
|
@@ -42,13 +42,17 @@ def local_path(auto_download=True):
|
|
|
42
42
|
return download()
|
|
43
43
|
raise ValueError(
|
|
44
44
|
("MHC data file %s does not exist locally,"
|
|
45
|
-
" call pepdata.mhc.download() to get a copy from IEDB") % path)
|
|
45
|
+
" call pepdata.iedb.mhc.download() to get a copy from IEDB") % path)
|
|
46
46
|
return path
|
|
47
47
|
|
|
48
48
|
def delete():
|
|
49
|
-
|
|
49
|
+
"""Remove the local assay export without downloading; missing files are ignored."""
|
|
50
|
+
path = cache.local_path(
|
|
51
|
+
filename=MHC_LOCAL_FILENAME,
|
|
52
|
+
url=MHC_URL,
|
|
53
|
+
decompress=MHC_DECOMPRESS)
|
|
54
|
+
Path(path).unlink(missing_ok=True)
|
|
50
55
|
|
|
51
|
-
@memoize
|
|
52
56
|
def load_dataframe(
|
|
53
57
|
mhc_class : int | None = None, # 1, 2, or None for neither
|
|
54
58
|
hla : str | None = None,
|
|
@@ -108,8 +112,6 @@ def load_dataframe(
|
|
|
108
112
|
# To deal with this, drop any columns which are all NaN
|
|
109
113
|
df = df.dropna(axis=1, how="all")
|
|
110
114
|
|
|
111
|
-
print(df.head())
|
|
112
|
-
|
|
113
115
|
n = len(df)
|
|
114
116
|
|
|
115
117
|
mhc_group_key = "MHC Restriction"
|
|
@@ -15,13 +15,13 @@ from __future__ import annotations
|
|
|
15
15
|
|
|
16
16
|
import logging
|
|
17
17
|
import os
|
|
18
|
+
from pathlib import Path
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
import pandas as pd
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
from .alleles import load_alleles_dict
|
|
24
|
-
from .memoize import memoize
|
|
25
25
|
from .common import bad_amino_acids, cache
|
|
26
26
|
from .columns import (
|
|
27
27
|
get_assay_method,
|
|
@@ -57,9 +57,13 @@ def local_path(auto_download=True):
|
|
|
57
57
|
return path
|
|
58
58
|
|
|
59
59
|
def delete():
|
|
60
|
-
|
|
60
|
+
"""Remove the local assay export without downloading; missing files are ignored."""
|
|
61
|
+
path = cache.local_path(
|
|
62
|
+
filename=TCELL_COMPACT_FILENAME,
|
|
63
|
+
url=TCELL_COMPACT_URL,
|
|
64
|
+
decompress=TCELL_COMPACT_DECOMPRESS)
|
|
65
|
+
Path(path).unlink(missing_ok=True)
|
|
61
66
|
|
|
62
|
-
@memoize
|
|
63
67
|
def load_dataframe(
|
|
64
68
|
mhc_class : str | None = None, # 1, 2, or None for neither
|
|
65
69
|
hla : str | None = None,
|
|
@@ -55,16 +55,31 @@ class PeptideVectorizer(object):
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
def fit_transform(self, amino_acid_strings):
|
|
58
|
+
"""
|
|
59
|
+
Learn the n-gram vocabulary of the given sequences and vectorize them.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
amino_acid_strings : list of str
|
|
64
|
+
Peptide or protein sequences.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
numpy.ndarray
|
|
69
|
+
Array of shape (len(amino_acid_strings), number of distinct
|
|
70
|
+
n-grams) with n-gram counts, or per-row frequencies (each row
|
|
71
|
+
divided by its total) when normalize_row is True.
|
|
72
|
+
"""
|
|
58
73
|
self.count_vectorizer = \
|
|
59
74
|
make_count_vectorizer(self.reduced_alphabet, self.max_ngram)
|
|
60
75
|
|
|
61
76
|
if self.training_already_reduced:
|
|
62
77
|
c = make_count_vectorizer(None, self.max_ngram)
|
|
63
|
-
X = c.fit_transform(amino_acid_strings).
|
|
78
|
+
X = c.fit_transform(amino_acid_strings).toarray()
|
|
64
79
|
self.count_vectorizer.vocabulary_ = c.vocabulary_
|
|
65
80
|
else:
|
|
66
81
|
c = self.count_vectorizer
|
|
67
|
-
X = c.fit_transform(amino_acid_strings).
|
|
82
|
+
X = c.fit_transform(amino_acid_strings).toarray()
|
|
68
83
|
|
|
69
84
|
if self.normalize_row:
|
|
70
85
|
X = normalize(X, norm='l1')
|
|
@@ -74,8 +89,24 @@ class PeptideVectorizer(object):
|
|
|
74
89
|
self.fit_transform(amino_acid_strings)
|
|
75
90
|
|
|
76
91
|
def transform(self, amino_acid_strings):
|
|
92
|
+
"""
|
|
93
|
+
Vectorize sequences with the vocabulary learned by fit.
|
|
94
|
+
|
|
95
|
+
n-grams that weren't seen during fitting are not counted.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
amino_acid_strings : list of str
|
|
100
|
+
Peptide or protein sequences.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
numpy.ndarray
|
|
105
|
+
Array of shape (len(amino_acid_strings), size of the fitted
|
|
106
|
+
vocabulary), normalized per row as in fit_transform.
|
|
107
|
+
"""
|
|
77
108
|
assert self.count_vectorizer, "Must call 'fit' before 'transform'"
|
|
78
|
-
X = self.count_vectorizer.transform(amino_acid_strings).
|
|
109
|
+
X = self.count_vectorizer.transform(amino_acid_strings).toarray()
|
|
79
110
|
if self.normalize_row:
|
|
80
111
|
X = normalize(X, norm='l1')
|
|
81
112
|
return X
|
|
@@ -83,5 +83,5 @@ def read_pmbec_coefficients(
|
|
|
83
83
|
return d
|
|
84
84
|
|
|
85
85
|
# dictionary of PMBEC coefficient accessed like pmbec_dict["V"]["R"]
|
|
86
|
-
pmbec_dict = read_pmbec_coefficients(key_type="row")
|
|
86
|
+
pmbec_dict = read_pmbec_coefficients(key_type="row", verbose=False)
|
|
87
87
|
pmbec_matrix = dict_to_amino_acid_matrix(pmbec_dict)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pepdata
|
|
3
|
+
Version: 1.3.5
|
|
4
|
+
Summary: Immunological peptide datasets and amino acid properties
|
|
5
|
+
Author-email: Alex Rubinsteyn <alex.rubinsteyn@mssm.edu>
|
|
6
|
+
Project-URL: Homepage, https://github.com/openvax/pepdata
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/openvax/pepdata/issues
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE.txt
|
|
22
|
+
Requires-Dist: numpy<3.0.0,>=2.0.0
|
|
23
|
+
Requires-Dist: pandas<4,>=3
|
|
24
|
+
Requires-Dist: scikit-learn>=0.14.1
|
|
25
|
+
Requires-Dist: datacache>=0.4.4
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
[](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
|
|
29
|
+
[](https://openvax.github.io/pepdata/)
|
|
30
|
+
[](https://pypi.org/project/pepdata/)
|
|
31
|
+
|
|
32
|
+
# pepdata
|
|
33
|
+
|
|
34
|
+
pepdata ships amino-acid property tables and pairwise residue matrices
|
|
35
|
+
(BLOSUM, PMBEC, contact energies), turns peptide sequences into n-gram feature
|
|
36
|
+
vectors, and loads MHC-binding and T-cell assay tables from the
|
|
37
|
+
[IEDB](https://www.iedb.org/). It is the [OpenVax](https://github.com/openvax)
|
|
38
|
+
library for peptide-level reference data. It does not predict MHC binding; for
|
|
39
|
+
that, see [mhctools](https://github.com/openvax/mhctools) and
|
|
40
|
+
[mhcflurry](https://github.com/openvax/mhcflurry).
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
python -m pip install pepdata
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
pepdata needs Python 3.11 or later. Property tables and matrices ship with the
|
|
49
|
+
package and work offline. The IEDB tables are downloaded on first use and
|
|
50
|
+
cached by [datacache](https://github.com/openvax/datacache).
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from pepdata.amino_acid_properties import hydropathy
|
|
56
|
+
|
|
57
|
+
peptide = "ACD"
|
|
58
|
+
print([hydropathy[residue] for residue in peptide])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
[1.8, 2.5, -3.5]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Each property table is a dictionary from single-letter residue to value. Use
|
|
66
|
+
uppercase canonical residue letters; a missing letter raises `KeyError`.
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
The [documentation](https://openvax.github.io/pepdata/) has two guides and an
|
|
71
|
+
API reference:
|
|
72
|
+
|
|
73
|
+
1. [Residue and pairwise tables](https://openvax.github.io/pepdata/guides/properties/):
|
|
74
|
+
property dictionaries, BLOSUM and other matrices, alphabets.
|
|
75
|
+
2. [Peptide features and IEDB tables](https://openvax.github.io/pepdata/guides/datasets/):
|
|
76
|
+
n-gram vectors and the MHC-binding and T-cell assay loaders.
|
|
77
|
+
3. [API reference](https://openvax.github.io/pepdata/reference/).
|
|
78
|
+
|
|
79
|
+
| Task | Module or object |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| Single-residue properties | `pepdata.amino_acid_properties` |
|
|
82
|
+
| BLOSUM substitution matrices | `pepdata.blosum` |
|
|
83
|
+
| PMBEC and contact tables | `pepdata.pmbec`, `pepdata.residue_contact_energies` |
|
|
84
|
+
| Residue alphabets | `pepdata.amino_acid_alphabet`, `pepdata.reduced_alphabet` |
|
|
85
|
+
| N-gram features | `pepdata.PeptideVectorizer` |
|
|
86
|
+
| MHC-binding assay tables | `pepdata.iedb.mhc` |
|
|
87
|
+
| T-cell assay tables | `pepdata.iedb.tcell` |
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
python -m pip install -e . pytest pytest-cov ruff
|
|
93
|
+
./lint.sh # ruff check
|
|
94
|
+
./test.sh # pytest with coverage
|
|
95
|
+
python -m pip install -r requirements-docs.txt
|
|
96
|
+
./docs.sh # mkdocs build --strict, then a rendered-link check
|
|
97
|
+
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The development installer uses `python` from the active environment. Set
|
|
101
|
+
`PYTHON=/path/to/python ./develop.sh` to select an interpreter explicitly;
|
|
102
|
+
additional arguments are passed to pip.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
|
|
@@ -25,7 +25,6 @@ pepdata/iedb/__init__.py
|
|
|
25
25
|
pepdata/iedb/alleles.py
|
|
26
26
|
pepdata/iedb/columns.py
|
|
27
27
|
pepdata/iedb/common.py
|
|
28
|
-
pepdata/iedb/memoize.py
|
|
29
28
|
pepdata/iedb/mhc.py
|
|
30
29
|
pepdata/iedb/tcell.py
|
|
31
30
|
pepdata/matrices/BLOSUM30
|
|
@@ -37,12 +36,10 @@ pepdata/matrices/helix_vs_coil.txt
|
|
|
37
36
|
pepdata/matrices/helix_vs_strand.txt
|
|
38
37
|
pepdata/matrices/pmbec.mat
|
|
39
38
|
pepdata/matrices/strand_vs_coil.txt
|
|
40
|
-
scripts/check_docs_examples.py
|
|
41
|
-
scripts/check_docs_links.py
|
|
42
|
-
tests/conftest.py
|
|
43
39
|
tests/test_amino_acids.py
|
|
44
40
|
tests/test_blosum.py
|
|
45
41
|
tests/test_iedb_alleles.py
|
|
42
|
+
tests/test_iedb_cache_lifecycle.py
|
|
46
43
|
tests/test_iedb_mhc.py
|
|
47
44
|
tests/test_iedb_tcell.py
|
|
48
45
|
tests/test_ngram.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pepdata
|
|
@@ -28,12 +28,15 @@ version = {attr = "pepdata.version.__version__"}
|
|
|
28
28
|
dependencies = {file = ["requirements.txt"]}
|
|
29
29
|
|
|
30
30
|
[tool.setuptools.packages.find]
|
|
31
|
-
|
|
31
|
+
include = ["pepdata", "pepdata.*"]
|
|
32
32
|
|
|
33
33
|
[project.urls]
|
|
34
34
|
"Homepage" = "https://github.com/openvax/pepdata"
|
|
35
35
|
"Bug Tracker" = "https://github.com/openvax/pepdata/issues"
|
|
36
36
|
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
target-version = "py311"
|
|
39
|
+
|
|
37
40
|
[tool.ruff.lint]
|
|
38
41
|
select = ["E", "F"]
|
|
39
42
|
ignore = ["F821", "E501", "F841", "E731", "E741", "E722", "E721"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from pepdata.amino_acid_alphabet import (
|
|
2
|
+
canonical_amino_acids,
|
|
3
|
+
canonical_amino_acid_letters,
|
|
4
|
+
extended_amino_acids,
|
|
5
|
+
extended_amino_acid_letters,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
def test_canonical_amino_acids():
|
|
9
|
+
assert len(canonical_amino_acids) == 20
|
|
10
|
+
|
|
11
|
+
def test_canonical_amino_acids_letters():
|
|
12
|
+
assert len(canonical_amino_acid_letters) == 20
|
|
13
|
+
assert "X" not in canonical_amino_acid_letters
|
|
14
|
+
expected_letters = [aa.letter for aa in canonical_amino_acids]
|
|
15
|
+
assert expected_letters == canonical_amino_acid_letters
|
|
16
|
+
|
|
17
|
+
def test_extended_amino_acids():
|
|
18
|
+
assert len(extended_amino_acids) > 20
|
|
19
|
+
|
|
20
|
+
def test_extended_amino_acids_letters():
|
|
21
|
+
assert len(extended_amino_acid_letters) > 20
|
|
22
|
+
assert "X" in extended_amino_acid_letters
|
|
23
|
+
assert "J" in extended_amino_acid_letters
|
|
24
|
+
expected_letters = [aa.letter for aa in extended_amino_acids]
|
|
25
|
+
assert expected_letters == extended_amino_acid_letters
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_amino_acid_representation_labels_match_values():
|
|
29
|
+
alanine = canonical_amino_acids[0]
|
|
30
|
+
expected = "AminoAcid(full_name='Alanine', short_name='Ala', letter='A', contains=['A'])"
|
|
31
|
+
assert str(alanine) == expected
|
|
32
|
+
assert repr(alanine) == expected
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_alphabet_helpers_return_letters_and_names():
|
|
36
|
+
from pepdata.amino_acid_alphabet import (
|
|
37
|
+
index_to_letter, letter_to_index, peptide_to_short_amino_acid_names,
|
|
38
|
+
)
|
|
39
|
+
for letter in extended_amino_acid_letters:
|
|
40
|
+
assert index_to_letter(letter_to_index(letter)) == letter
|
|
41
|
+
assert peptide_to_short_amino_acid_names("ACX") == ["Ala", "Cys", "Xaa"]
|
|
42
|
+
assert peptide_to_short_amino_acid_names("") == []
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_pair_positions_use_two_letter_keys_in_existing_order():
|
|
46
|
+
from pepdata.amino_acid_alphabet import (
|
|
47
|
+
amino_acid_letter_pairs, amino_acid_pair_positions,
|
|
48
|
+
)
|
|
49
|
+
letters = extended_amino_acid_letters
|
|
50
|
+
assert len(amino_acid_pair_positions) == len(letters) ** 2
|
|
51
|
+
for j, y in enumerate(letters):
|
|
52
|
+
for i, x in enumerate(letters):
|
|
53
|
+
position = j * len(letters) + i
|
|
54
|
+
assert amino_acid_pair_positions[x + y] == position
|
|
55
|
+
assert amino_acid_letter_pairs[position] == x + y
|