pepdata 1.2.2__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {pepdata-1.2.2 → pepdata-1.3.0}/MANIFEST.in +0 -1
  2. pepdata-1.3.0/PKG-INFO +102 -0
  3. pepdata-1.3.0/README.md +75 -0
  4. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/alleles.py +1 -1
  5. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/columns.py +3 -2
  6. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/mhc.py +1 -3
  7. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/tcell.py +14 -9
  8. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/peptide_vectorizer.py +34 -3
  9. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/pmbec.py +1 -1
  10. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/version.py +2 -2
  11. pepdata-1.3.0/pepdata.egg-info/PKG-INFO +102 -0
  12. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata.egg-info/SOURCES.txt +3 -0
  13. pepdata-1.3.0/pepdata.egg-info/requires.txt +4 -0
  14. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata.egg-info/top_level.txt +2 -0
  15. {pepdata-1.2.2 → pepdata-1.3.0}/pyproject.toml +8 -1
  16. {pepdata-1.2.2 → pepdata-1.3.0}/requirements.txt +1 -5
  17. pepdata-1.3.0/scripts/check_docs_examples.py +33 -0
  18. pepdata-1.3.0/scripts/check_docs_links.py +54 -0
  19. pepdata-1.3.0/tests/conftest.py +23 -0
  20. pepdata-1.3.0/tests/test_blosum.py +68 -0
  21. {pepdata-1.2.2 → pepdata-1.3.0}/tests/test_iedb_alleles.py +20 -1
  22. {pepdata-1.2.2 → pepdata-1.3.0}/tests/test_iedb_mhc.py +19 -0
  23. {pepdata-1.2.2 → pepdata-1.3.0}/tests/test_iedb_tcell.py +8 -15
  24. pepdata-1.3.0/tests/test_ngram.py +119 -0
  25. pepdata-1.3.0/tests/test_pmbec.py +31 -0
  26. pepdata-1.2.2/PKG-INFO +0 -78
  27. pepdata-1.2.2/README.md +0 -51
  28. pepdata-1.2.2/pepdata.egg-info/PKG-INFO +0 -78
  29. pepdata-1.2.2/pepdata.egg-info/requires.txt +0 -8
  30. pepdata-1.2.2/tests/test_blosum.py +0 -17
  31. pepdata-1.2.2/tests/test_ngram.py +0 -61
  32. pepdata-1.2.2/tests/test_pmbec.py +0 -7
  33. {pepdata-1.2.2 → pepdata-1.3.0}/LICENSE.txt +0 -0
  34. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/__init__.py +0 -0
  35. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/amino_acid.py +0 -0
  36. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/amino_acid_alphabet.py +0 -0
  37. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/amino_acid_properties.py +0 -0
  38. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/blosum.py +0 -0
  39. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/chou_fasman.py +0 -0
  40. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/common.py +0 -0
  41. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/__init__.py +0 -0
  42. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/common.py +0 -0
  43. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/iedb/memoize.py +0 -0
  44. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/BLOSUM30 +0 -0
  45. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/BLOSUM50 +0 -0
  46. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/BLOSUM62 +0 -0
  47. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/__init__.py +0 -0
  48. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/amino_acid_properties.txt +0 -0
  49. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/helix_vs_coil.txt +0 -0
  50. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/helix_vs_strand.txt +0 -0
  51. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/pmbec.mat +0 -0
  52. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/matrices/strand_vs_coil.txt +0 -0
  53. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/reduced_alphabet.py +0 -0
  54. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/residue_contact_energies.py +0 -0
  55. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata/static_data.py +0 -0
  56. {pepdata-1.2.2 → pepdata-1.3.0}/pepdata.egg-info/dependency_links.txt +0 -0
  57. {pepdata-1.2.2 → pepdata-1.3.0}/setup.cfg +0 -0
  58. {pepdata-1.2.2 → pepdata-1.3.0}/tests/test_amino_acids.py +0 -0
@@ -1,2 +1 @@
1
1
  recursive-include pepdata/matrices *
