pepdata 1.3.7__tar.gz → 1.3.9__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.7/pepdata.egg-info → pepdata-1.3.9}/PKG-INFO +1 -1
- pepdata-1.3.9/pepdata/amino_acid_properties.py +218 -0
- pepdata-1.3.9/pepdata/blosum.py +78 -0
- pepdata-1.3.9/pepdata/pairwise_table.py +167 -0
- pepdata-1.3.9/pepdata/pmbec.py +78 -0
- pepdata-1.3.9/pepdata/residue_contact_energies.py +96 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/version.py +1 -1
- {pepdata-1.3.7 → pepdata-1.3.9/pepdata.egg-info}/PKG-INFO +1 -1
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata.egg-info/SOURCES.txt +5 -1
- pepdata-1.3.9/tests/test_amino_acid_properties.py +109 -0
- pepdata-1.3.9/tests/test_pairwise_table.py +171 -0
- pepdata-1.3.9/tests/test_public_tables_unchanged.py +84 -0
- pepdata-1.3.7/pepdata/amino_acid_properties.py +0 -357
- pepdata-1.3.7/pepdata/blosum.py +0 -73
- pepdata-1.3.7/pepdata/pmbec.py +0 -87
- pepdata-1.3.7/pepdata/residue_contact_energies.py +0 -74
- {pepdata-1.3.7 → pepdata-1.3.9}/LICENSE.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/MANIFEST.in +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/README.md +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/__init__.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/amino_acid.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/amino_acid_alphabet.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/chou_fasman.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/common.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/__init__.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/alleles.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/columns.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/common.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/mhc.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/iedb/tcell.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/BLOSUM30 +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/BLOSUM50 +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/BLOSUM62 +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/__init__.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/amino_acid_properties.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/helix_vs_coil.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/helix_vs_strand.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/pmbec.mat +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/matrices/strand_vs_coil.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/peptide_vectorizer.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/reduced_alphabet.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata/static_data.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata.egg-info/dependency_links.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata.egg-info/requires.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pepdata.egg-info/top_level.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/pyproject.toml +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/requirements.txt +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/setup.cfg +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_amino_acids.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_blosum.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_iedb_alleles.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_iedb_cache_lifecycle.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_iedb_mhc.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_iedb_tcell.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_ngram.py +0 -0
- {pepdata-1.3.7 → pepdata-1.3.9}/tests/test_pmbec.py +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
"""
|
|
14
|
+
Quantify amino acids by their physical/chemical properties
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from os.path import join
|
|
19
|
+
|
|
20
|
+
from .amino_acid_alphabet import canonical_amino_acid_letters, letter_to_index
|
|
21
|
+
from .static_data import MATRIX_DIR
|
|
22
|
+
|
|
23
|
+
# Copy of the CRASP amino-acid property page,
|
|
24
|
+
# http://www.sgi.sscc.ru/mgs/programs/crasp/texts/AA_Properties.htm
|
|
25
|
+
CRASP_PROPERTIES_PATH = join(MATRIX_DIR, "amino_acid_properties.txt")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def aa_dict_to_positional_list(aa_property_dict):
|
|
29
|
+
value_list = [None] * 20
|
|
30
|
+
for letter, value in aa_property_dict.items():
|
|
31
|
+
idx = letter_to_index(letter)
|
|
32
|
+
assert idx >= 0
|
|
33
|
+
assert idx < 20
|
|
34
|
+
value_list[idx] = value
|
|
35
|
+
assert all(elt is not None for elt in value_list), \
|
|
36
|
+
"Missing amino acids in:\n%s" % aa_property_dict.keys()
|
|
37
|
+
return value_list
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_property_table(table_string):
|
|
41
|
+
"""
|
|
42
|
+
Parse lines like `1.80000 A ALA` into a residue property dictionary.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
table_string : str
|
|
47
|
+
One line per residue: the value, the one-letter code and, optionally,
|
|
48
|
+
further fields that are ignored. Blank lines are skipped.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
dict of str to float
|
|
53
|
+
Property value for each one-letter residue code, in line order.
|
|
54
|
+
|
|
55
|
+
Raises
|
|
56
|
+
------
|
|
57
|
+
ValueError
|
|
58
|
+
If a line has fewer than two fields, a value is not a number, or a
|
|
59
|
+
residue is repeated.
|
|
60
|
+
"""
|
|
61
|
+
value_dict = {}
|
|
62
|
+
for line in table_string.splitlines():
|
|
63
|
+
fields = line.split()
|
|
64
|
+
if not fields:
|
|
65
|
+
continue
|
|
66
|
+
if len(fields) < 2:
|
|
67
|
+
raise ValueError("Expected a value and a residue in '%s'" % line)
|
|
68
|
+
value, letter = fields[:2]
|
|
69
|
+
if letter in value_dict:
|
|
70
|
+
raise ValueError("Repeated amino acid in '%s'" % line)
|
|
71
|
+
value_dict[letter] = float(value)
|
|
72
|
+
return value_dict
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def read_crasp_properties(path=CRASP_PROPERTIES_PATH):
|
|
76
|
+
"""
|
|
77
|
+
Read every table of the CRASP amino-acid property file.
|
|
78
|
+
|
|
79
|
+
The file is a sequence of blocks separated by blank lines. Each block is
|
|
80
|
+
a numbered header such as `19. Hydropathy (Kyte and Doolittle 1982)`, a
|
|
81
|
+
line with the literature citation, and one `value letter code` line per
|
|
82
|
+
canonical residue. Blocks without a numbered header, such as the source
|
|
83
|
+
URL on the first line, are skipped.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
path : str or path-like
|
|
88
|
+
Location of the property file; defaults to the copy shipped with
|
|
89
|
+
pepdata.
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
dict of str to dict of str to float
|
|
94
|
+
Residue property dictionaries keyed by their header, written as
|
|
95
|
+
`"<number>. <title>"` with a single space after the period.
|
|
96
|
+
|
|
97
|
+
Raises
|
|
98
|
+
------
|
|
99
|
+
ValueError
|
|
100
|
+
If a header is repeated, a table is malformed, or a table does not
|
|
101
|
+
cover exactly the 20 canonical residues.
|
|
102
|
+
"""
|
|
103
|
+
with open(path, "r") as f:
|
|
104
|
+
blocks = re.split(r"\n\s*\n", f.read())
|
|
105
|
+
properties = {}
|
|
106
|
+
for block in blocks:
|
|
107
|
+
lines = block.strip().splitlines()
|
|
108
|
+
header = re.fullmatch(r"(\d+)\.\s*(.+)", lines[0].strip()) if lines else None
|
|
109
|
+
if header is None:
|
|
110
|
+
continue
|
|
111
|
+
name = "%s. %s" % (header.group(1), header.group(2))
|
|
112
|
+
if name in properties:
|
|
113
|
+
raise ValueError("Repeated property table '%s'" % name)
|
|
114
|
+
table = parse_property_table("\n".join(lines[2:]))
|
|
115
|
+
if sorted(table) != sorted(canonical_amino_acid_letters):
|
|
116
|
+
raise ValueError(
|
|
117
|
+
"Property table '%s' does not cover the 20 canonical "
|
|
118
|
+
"amino acids: %s" % (name, "".join(table)))
|
|
119
|
+
properties[name] = table
|
|
120
|
+
return properties
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# All 36 tables of the CRASP property file, keyed by their numbered header
|
|
124
|
+
crasp_properties = read_crasp_properties()
|
|
125
|
+
|
|
126
|
+
# The names below are the CRASP tables this module has always exported.
|
|
127
|
+
# Each comment gives the literature citation as written in the CRASP file.
|
|
128
|
+
|
|
129
|
+
# Kyte and Doolittle, J. Mol. Biol. (1982) 157 105-132
|
|
130
|
+
hydropathy = crasp_properties["19. Hydropathy (Kyte and Doolittle 1982)"]
|
|
131
|
+
|
|
132
|
+
# Chothia, Annu. Rev. Biochem. (1984) 53 537-572
|
|
133
|
+
volume = crasp_properties["7. Volume (Chothia 1984)"]
|
|
134
|
+
|
|
135
|
+
# Ponnuswamy et al., Biochim.Biophys.Acta(1980) 623 301-316
|
|
136
|
+
polarity = crasp_properties["32. Polarity (Ponnuswamy et al. 1980)"]
|
|
137
|
+
|
|
138
|
+
# White A,Handler P,Smith EL,Hill RL,Lehman IR;Principles of Biochemistry;1978
|
|
139
|
+
pK_side_chain = crasp_properties["35. pK of side chain (White et al., 1978)"]
|
|
140
|
+
|
|
141
|
+
# Janin et al., J. Mol. Biol. (1978) 125 357-386
|
|
142
|
+
prct_exposed_residues = crasp_properties[
|
|
143
|
+
"27. Percentage of exposed residues (Janin et al. 1978)"]
|
|
144
|
+
|
|
145
|
+
# Hopp and Woods, Proc. Natl. Acad. Sci. USA (1981) 78 3824-3828
|
|
146
|
+
hydrophilicity = crasp_properties["18. Hydrophilicity (Hopp and Woods 1981)"]
|
|
147
|
+
|
|
148
|
+
# Janin et al., J. Mol. Biol. (1978) 125 357-386
|
|
149
|
+
accessible_surface_area = crasp_properties[
|
|
150
|
+
"12. Average accessibility surface area (Janin et al. 1978)"]
|
|
151
|
+
|
|
152
|
+
# Ragone et al., Prot. Engineering(1989) 2 497-504
|
|
153
|
+
local_flexibility = crasp_properties["8. Local flexibility (Ragone et al. 1989)"]
|
|
154
|
+
|
|
155
|
+
# Rose et al., Science (1975) 229 834-838
|
|
156
|
+
accessible_surface_area_folded = crasp_properties[
|
|
157
|
+
"16. Average accessible surface area in folded proteins (Rose et al. 1985)"]
|
|
158
|
+
|
|
159
|
+
# Jones, J.theor.Biol.(1975) 50 167-183
|
|
160
|
+
refractivity = crasp_properties["22. Refractivity (Jones 1975)"]
|
|
161
|
+
|
|
162
|
+
# Biemann, Meth.Enzimol. (1990) v.193, p.888
|
|
163
|
+
mass = crasp_properties["33. Average isotopic mass (Biemann, 1990)"]
|
|
164
|
+
|
|
165
|
+
###
|
|
166
|
+
# Values copied from:
|
|
167
|
+
# "Solvent accessibility of AA in known protein structures"
|
|
168
|
+
# http://prowl.rockefeller.edu/aainfo/access.htm
|
|
169
|
+
###
|
|
170
|
+
"""
|
|
171
|
+
Solvent accessibility of AA in known protein structures
|
|
172
|
+
|
|
173
|
+
Figure 1.
|
|
174
|
+
|
|
175
|
+
S 0.70 0.20 0.10
|
|
176
|
+
T 0.71 0.16 0.13
|
|
177
|
+
A 0.48 0.35 0.17
|
|
178
|
+
G 0.51 0.36 0.13
|
|
179
|
+
P 0.78 0.13 0.09
|
|
180
|
+
C 0.32 0.54 0.14
|
|
181
|
+
D 0.81 0.09 0.10
|
|
182
|
+
E 0.93 0.04 0.03
|
|
183
|
+
Q 0.81 0.10 0.09
|
|
184
|
+
N 0.82 0.10 0.08
|
|
185
|
+
L 0.41 0.49 0.10
|
|
186
|
+
I 0.39 0.47 0.14
|
|
187
|
+
V 0.40 0.50 0.10
|
|
188
|
+
M 0.44 0.20 0.36
|
|
189
|
+
F 0.42 0.42 0.16
|
|
190
|
+
Y 0.67 0.20 0.13
|
|
191
|
+
W 0.49 0.44 0.07
|
|
192
|
+
K 0.93 0.02 0.05
|
|
193
|
+
R 0.84 0.05 0.11
|
|
194
|
+
H 0.66 0.19 0.15
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
solvent_exposed_area = dict(
|
|
198
|
+
S=0.70,
|
|
199
|
+
T=0.71,
|
|
200
|
+
A=0.48,
|
|
201
|
+
G=0.51,
|
|
202
|
+
P=0.78,
|
|
203
|
+
C=0.32,
|
|
204
|
+
D=0.81,
|
|
205
|
+
E=0.93,
|
|
206
|
+
Q=0.81,
|
|
207
|
+
N=0.82,
|
|
208
|
+
L=0.41,
|
|
209
|
+
I=0.39,
|
|
210
|
+
V=0.40,
|
|
211
|
+
M=0.44,
|
|
212
|
+
F=0.42,
|
|
213
|
+
Y=0.67,
|
|
214
|
+
W=0.49,
|
|
215
|
+
K=0.93,
|
|
216
|
+
R=0.84,
|
|
217
|
+
H=0.66,
|
|
218
|
+
)
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
import warnings
|
|
14
|
+
from os.path import join
|
|
15
|
+
|
|
16
|
+
from .static_data import MATRIX_DIR
|
|
17
|
+
|
|
18
|
+
from .amino_acid_alphabet import dict_to_amino_acid_matrix
|
|
19
|
+
from .pairwise_table import (
|
|
20
|
+
parse_pairwise_table,
|
|
21
|
+
read_pairwise_table,
|
|
22
|
+
rekey_pairwise_table,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_blosum_table(table, coeff_type=int, key_type='row'):
|
|
27
|
+
"""
|
|
28
|
+
Parse a table of pairwise amino acid coefficient (e.g. BLOSUM50)
|
|
29
|
+
|
|
30
|
+
Deprecated since 1.3.8: use
|
|
31
|
+
`pepdata.pairwise_table.parse_pairwise_table` or
|
|
32
|
+
`pepdata.pairwise_table.read_pairwise_table`. This wrapper will be
|
|
33
|
+
removed in a future release.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
table : str
|
|
38
|
+
Contents of a table with a header line of column labels.
|
|
39
|
+
|
|
40
|
+
coeff_type : callable, default int
|
|
41
|
+
Converts each coefficient string to a number.
|
|
42
|
+
|
|
43
|
+
key_type : {'row', 'pair', 'pair_string'}
|
|
44
|
+
Layout of the returned dictionary; see
|
|
45
|
+
`pepdata.pairwise_table.rekey_pairwise_table`.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
dict
|
|
50
|
+
Coefficients in the requested layout.
|
|
51
|
+
|
|
52
|
+
Raises
|
|
53
|
+
------
|
|
54
|
+
ValueError
|
|
55
|
+
If the table is malformed, has fewer than 20 column labels, or
|
|
56
|
+
`key_type` is unknown.
|
|
57
|
+
"""
|
|
58
|
+
warnings.warn(
|
|
59
|
+
"parse_blosum_table is deprecated; use "
|
|
60
|
+
"pepdata.pairwise_table.parse_pairwise_table instead",
|
|
61
|
+
DeprecationWarning,
|
|
62
|
+
stacklevel=2)
|
|
63
|
+
coeffs = parse_pairwise_table(table, coeff_type=coeff_type)
|
|
64
|
+
n_labels = len(next(iter(coeffs.values())))
|
|
65
|
+
if n_labels < 20:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
"Expected 20+ amino acids but header has %d fields" % n_labels)
|
|
68
|
+
return rekey_pairwise_table(coeffs, key_type=key_type)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
blosum30_dict = read_pairwise_table(join(MATRIX_DIR, 'BLOSUM30'), coeff_type=int)
|
|
72
|
+
blosum30_matrix = dict_to_amino_acid_matrix(blosum30_dict)
|
|
73
|
+
|
|
74
|
+
blosum50_dict = read_pairwise_table(join(MATRIX_DIR, 'BLOSUM50'), coeff_type=int)
|
|
75
|
+
blosum50_matrix = dict_to_amino_acid_matrix(blosum50_dict)
|
|
76
|
+
|
|
77
|
+
blosum62_dict = read_pairwise_table(join(MATRIX_DIR, 'BLOSUM62'), coeff_type=int)
|
|
78
|
+
blosum62_matrix = dict_to_amino_acid_matrix(blosum62_dict)
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
"""
|
|
14
|
+
Read whitespace-delimited tables of amino-acid pair coefficients.
|
|
15
|
+
|
|
16
|
+
One parser serves the BLOSUM substitution matrices, the PMBEC matrix and the
|
|
17
|
+
residue contact energy tables that ship in `pepdata/matrices`.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def parse_pairwise_table(text, column_order=None, coeff_type=float):
|
|
22
|
+
"""
|
|
23
|
+
Parse the text of a table of pairwise amino-acid coefficients.
|
|
24
|
+
|
|
25
|
+
Blank lines and lines starting with `#` are ignored.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
text : str
|
|
30
|
+
Contents of the table.
|
|
31
|
+
|
|
32
|
+
column_order : sequence of str, optional
|
|
33
|
+
Residue labels of a table that has no header line and no row labels,
|
|
34
|
+
such as the residue contact energy tables. The same labels name the
|
|
35
|
+
rows and the columns, so the table must be square. When omitted, the
|
|
36
|
+
first line holds the column labels and every later line starts with
|
|
37
|
+
its row label.
|
|
38
|
+
|
|
39
|
+
coeff_type : callable, default float
|
|
40
|
+
Converts each coefficient string to a number, e.g. `int` for
|
|
41
|
+
BLOSUM scores.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
dict of str to dict of str to number
|
|
46
|
+
Coefficients accessed like `table[row_label][column_label]`.
|
|
47
|
+
|
|
48
|
+
Raises
|
|
49
|
+
------
|
|
50
|
+
ValueError
|
|
51
|
+
If the table is empty, a label is repeated, a row has the wrong
|
|
52
|
+
number of fields, or a coefficient is not a number.
|
|
53
|
+
"""
|
|
54
|
+
rows = [
|
|
55
|
+
line.split()
|
|
56
|
+
for line in text.splitlines()
|
|
57
|
+
if line.strip() and not line.strip().startswith("#")
|
|
58
|
+
]
|
|
59
|
+
if column_order is None:
|
|
60
|
+
if not rows:
|
|
61
|
+
raise ValueError("Pairwise table has no header line")
|
|
62
|
+
column_labels = rows[0]
|
|
63
|
+
labeled_rows = [(fields[0], fields[1:]) for fields in rows[1:]]
|
|
64
|
+
else:
|
|
65
|
+
column_labels = list(column_order)
|
|
66
|
+
if len(rows) != len(column_labels):
|
|
67
|
+
raise ValueError(
|
|
68
|
+
"Expected %d rows in pairwise table but found %d" % (
|
|
69
|
+
len(column_labels), len(rows)))
|
|
70
|
+
labeled_rows = list(zip(column_labels, rows))
|
|
71
|
+
|
|
72
|
+
if len(set(column_labels)) != len(column_labels):
|
|
73
|
+
raise ValueError(
|
|
74
|
+
"Repeated column label in pairwise table: %s" % (column_labels,))
|
|
75
|
+
if not labeled_rows:
|
|
76
|
+
raise ValueError("Pairwise table has no rows")
|
|
77
|
+
|
|
78
|
+
table = {}
|
|
79
|
+
for row_label, coeff_strings in labeled_rows:
|
|
80
|
+
if row_label in table:
|
|
81
|
+
raise ValueError(
|
|
82
|
+
"Repeated row label '%s' in pairwise table" % row_label)
|
|
83
|
+
if len(coeff_strings) != len(column_labels):
|
|
84
|
+
raise ValueError(
|
|
85
|
+
"Expected %d coefficients in row '%s' but found %d" % (
|
|
86
|
+
len(column_labels), row_label, len(coeff_strings)))
|
|
87
|
+
table[row_label] = {
|
|
88
|
+
column_label: coeff_type(coeff_string)
|
|
89
|
+
for column_label, coeff_string in zip(column_labels, coeff_strings)
|
|
90
|
+
}
|
|
91
|
+
return table
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def read_pairwise_table(path, column_order=None, coeff_type=float):
|
|
95
|
+
"""
|
|
96
|
+
Read a file holding a table of pairwise amino-acid coefficients.
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
path : str or path-like
|
|
101
|
+
Location of the table.
|
|
102
|
+
|
|
103
|
+
column_order : sequence of str, optional
|
|
104
|
+
Residue labels of a table without a header line or row labels; see
|
|
105
|
+
`parse_pairwise_table`.
|
|
106
|
+
|
|
107
|
+
coeff_type : callable, default float
|
|
108
|
+
Converts each coefficient string to a number.
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
dict of str to dict of str to number
|
|
113
|
+
Coefficients accessed like `table[row_label][column_label]`.
|
|
114
|
+
|
|
115
|
+
Raises
|
|
116
|
+
------
|
|
117
|
+
ValueError
|
|
118
|
+
If the table is malformed; see `parse_pairwise_table`.
|
|
119
|
+
"""
|
|
120
|
+
with open(path, "r") as f:
|
|
121
|
+
return parse_pairwise_table(
|
|
122
|
+
f.read(), column_order=column_order, coeff_type=coeff_type)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def rekey_pairwise_table(table, key_type="row"):
|
|
126
|
+
"""
|
|
127
|
+
Convert a nested pairwise table to one of the legacy key layouts.
|
|
128
|
+
|
|
129
|
+
Exists to support the deprecated `key_type` argument of
|
|
130
|
+
`pepdata.blosum.parse_blosum_table` and
|
|
131
|
+
`pepdata.pmbec.read_pmbec_coefficients`.
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
table : dict of str to dict of str to number
|
|
136
|
+
Coefficients accessed like `table[row_label][column_label]`.
|
|
137
|
+
|
|
138
|
+
key_type : {'row', 'pair', 'pair_string'}
|
|
139
|
+
`'row'` returns the nested layout unchanged, `'pair'` keys each
|
|
140
|
+
coefficient by a `(row_label, column_label)` tuple and
|
|
141
|
+
`'pair_string'` by the two labels joined into one string.
|
|
142
|
+
|
|
143
|
+
Returns
|
|
144
|
+
-------
|
|
145
|
+
dict
|
|
146
|
+
The coefficients in the requested layout.
|
|
147
|
+
|
|
148
|
+
Raises
|
|
149
|
+
------
|
|
150
|
+
ValueError
|
|
151
|
+
If `key_type` is not one of the three layouts.
|
|
152
|
+
"""
|
|
153
|
+
if key_type == "row":
|
|
154
|
+
return table
|
|
155
|
+
if key_type == "pair":
|
|
156
|
+
return {
|
|
157
|
+
(row_label, column_label): coeff
|
|
158
|
+
for row_label, row in table.items()
|
|
159
|
+
for column_label, coeff in row.items()
|
|
160
|
+
}
|
|
161
|
+
if key_type == "pair_string":
|
|
162
|
+
return {
|
|
163
|
+
row_label + column_label: coeff
|
|
164
|
+
for row_label, row in table.items()
|
|
165
|
+
for column_label, coeff in row.items()
|
|
166
|
+
}
|
|
167
|
+
raise ValueError("Unknown key type: %s" % key_type)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Copyright (c) 2014-2016. Mount Sinai School of Medicine
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import warnings
|
|
16
|
+
from os.path import join
|
|
17
|
+
|
|
18
|
+
from .static_data import MATRIX_DIR
|
|
19
|
+
|
|
20
|
+
from .amino_acid_alphabet import dict_to_amino_acid_matrix
|
|
21
|
+
from .pairwise_table import read_pairwise_table, rekey_pairwise_table
|
|
22
|
+
|
|
23
|
+
PMBEC_PATH = join(MATRIX_DIR, 'pmbec.mat')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def read_pmbec_coefficients(
|
|
27
|
+
key_type='row',
|
|
28
|
+
verbose=False,
|
|
29
|
+
filename=PMBEC_PATH):
|
|
30
|
+
"""
|
|
31
|
+
Read the PMBEC coefficient matrix.
|
|
32
|
+
|
|
33
|
+
Deprecated since 1.3.8: use
|
|
34
|
+
`pepdata.pairwise_table.read_pairwise_table`. This wrapper will be
|
|
35
|
+
removed in a future release.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
key_type : str
|
|
40
|
+
'row' : every key is a single amino acid,
|
|
41
|
+
which maps to a dictionary for that row
|
|
42
|
+
'pair' : every key is a tuple of amino acids
|
|
43
|
+
'pair_string' : every key is a string of two amino acid characters
|
|
44
|
+
|
|
45
|
+
verbose : bool
|
|
46
|
+
Ignored. Earlier releases printed the header and residue list to
|
|
47
|
+
stdout by default; nothing is printed any more.
|
|
48
|
+
|
|
49
|
+
filename : str
|
|
50
|
+
Location of PMBEC coefficient matrix
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
dict
|
|
55
|
+
Coefficients in the requested layout.
|
|
56
|
+
|
|
57
|
+
Raises
|
|
58
|
+
------
|
|
59
|
+
ValueError
|
|
60
|
+
If the table is malformed, does not have exactly 20 columns, or
|
|
61
|
+
`key_type` is unknown.
|
|
62
|
+
"""
|
|
63
|
+
warnings.warn(
|
|
64
|
+
"read_pmbec_coefficients is deprecated; use "
|
|
65
|
+
"pepdata.pairwise_table.read_pairwise_table instead",
|
|
66
|
+
DeprecationWarning,
|
|
67
|
+
stacklevel=2)
|
|
68
|
+
coeffs = read_pairwise_table(filename)
|
|
69
|
+
n_labels = len(next(iter(coeffs.values())))
|
|
70
|
+
if n_labels != 20:
|
|
71
|
+
raise ValueError(
|
|
72
|
+
"Expected 20 amino acids but header has %d fields" % n_labels)
|
|
73
|
+
return rekey_pairwise_table(coeffs, key_type=key_type)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# dictionary of PMBEC coefficient accessed like pmbec_dict["V"]["R"]
|
|
77
|
+
pmbec_dict = read_pairwise_table(PMBEC_PATH)
|
|
78
|
+
pmbec_matrix = dict_to_amino_acid_matrix(pmbec_dict)
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import warnings
|
|
14
|
+
from os.path import join
|
|
15
|
+
|
|
16
|
+
from .amino_acid_alphabet import canonical_amino_acid_letters, dict_to_amino_acid_matrix
|
|
17
|
+
from .pairwise_table import parse_pairwise_table, read_pairwise_table
|
|
18
|
+
from .static_data import MATRIX_DIR
|
|
19
|
+
|
|
20
|
+
# Row and column order shared by the three shipped contact energy tables
|
|
21
|
+
CONTACT_TABLE_AMINO_ACID_ORDER = "ARNDCQEGHILKMFPSTWYV"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def parse_interaction_table(table, amino_acid_order=CONTACT_TABLE_AMINO_ACID_ORDER):
|
|
25
|
+
"""
|
|
26
|
+
Parse a headerless 20x20 table of residue contact energies.
|
|
27
|
+
|
|
28
|
+
Deprecated since 1.3.8: use
|
|
29
|
+
`pepdata.pairwise_table.parse_pairwise_table` with its `column_order`
|
|
30
|
+
argument. This wrapper will be removed in a future release.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
table : str
|
|
35
|
+
Contents of a table with one row of coefficients per residue.
|
|
36
|
+
|
|
37
|
+
amino_acid_order : str
|
|
38
|
+
Residue letters naming both the rows and the columns.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
dict of str to dict of str to float
|
|
43
|
+
Coefficients accessed like `d[row_letter][column_letter]`.
|
|
44
|
+
|
|
45
|
+
Raises
|
|
46
|
+
------
|
|
47
|
+
ValueError
|
|
48
|
+
If the table does not have one row per residue or a row has the
|
|
49
|
+
wrong number of coefficients.
|
|
50
|
+
"""
|
|
51
|
+
warnings.warn(
|
|
52
|
+
"parse_interaction_table is deprecated; use "
|
|
53
|
+
"pepdata.pairwise_table.parse_pairwise_table instead",
|
|
54
|
+
DeprecationWarning,
|
|
55
|
+
stacklevel=2)
|
|
56
|
+
return parse_pairwise_table(table, column_order=amino_acid_order)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def transpose_interaction_dict(d):
|
|
60
|
+
transposed = {}
|
|
61
|
+
for x in canonical_amino_acid_letters:
|
|
62
|
+
transposed[x] = {}
|
|
63
|
+
for y in canonical_amino_acid_letters:
|
|
64
|
+
transposed[x][y] = d[y][x]
|
|
65
|
+
return transposed
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Strand vs. Coil
|
|
69
|
+
strand_vs_coil_dict = read_pairwise_table(
|
|
70
|
+
join(MATRIX_DIR, 'strand_vs_coil.txt'),
|
|
71
|
+
column_order=CONTACT_TABLE_AMINO_ACID_ORDER)
|
|
72
|
+
strand_vs_coil_array = dict_to_amino_acid_matrix(strand_vs_coil_dict)
|
|
73
|
+
|
|
74
|
+
# Coil vs. Strand
|
|
75
|
+
coil_vs_strand_dict = transpose_interaction_dict(strand_vs_coil_dict)
|
|
76
|
+
coil_vs_strand_array = dict_to_amino_acid_matrix(coil_vs_strand_dict)
|
|
77
|
+
|
|
78
|
+
# Helix vs. Strand
|
|
79
|
+
helix_vs_strand_dict = read_pairwise_table(
|
|
80
|
+
join(MATRIX_DIR, 'helix_vs_strand.txt'),
|
|
81
|
+
column_order=CONTACT_TABLE_AMINO_ACID_ORDER)
|
|
82
|
+
helix_vs_strand_array = dict_to_amino_acid_matrix(helix_vs_strand_dict)
|
|
83
|
+
|
|
84
|
+
# Strand vs. Helix
|
|
85
|
+
strand_vs_helix_dict = transpose_interaction_dict(helix_vs_strand_dict)
|
|
86
|
+
strand_vs_helix_array = dict_to_amino_acid_matrix(strand_vs_helix_dict)
|
|
87
|
+
|
|
88
|
+
# Helix vs. Coil
|
|
89
|
+
helix_vs_coil_dict = read_pairwise_table(
|
|
90
|
+
join(MATRIX_DIR, 'helix_vs_coil.txt'),
|
|
91
|
+
column_order=CONTACT_TABLE_AMINO_ACID_ORDER)
|
|
92
|
+
helix_vs_coil_array = dict_to_amino_acid_matrix(helix_vs_coil_dict)
|
|
93
|
+
|
|
94
|
+
# Coil vs. Helix
|
|
95
|
+
coil_vs_helix_dict = transpose_interaction_dict(helix_vs_coil_dict)
|
|
96
|
+
coil_vs_helix_array = dict_to_amino_acid_matrix(coil_vs_helix_dict)
|
|
@@ -10,6 +10,7 @@ pepdata/amino_acid_properties.py
|
|
|
10
10
|
pepdata/blosum.py
|
|
11
11
|
pepdata/chou_fasman.py
|
|
12
12
|
pepdata/common.py
|
|
13
|
+
pepdata/pairwise_table.py
|
|
13
14
|
pepdata/peptide_vectorizer.py
|
|
14
15
|
pepdata/pmbec.py
|
|
15
16
|
pepdata/reduced_alphabet.py
|
|
@@ -36,6 +37,7 @@ pepdata/matrices/helix_vs_coil.txt
|
|
|
36
37
|
pepdata/matrices/helix_vs_strand.txt
|
|
37
38
|
pepdata/matrices/pmbec.mat
|
|
38
39
|
pepdata/matrices/strand_vs_coil.txt
|
|
40
|
+
tests/test_amino_acid_properties.py
|
|
39
41
|
tests/test_amino_acids.py
|
|
40
42
|
tests/test_blosum.py
|
|
41
43
|
tests/test_iedb_alleles.py
|
|
@@ -43,4 +45,6 @@ tests/test_iedb_cache_lifecycle.py
|
|
|
43
45
|
tests/test_iedb_mhc.py
|
|
44
46
|
tests/test_iedb_tcell.py
|
|
45
47
|
tests/test_ngram.py
|
|
46
|
-
tests/
|
|
48
|
+
tests/test_pairwise_table.py
|
|
49
|
+
tests/test_pmbec.py
|
|
50
|
+
tests/test_public_tables_unchanged.py
|