pepdata 1.3.0__tar.gz → 1.3.7__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.0/pepdata.egg-info → pepdata-1.3.7}/PKG-INFO +5 -1
- {pepdata-1.3.0 → pepdata-1.3.7}/README.md +4 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/amino_acid.py +1 -1
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/amino_acid_alphabet.py +8 -6
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/alleles.py +3 -6
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/mhc.py +7 -3
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/tcell.py +7 -3
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/BLOSUM50 +1 -1
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/peptide_vectorizer.py +24 -11
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/version.py +1 -1
- {pepdata-1.3.0 → pepdata-1.3.7/pepdata.egg-info}/PKG-INFO +5 -1
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata.egg-info/SOURCES.txt +1 -4
- pepdata-1.3.7/pepdata.egg-info/top_level.txt +1 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pyproject.toml +1 -1
- pepdata-1.3.7/tests/test_amino_acids.py +55 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_blosum.py +27 -10
- pepdata-1.3.7/tests/test_iedb_cache_lifecycle.py +57 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_ngram.py +35 -0
- pepdata-1.3.0/pepdata/iedb/memoize.py +0 -47
- pepdata-1.3.0/pepdata.egg-info/top_level.txt +0 -5
- pepdata-1.3.0/scripts/check_docs_examples.py +0 -33
- pepdata-1.3.0/scripts/check_docs_links.py +0 -54
- pepdata-1.3.0/tests/conftest.py +0 -23
- pepdata-1.3.0/tests/test_amino_acids.py +0 -25
- {pepdata-1.3.0 → pepdata-1.3.7}/LICENSE.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/MANIFEST.in +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/__init__.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/amino_acid_properties.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/blosum.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/chou_fasman.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/common.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/__init__.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/columns.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/iedb/common.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/BLOSUM30 +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/BLOSUM62 +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/__init__.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/amino_acid_properties.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/helix_vs_coil.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/helix_vs_strand.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/pmbec.mat +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/matrices/strand_vs_coil.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/pmbec.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/reduced_alphabet.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/residue_contact_energies.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata/static_data.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata.egg-info/dependency_links.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/pepdata.egg-info/requires.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/requirements.txt +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/setup.cfg +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_iedb_alleles.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_iedb_mhc.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_iedb_tcell.py +0 -0
- {pepdata-1.3.0 → pepdata-1.3.7}/tests/test_pmbec.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pepdata
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.7
|
|
4
4
|
Summary: Immunological peptide datasets and amino acid properties
|
|
5
5
|
Author-email: Alex Rubinsteyn <alex.rubinsteyn@mssm.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/openvax/pepdata
|
|
@@ -97,6 +97,10 @@ python -m pip install -r requirements-docs.txt
|
|
|
97
97
|
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
98
98
|
```
|
|
99
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
|
+
|
|
100
104
|
## License
|
|
101
105
|
|
|
102
106
|
Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
|
|
@@ -70,6 +70,10 @@ python -m pip install -r requirements-docs.txt
|
|
|
70
70
|
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
71
71
|
```
|
|
72
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
|
+
|
|
73
77
|
## License
|
|
74
78
|
|
|
75
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
|
|
14
|
+
from pathlib import Path
|
|
15
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
|
|
|
@@ -46,9 +46,13 @@ def local_path(auto_download=True):
|
|
|
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,
|
|
@@ -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,
|
|
@@ -16,6 +16,6 @@ F -3 -3 -4 -5 -2 -4 -3 -4 -1 0 1 -4 0 8 -4 -3 -2 1 4 -1
|
|
|
16
16
|
P -1 -3 -2 -1 -4 -1 -1 -2 -2 -3 -4 -1 -3 -4 10 -1 -1 -4 -3 -3
|
|
17
17
|
S 1 -1 1 0 -1 0 -1 0 -1 -3 -3 0 -2 -3 -1 5 2 -4 -2 -2
|
|
18
18
|
T 0 -1 0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -2 -1 2 5 -3 -2 0
|
|
19
|
-
W -3 -3 -4 -5 -5 -1 -3 -3 -3 -3 -2 -3 -1 1 -4 -4 -
|
|
19
|
+
W -3 -3 -4 -5 -5 -1 -3 -3 -3 -3 -2 -3 -1 1 -4 -4 -3 15 2 -3
|
|
20
20
|
Y -2 -1 -2 -3 -3 -1 -2 -3 2 -1 -1 -2 0 4 -3 -2 -2 2 8 -1
|
|
21
21
|
V 0 -3 -3 -4 -1 -3 -3 -4 -4 4 1 -3 1 -1 -3 -2 0 -3 -1 5
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
from copy import copy
|
|
17
|
+
|
|
16
18
|
import numpy as np
|
|
17
19
|
from sklearn.feature_extraction.text import CountVectorizer
|
|
18
20
|
from sklearn.preprocessing import normalize
|
|
@@ -70,16 +72,12 @@ class PeptideVectorizer(object):
|
|
|
70
72
|
n-grams) with n-gram counts, or per-row frequencies (each row
|
|
71
73
|
divided by its total) when normalize_row is True.
|
|
72
74
|
"""
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if self.training_already_reduced
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
self.count_vectorizer.vocabulary_ = c.vocabulary_
|
|
80
|
-
else:
|
|
81
|
-
c = self.count_vectorizer
|
|
82
|
-
X = c.fit_transform(amino_acid_strings).toarray()
|
|
75
|
+
# Already-reduced training must use the same tokenization later used
|
|
76
|
+
# for reduced transform input. Keep its existing lowercase vocabulary
|
|
77
|
+
# and feature-column order, including in saved vectorizers.
|
|
78
|
+
alphabet = None if self.training_already_reduced else self.reduced_alphabet
|
|
79
|
+
self.count_vectorizer = make_count_vectorizer(alphabet, self.max_ngram)
|
|
80
|
+
X = self.count_vectorizer.fit_transform(amino_acid_strings).toarray()
|
|
83
81
|
|
|
84
82
|
if self.normalize_row:
|
|
85
83
|
X = normalize(X, norm='l1')
|
|
@@ -93,6 +91,8 @@ class PeptideVectorizer(object):
|
|
|
93
91
|
Vectorize sequences with the vocabulary learned by fit.
|
|
94
92
|
|
|
95
93
|
n-grams that weren't seen during fitting are not counted.
|
|
94
|
+
Input sequences are unreduced, even when training_already_reduced was
|
|
95
|
+
used during fitting.
|
|
96
96
|
|
|
97
97
|
Parameters
|
|
98
98
|
----------
|
|
@@ -106,7 +106,20 @@ class PeptideVectorizer(object):
|
|
|
106
106
|
vocabulary), normalized per row as in fit_transform.
|
|
107
107
|
"""
|
|
108
108
|
assert self.count_vectorizer, "Must call 'fit' before 'transform'"
|
|
109
|
-
|
|
109
|
+
vectorizer = self.count_vectorizer
|
|
110
|
+
if self.training_already_reduced:
|
|
111
|
+
if self.reduced_alphabet is not None:
|
|
112
|
+
amino_acid_strings = [
|
|
113
|
+
"".join(self.reduced_alphabet[residue] for residue in sequence)
|
|
114
|
+
for sequence in amino_acid_strings
|
|
115
|
+
]
|
|
116
|
+
# Older saved models attached the raw-sequence preprocessor to a
|
|
117
|
+
# lowercase vocabulary fitted by a different CountVectorizer.
|
|
118
|
+
# Preserve that vocabulary without reducing twice or mutating it.
|
|
119
|
+
if vectorizer.preprocessor is not None:
|
|
120
|
+
vectorizer = copy(vectorizer)
|
|
121
|
+
vectorizer.preprocessor = None
|
|
122
|
+
X = vectorizer.transform(amino_acid_strings).toarray()
|
|
110
123
|
if self.normalize_row:
|
|
111
124
|
X = normalize(X, norm='l1')
|
|
112
125
|
return X
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pepdata
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.7
|
|
4
4
|
Summary: Immunological peptide datasets and amino acid properties
|
|
5
5
|
Author-email: Alex Rubinsteyn <alex.rubinsteyn@mssm.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/openvax/pepdata
|
|
@@ -97,6 +97,10 @@ python -m pip install -r requirements-docs.txt
|
|
|
97
97
|
python scripts/check_docs_examples.py # run docs examples, compare output
|
|
98
98
|
```
|
|
99
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
|
+
|
|
100
104
|
## License
|
|
101
105
|
|
|
102
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,7 +28,7 @@ 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"
|
|
@@ -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
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
1
3
|
import pytest
|
|
2
4
|
|
|
3
5
|
from pepdata.amino_acid_alphabet import canonical_amino_acid_letters
|
|
@@ -41,7 +43,7 @@ def test_blosum_diagonal_scores(number):
|
|
|
41
43
|
assert table[residue][residue] == max(row)
|
|
42
44
|
|
|
43
45
|
|
|
44
|
-
@pytest.mark.parametrize("number",
|
|
46
|
+
@pytest.mark.parametrize("number", sorted(BLOSUM_TABLES))
|
|
45
47
|
def test_blosum_is_symmetric(number):
|
|
46
48
|
table, _ = BLOSUM_TABLES[number]
|
|
47
49
|
for x in canonical_amino_acid_letters:
|
|
@@ -49,15 +51,15 @@ def test_blosum_is_symmetric(number):
|
|
|
49
51
|
assert table[x][y] == table[y][x]
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
def test_blosum50_matches_ncbi_canonical_scores():
|
|
55
|
+
reference = Path(__file__).parent / "data/ncbi_BLOSUM50.txt"
|
|
56
|
+
rows = [line.split() for line in reference.read_text().splitlines()
|
|
57
|
+
if line.strip() and not line.startswith("#")]
|
|
58
|
+
header = rows[0]
|
|
59
|
+
expected = {row[0]: dict(zip(header, map(int, row[1:]))) for row in rows[1:]}
|
|
60
|
+
for x in canonical_amino_acid_letters:
|
|
61
|
+
for y in canonical_amino_acid_letters:
|
|
62
|
+
assert blosum50_dict[x][y] == expected[x][y], (x, y)
|
|
61
63
|
|
|
62
64
|
|
|
63
65
|
@pytest.mark.parametrize("number", sorted(BLOSUM_TABLES))
|
|
@@ -66,3 +68,18 @@ def test_blosum_matrix_matches_dict_in_canonical_order(number):
|
|
|
66
68
|
for i, x in enumerate(canonical_amino_acid_letters):
|
|
67
69
|
for j, y in enumerate(canonical_amino_acid_letters):
|
|
68
70
|
assert matrix[i, j] == table[x][y]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize("number", sorted(BLOSUM_TABLES))
|
|
74
|
+
def test_blosum_matrix_has_only_the_requested_alphabet(number):
|
|
75
|
+
_, matrix = BLOSUM_TABLES[number]
|
|
76
|
+
assert matrix.shape == (len(canonical_amino_acid_letters),) * 2
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_dict_to_matrix_respects_a_subset_and_its_order():
|
|
80
|
+
from pepdata.amino_acid import AminoAcid
|
|
81
|
+
from pepdata.amino_acid_alphabet import dict_to_amino_acid_matrix
|
|
82
|
+
|
|
83
|
+
alphabet = [AminoAcid("Cysteine", "Cys", "C"), AminoAcid("Alanine", "Ala", "A")]
|
|
84
|
+
matrix = dict_to_amino_acid_matrix(blosum62_dict, alphabet=alphabet)
|
|
85
|
+
assert matrix.tolist() == [[9, 0], [0, 4]]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""The two assay loaders agree about file freshness and ownership."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import shutil
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from pepdata.iedb import alleles, mhc, tcell
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize("module", [mhc, tcell, alleles])
|
|
12
|
+
def test_delete_never_downloads_and_is_idempotent(module, monkeypatch, tmp_path):
|
|
13
|
+
path = tmp_path / "assays.csv"
|
|
14
|
+
monkeypatch.setattr(module.cache, "local_path", lambda **kwargs: str(path))
|
|
15
|
+
|
|
16
|
+
def fail_download(**kwargs):
|
|
17
|
+
pytest.fail("deleting a local export must never download it")
|
|
18
|
+
|
|
19
|
+
monkeypatch.setattr(module.cache, "fetch", fail_download)
|
|
20
|
+
module.delete()
|
|
21
|
+
path.write_text("local export")
|
|
22
|
+
module.delete()
|
|
23
|
+
assert not path.exists()
|
|
24
|
+
module.delete()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.parametrize("module", [mhc, tcell])
|
|
28
|
+
def test_load_returns_independent_frames_and_observes_replaced_file(module, monkeypatch, tmp_path):
|
|
29
|
+
source = tmp_path / "assays.csv"
|
|
30
|
+
fixture = Path(module.local_path())
|
|
31
|
+
shutil.copyfile(fixture, source)
|
|
32
|
+
monkeypatch.setattr(module, "local_path", lambda auto_download=True: str(source))
|
|
33
|
+
|
|
34
|
+
first = module.load_dataframe()
|
|
35
|
+
count = len(first)
|
|
36
|
+
assert count > 0
|
|
37
|
+
first.drop(first.index, inplace=True)
|
|
38
|
+
assert len(module.load_dataframe()) == count
|
|
39
|
+
|
|
40
|
+
lines = source.read_text().splitlines(keepends=True)
|
|
41
|
+
source.write_text("".join(lines + lines[2:]))
|
|
42
|
+
assert len(module.load_dataframe()) == count * 2
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_allele_loaders_return_independent_values():
|
|
46
|
+
first = alleles.load_alleles()
|
|
47
|
+
assert first
|
|
48
|
+
first[0].synonyms.add("caller-added-synonym")
|
|
49
|
+
first.clear()
|
|
50
|
+
second = alleles.load_alleles()
|
|
51
|
+
assert second
|
|
52
|
+
assert "caller-added-synonym" not in second[0].synonyms
|
|
53
|
+
|
|
54
|
+
first_dict = alleles.load_alleles_dict()
|
|
55
|
+
assert first_dict
|
|
56
|
+
first_dict.clear()
|
|
57
|
+
assert alleles.load_alleles_dict()
|
|
@@ -18,6 +18,7 @@ import numpy as np
|
|
|
18
18
|
import pytest
|
|
19
19
|
|
|
20
20
|
from pepdata import PeptideVectorizer
|
|
21
|
+
from pepdata.peptide_vectorizer import make_count_vectorizer
|
|
21
22
|
from pepdata.reduced_alphabet import hp2
|
|
22
23
|
|
|
23
24
|
# isoforms of two different proteins a, b
|
|
@@ -117,3 +118,37 @@ def test_pickled_vectorizer_transforms_identically():
|
|
|
117
118
|
vectorizer.fit(A)
|
|
118
119
|
restored = pickle.loads(pickle.dumps(vectorizer))
|
|
119
120
|
np.testing.assert_allclose(restored.transform(B), vectorizer.transform(B))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@pytest.mark.parametrize("max_ngram", [1, 2])
|
|
124
|
+
@pytest.mark.parametrize("normalize_row", [False, True])
|
|
125
|
+
def test_already_reduced_training_matches_raw_transform(max_ngram, normalize_row):
|
|
126
|
+
sequences = ["SIINFEKL", "GILGFVFTL"]
|
|
127
|
+
reduced = ["".join(hp2[r] for r in sequence) for sequence in sequences]
|
|
128
|
+
vectorizer = PeptideVectorizer(
|
|
129
|
+
max_ngram=max_ngram, reduced_alphabet=hp2,
|
|
130
|
+
training_already_reduced=True, normalize_row=normalize_row)
|
|
131
|
+
expected = vectorizer.fit_transform(reduced)
|
|
132
|
+
assert expected.sum() > 0
|
|
133
|
+
vocabulary = dict(vectorizer.count_vectorizer.vocabulary_)
|
|
134
|
+
np.testing.assert_allclose(vectorizer.transform(sequences), expected)
|
|
135
|
+
restored = pickle.loads(pickle.dumps(vectorizer))
|
|
136
|
+
np.testing.assert_allclose(restored.transform(sequences), expected)
|
|
137
|
+
assert restored.count_vectorizer.vocabulary_ == vocabulary
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_legacy_reduced_vectorizer_preserves_lowercase_feature_columns():
|
|
141
|
+
sequences = ["SIINFEKL", "GILGFVFTL"]
|
|
142
|
+
reduced = ["".join(hp2[r] for r in sequence) for sequence in sequences]
|
|
143
|
+
fitted = make_count_vectorizer(None, 2)
|
|
144
|
+
expected = fitted.fit_transform(reduced).toarray()
|
|
145
|
+
legacy = PeptideVectorizer(
|
|
146
|
+
max_ngram=2, reduced_alphabet=hp2,
|
|
147
|
+
training_already_reduced=True, normalize_row=False)
|
|
148
|
+
legacy.count_vectorizer = make_count_vectorizer(hp2, 2)
|
|
149
|
+
legacy.count_vectorizer.vocabulary_ = fitted.vocabulary_
|
|
150
|
+
original_preprocessor = legacy.count_vectorizer.preprocessor
|
|
151
|
+
vocabulary = dict(fitted.vocabulary_)
|
|
152
|
+
np.testing.assert_array_equal(legacy.transform(sequences), expected)
|
|
153
|
+
assert legacy.count_vectorizer.preprocessor is original_preprocessor
|
|
154
|
+
assert legacy.count_vectorizer.vocabulary_ == vocabulary
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
2
|
-
# you may not use this file except in compliance with the License.
|
|
3
|
-
# You may obtain a copy of the License at
|
|
4
|
-
#
|
|
5
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
#
|
|
7
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
# See the License for the specific language governing permissions and
|
|
11
|
-
# limitations under the License.
|
|
12
|
-
|
|
13
|
-
from functools import wraps
|
|
14
|
-
|
|
15
|
-
def _prepare_memoization_key(args, kwargs):
|
|
16
|
-
"""
|
|
17
|
-
Make a tuple of arguments which can be used as a key
|
|
18
|
-
for a memoized function's lookup_table. If some object can't be hashed
|
|
19
|
-
then used its __repr__ instead.
|
|
20
|
-
"""
|
|
21
|
-
key_list = []
|
|
22
|
-
for arg in args:
|
|
23
|
-
try:
|
|
24
|
-
hash(arg)
|
|
25
|
-
key_list.append(arg)
|
|
26
|
-
except:
|
|
27
|
-
key_list.append(repr(arg))
|
|
28
|
-
for (k, v) in kwargs.items():
|
|
29
|
-
try:
|
|
30
|
-
hash(k)
|
|
31
|
-
hash(v)
|
|
32
|
-
key_list.append((k, v))
|
|
33
|
-
except:
|
|
34
|
-
key_list.append((repr(k), repr(v)))
|
|
35
|
-
return tuple(key_list)
|
|
36
|
-
|
|
37
|
-
def memoize(fn):
|
|
38
|
-
lookup_table = {}
|
|
39
|
-
|
|
40
|
-
@wraps(fn)
|
|
41
|
-
def wrapped_fn(*args, **kwargs):
|
|
42
|
-
key = _prepare_memoization_key(args, kwargs)
|
|
43
|
-
if key not in lookup_table:
|
|
44
|
-
lookup_table[key] = fn(*args, **kwargs)
|
|
45
|
-
return lookup_table[key]
|
|
46
|
-
|
|
47
|
-
return wrapped_fn
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"""Execute documentation examples and compare the printed output."""
|
|
2
|
-
|
|
3
|
-
import contextlib
|
|
4
|
-
import io
|
|
5
|
-
import re
|
|
6
|
-
import sys
|
|
7
|
-
import types
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def main():
|
|
12
|
-
count = 0
|
|
13
|
-
for path in sorted(Path("docs").rglob("*.md")):
|
|
14
|
-
module = types.ModuleType("docs_example_" + path.stem.replace("-", "_"))
|
|
15
|
-
sys.modules[module.__name__] = module
|
|
16
|
-
blocks = list(re.finditer(r"```(python|text)\n(.*?)\n```", path.read_text(), re.S))
|
|
17
|
-
for index, match in enumerate(blocks):
|
|
18
|
-
if match[1] != "python" or index + 1 == len(blocks) or blocks[index + 1][1] != "text":
|
|
19
|
-
continue
|
|
20
|
-
output = io.StringIO()
|
|
21
|
-
with contextlib.redirect_stdout(output):
|
|
22
|
-
exec(compile(match[2], str(path), "exec"), module.__dict__)
|
|
23
|
-
if index + 1 < len(blocks) and blocks[index + 1][1] == "text":
|
|
24
|
-
expected = blocks[index + 1][2].rstrip()
|
|
25
|
-
actual = output.getvalue().rstrip()
|
|
26
|
-
if actual != expected:
|
|
27
|
-
raise AssertionError(f"{path}: {actual!r} != {expected!r}")
|
|
28
|
-
count += 1
|
|
29
|
-
print(f"Executed {count} documentation examples.")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if __name__ == "__main__":
|
|
33
|
-
main()
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"""Check rendered internal links and fragment targets."""
|
|
2
|
-
from html.parser import HTMLParser
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from urllib.parse import unquote, urlsplit
|
|
5
|
-
import yaml
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Page(HTMLParser):
|
|
9
|
-
def __init__(self, text):
|
|
10
|
-
super().__init__()
|
|
11
|
-
self.ids = set()
|
|
12
|
-
self.links = []
|
|
13
|
-
self.feed(text)
|
|
14
|
-
|
|
15
|
-
def handle_starttag(self, tag, attrs):
|
|
16
|
-
attrs = dict(attrs)
|
|
17
|
-
if attrs.get("id"):
|
|
18
|
-
self.ids.add(attrs["id"])
|
|
19
|
-
if tag == "a" and attrs.get("href"):
|
|
20
|
-
self.links.append(attrs["href"])
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def main():
|
|
24
|
-
root = Path("site").resolve()
|
|
25
|
-
base = urlsplit(yaml.safe_load(Path("mkdocs.yml").read_text())["site_url"]).path.rstrip("/")
|
|
26
|
-
pages = {p.resolve(): Page(p.read_text()) for p in root.rglob("*.html")}
|
|
27
|
-
failures = []
|
|
28
|
-
count = 0
|
|
29
|
-
for source, page in pages.items():
|
|
30
|
-
for href in page.links:
|
|
31
|
-
url = urlsplit(href)
|
|
32
|
-
if url.scheme or url.netloc:
|
|
33
|
-
continue
|
|
34
|
-
path = unquote(url.path)
|
|
35
|
-
if path.startswith("/"):
|
|
36
|
-
if not (path == base or path.startswith(base + "/")):
|
|
37
|
-
continue
|
|
38
|
-
target = (root / path[len(base):].lstrip("/")).resolve()
|
|
39
|
-
else:
|
|
40
|
-
target = (source.parent / path).resolve() if path else source
|
|
41
|
-
if target.is_dir():
|
|
42
|
-
target /= "index.html"
|
|
43
|
-
count += 1
|
|
44
|
-
if not target.is_relative_to(root) or not target.exists():
|
|
45
|
-
failures.append(f"{source.relative_to(root)}: missing {href}")
|
|
46
|
-
elif url.fragment and target in pages and unquote(url.fragment) not in pages[target].ids:
|
|
47
|
-
failures.append(f"{source.relative_to(root)}: missing fragment {href}")
|
|
48
|
-
if failures:
|
|
49
|
-
raise SystemExit("\n".join(failures))
|
|
50
|
-
print(f"Checked {len(pages)} pages and {count} internal links.")
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if __name__ == "__main__":
|
|
54
|
-
main()
|
pepdata-1.3.0/tests/conftest.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""Use synthetic IEDB-format fixtures instead of live downloads in unit tests."""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "data")
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@pytest.fixture(autouse=True)
|
|
10
|
-
def patch_iedb_paths(monkeypatch):
|
|
11
|
-
"""Redirect assay tables and the allele catalogue to bundled fixtures."""
|
|
12
|
-
monkeypatch.setattr(
|
|
13
|
-
"pepdata.iedb.alleles.local_path",
|
|
14
|
-
lambda force_download=False: os.path.join(FIXTURES_DIR, "alleles_test_fixture.xml"),
|
|
15
|
-
)
|
|
16
|
-
monkeypatch.setattr(
|
|
17
|
-
"pepdata.iedb.tcell.local_path",
|
|
18
|
-
lambda auto_download=True: os.path.join(FIXTURES_DIR, "tcell_test_fixture.csv"),
|
|
19
|
-
)
|
|
20
|
-
monkeypatch.setattr(
|
|
21
|
-
"pepdata.iedb.mhc.local_path",
|
|
22
|
-
lambda auto_download=True: os.path.join(FIXTURES_DIR, "mhc_test_fixture.csv"),
|
|
23
|
-
)
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|