2
- recursive-include pepdata/data *csv
pepdata-1.3.0/PKG-INFO ADDED
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: pepdata
3
+ Version: 1.3.0
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
+ [![Tests](https://github.com/openvax/pepdata/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
29
+ [![Documentation](https://github.com/openvax/pepdata/actions/workflows/documentation.yml/badge.svg?branch=master)](https://openvax.github.io/pepdata/)
30
+ [![PyPI](https://img.shields.io/pypi/v/pepdata.svg)](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
+ ## License
101
+
102
+ Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
@@ -0,0 +1,75 @@
1
+ [![Tests](https://github.com/openvax/pepdata/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
2
+ [![Documentation](https://github.com/openvax/pepdata/actions/workflows/documentation.yml/badge.svg?branch=master)](https://openvax.github.io/pepdata/)
3
+ [![PyPI](https://img.shields.io/pypi/v/pepdata.svg)](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
+ ## License
74
+
75
+ Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
@@ -12,7 +12,7 @@
12
12
 
13
13
  from collections import namedtuple
14
14
  import os
15
- import xml
15
+ import xml.etree.ElementTree
16
16
 
17
17
  from .common import cache
18
18
  from .memoize import memoize
@@ -47,8 +47,9 @@ def find(df : pd.DataFrame, group_candidates : list[str], column_candidates : li
47
47
 
48
48
  if len(possible_matches) == 0:
49
49
  return None
50
- # get the shortest matches
51
-
50
+ # get the shortest match
51
+ best = min(possible_matches, key=lambda p: len(p[0]) + len(p[1]))
52
+ return df[best]
52
53
 
53
54
 
54
55
  MHC_GROUP_CANDIDATES : list[str] = ["MHC", "MHC Restriction"]
@@ -42,7 +42,7 @@ 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():
@@ -108,8 +108,6 @@ def load_dataframe(
108
108
  # To deal with this, drop any columns which are all NaN
109
109
  df = df.dropna(axis=1, how="all")
110
110
 
111
- print(df.head())
112
-
113
111
  n = len(df)
114
112
 
115
113
  mhc_group_key = "MHC Restriction"
@@ -62,8 +62,8 @@ def delete():
62
62
  @memoize
63
63
  def load_dataframe(
64
64
  mhc_class : str | None = None, # 1, 2, or None for neither
65
- mhc_pattern : str | None = None,
66
- exclude_mhc : str | None = None,
65
+ hla : str | None = None,
66
+ exclude_hla : str | None = None,
67
67
  human_only : bool =False,
68
68
  peptide_length : int | None = None,
69
69
  assay_method : str | None = None,
@@ -78,10 +78,10 @@ def load_dataframe(
78
78
  mhc_class: {None, 1, 2}
79
79
  Restrict to MHC Class I or Class II (or None for neither)
80
80
 
81
- mhc_pattern: regex pattern, optional
81
+ hla: regex pattern, optional
82
82
  Restrict results to specific MHC used in assay
83
83
 
84
- exclude_mhc: regex pattern, optional
84
+ exclude_hla: regex pattern, optional
85
85
  Exclude certain MHC allele patterns
86
86
 
87
87
  human_only: bool
@@ -119,6 +119,11 @@ def load_dataframe(
119
119
  organism = get_host_name(df)
120
120
  assay_method_series = get_assay_method(df)
121
121
 
122
+ if epitopes is None:
123
+ raise ValueError(
124
+ "Could not find epitope name column in IEDB T-cell data. "
125
+ f"Available columns: {list(df.columns)}"
126
+ )
122
127
 
123
128
  # Sometimes the IEDB seems to put in an extra comma in the
124
129
  # header line, which creates an unnamed column of NaNs.
@@ -126,7 +131,7 @@ def load_dataframe(
126
131
  df = df.dropna(axis=1, how="all")
127
132
 
128
133
  n = len(df)
129
-
134
+
130
135
  null_epitope_seq = epitopes.isnull()
131
136
  n_null = null_epitope_seq.sum()
132
137
 
@@ -173,11 +178,11 @@ def load_dataframe(
173
178
  # or
174
179
  # "Class I,allele undetermined"
175
180
 
176
- if mhc_pattern:
177
- mask &= mhc.str.contains(mhc_pattern, na=False)
181
+ if hla:
182
+ mask &= mhc.str.contains(hla, na=False)
178
183
 
179
- if exclude_mhc:
180
- mask &= ~(mhc.str.contains(exclude_mhc, na=False))
184
+ if exclude_hla:
185
+ mask &= ~(mhc.str.contains(exclude_hla, na=False))
181
186
 
182
187
  if assay_method is not None and assay_method_series is not None:
183
188
  mask &= assay_method_series.str.contains(assay_method, na=False)
@@ -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).todense()
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).todense()
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).todense()
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)
@@ -1,8 +1,8 @@
1
- __version__ = "1.2.2"
1
+ __version__ = "1.3.0"
2
2
 
3
3
 
4
4
  def print_version():
5
5
  print(f"v{__version__}")
6
6
 
7
7
  if __name__ == "__main__":
8
- print_version()
8
+ print_version()
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: pepdata
3
+ Version: 1.3.0
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
+ [![Tests](https://github.com/openvax/pepdata/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/openvax/pepdata/actions/workflows/tests.yml)
29
+ [![Documentation](https://github.com/openvax/pepdata/actions/workflows/documentation.yml/badge.svg?branch=master)](https://openvax.github.io/pepdata/)
30
+ [![PyPI](https://img.shields.io/pypi/v/pepdata.svg)](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
+ ## License
101
+
102
+ Apache 2.0; see [LICENSE.txt](https://github.com/openvax/pepdata/blob/master/LICENSE.txt).
@@ -37,6 +37,9 @@ pepdata/matrices/helix_vs_coil.txt
37
37
  pepdata/matrices/helix_vs_strand.txt
38
38
  pepdata/matrices/pmbec.mat
39
39
  pepdata/matrices/strand_vs_coil.txt
40
+ scripts/check_docs_examples.py
41
+ scripts/check_docs_links.py
42
+ tests/conftest.py
40
43
  tests/test_amino_acids.py
41
44
  tests/test_blosum.py
42
45
  tests/test_iedb_alleles.py
@@ -0,0 +1,4 @@
1
+ numpy<3.0.0,>=2.0.0
2
+ pandas<4,>=3
3
+ scikit-learn>=0.14.1
4
+ datacache>=0.4.4
@@ -1,3 +1,5 @@
1
1
  dist
2
+ docs
2
3
  pepdata
4
+ scripts
3
5
  tests
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pepdata"
7
- requires-python = ">=3.9"
7
+ requires-python = ">=3.11"
8
8
  authors = [{name="Alex Rubinsteyn", email="alex.rubinsteyn@mssm.edu"}]
9
9
  description = "Immunological peptide datasets and amino acid properties"
10
10
  classifiers = [
@@ -14,6 +14,10 @@ classifiers = [
14
14
  "Intended Audience :: Science/Research",
15
15
  "License :: OSI Approved :: Apache Software License",
16
16
  "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
17
21
  "Topic :: Scientific/Engineering :: Bio-Informatics",
18
22
  ]
19
23
  readme = "README.md"
@@ -30,6 +34,9 @@ exclude = ["test", "test.*"]
30
34
  "Homepage" = "https://github.com/openvax/pepdata"
31
35
  "Bug Tracker" = "https://github.com/openvax/pepdata/issues"
32
36
 
37
+ [tool.ruff]
38
+ target-version = "py311"
39
+
33
40
  [tool.ruff.lint]
34
41
  select = ["E", "F"]
35
42
  ignore = ["F821", "E501", "F841", "E731", "E741", "E722", "E721"]
@@ -1,8 +1,4 @@
1
1
  numpy>=2.0.0,<3.0.0
2
- scipy>=0.9
3
- pandas>=0.17
2
+ pandas>=3,<4
4
3
  scikit-learn>=0.14.1
5
- progressbar33
6
- biopython>=1.65
7
4
  datacache>=0.4.4
8
- lxml
@@ -0,0 +1,33 @@
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()
@@ -0,0 +1,54 @@
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()
@@ -0,0 +1,23 @@
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
+ )