pepdata 1.3.5__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.5/pepdata.egg-info → pepdata-1.3.7}/PKG-INFO +1 -1
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/BLOSUM50 +1 -1
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/peptide_vectorizer.py +24 -11
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/version.py +1 -1
- {pepdata-1.3.5 → pepdata-1.3.7/pepdata.egg-info}/PKG-INFO +1 -1
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_blosum.py +12 -10
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_ngram.py +35 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/LICENSE.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/MANIFEST.in +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/README.md +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/__init__.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/amino_acid.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/amino_acid_alphabet.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/amino_acid_properties.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/blosum.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/chou_fasman.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/common.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/__init__.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/alleles.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/columns.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/common.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/mhc.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/iedb/tcell.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/BLOSUM30 +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/BLOSUM62 +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/__init__.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/amino_acid_properties.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/helix_vs_coil.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/helix_vs_strand.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/pmbec.mat +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/matrices/strand_vs_coil.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/pmbec.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/reduced_alphabet.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/residue_contact_energies.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata/static_data.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata.egg-info/SOURCES.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata.egg-info/dependency_links.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata.egg-info/requires.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pepdata.egg-info/top_level.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/pyproject.toml +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/requirements.txt +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/setup.cfg +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_amino_acids.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_iedb_alleles.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_iedb_cache_lifecycle.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_iedb_mhc.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_iedb_tcell.py +0 -0
- {pepdata-1.3.5 → pepdata-1.3.7}/tests/test_pmbec.py +0 -0
|
@@ -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,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))
|
|
@@ -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
|
|
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
|
|
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
|