pepdata 1.3.0__tar.gz → 1.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. {pepdata-1.3.0/pepdata.egg-info → pepdata-1.3.5}/PKG-INFO +5 -1
  2. {pepdata-1.3.0 → pepdata-1.3.5}/README.md +4 -0
  3. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/amino_acid.py +1 -1
  4. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/amino_acid_alphabet.py +8 -6
  5. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/alleles.py +3 -6
  6. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/mhc.py +7 -3
  7. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/tcell.py +7 -3
  8. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/version.py +1 -1
  9. {pepdata-1.3.0 → pepdata-1.3.5/pepdata.egg-info}/PKG-INFO +5 -1
  10. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata.egg-info/SOURCES.txt +1 -4
  11. pepdata-1.3.5/pepdata.egg-info/top_level.txt +1 -0
  12. {pepdata-1.3.0 → pepdata-1.3.5}/pyproject.toml +1 -1
  13. pepdata-1.3.5/tests/test_amino_acids.py +55 -0
  14. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_blosum.py +15 -0
  15. pepdata-1.3.5/tests/test_iedb_cache_lifecycle.py +57 -0
  16. pepdata-1.3.0/pepdata/iedb/memoize.py +0 -47
  17. pepdata-1.3.0/pepdata.egg-info/top_level.txt +0 -5
  18. pepdata-1.3.0/scripts/check_docs_examples.py +0 -33
  19. pepdata-1.3.0/scripts/check_docs_links.py +0 -54
  20. pepdata-1.3.0/tests/conftest.py +0 -23
  21. pepdata-1.3.0/tests/test_amino_acids.py +0 -25
  22. {pepdata-1.3.0 → pepdata-1.3.5}/LICENSE.txt +0 -0
  23. {pepdata-1.3.0 → pepdata-1.3.5}/MANIFEST.in +0 -0
  24. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/__init__.py +0 -0
  25. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/amino_acid_properties.py +0 -0
  26. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/blosum.py +0 -0
  27. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/chou_fasman.py +0 -0
  28. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/common.py +0 -0
  29. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/__init__.py +0 -0
  30. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/columns.py +0 -0
  31. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/iedb/common.py +0 -0
  32. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/BLOSUM30 +0 -0
  33. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/BLOSUM50 +0 -0
  34. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/BLOSUM62 +0 -0
  35. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/__init__.py +0 -0
  36. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/amino_acid_properties.txt +0 -0
  37. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/helix_vs_coil.txt +0 -0
  38. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/helix_vs_strand.txt +0 -0
  39. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/pmbec.mat +0 -0
  40. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/matrices/strand_vs_coil.txt +0 -0
  41. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/peptide_vectorizer.py +0 -0
  42. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/pmbec.py +0 -0
  43. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/reduced_alphabet.py +0 -0
  44. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/residue_contact_energies.py +0 -0
  45. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata/static_data.py +0 -0
  46. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata.egg-info/dependency_links.txt +0 -0
  47. {pepdata-1.3.0 → pepdata-1.3.5}/pepdata.egg-info/requires.txt +0 -0
  48. {pepdata-1.3.0 → pepdata-1.3.5}/requirements.txt +0 -0
  49. {pepdata-1.3.0 → pepdata-1.3.5}/setup.cfg +0 -0
  50. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_iedb_alleles.py +0 -0
  51. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_iedb_mhc.py +0 -0
  52. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_iedb_tcell.py +0 -0
  53. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_ngram.py +0 -0
  54. {pepdata-1.3.0 → pepdata-1.3.5}/tests/test_pmbec.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pepdata
3
- Version: 1.3.0
3
+ Version: 1.3.5
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.letter, self.full_name, self.short_name, self.contains))
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
- "%s%s" % (x, y)
110
- for y in extended_amino_acids
111
- for x in extended_amino_acids
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
- return extended_amino_acids[idx]
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
- return [amino_acid_letter_indices[x] for x in xs]
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(d)
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 os
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
- """Deletes local XML file"""
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
- os.remove(path)
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
- os.remove(local_path())
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
- os.remove(local_path())
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,
@@ -1,4 +1,4 @@
1
- __version__ = "1.3.0"
1
+ __version__ = "1.3.5"
2
2
 
3
3
 
4
4
  def print_version():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pepdata
3
- Version: 1.3.0
3
+ Version: 1.3.5
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
- exclude = ["test", "test.*"]
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
@@ -66,3 +66,18 @@ def test_blosum_matrix_matches_dict_in_canonical_order(number):
66
66
  for i, x in enumerate(canonical_amino_acid_letters):
67
67
  for j, y in enumerate(canonical_amino_acid_letters):
68
68
  assert matrix[i, j] == table[x][y]
69
+
70
+
71
+ @pytest.mark.parametrize("number", sorted(BLOSUM_TABLES))
72
+ def test_blosum_matrix_has_only_the_requested_alphabet(number):
73
+ _, matrix = BLOSUM_TABLES[number]
74
+ assert matrix.shape == (len(canonical_amino_acid_letters),) * 2
75
+
76
+
77
+ def test_dict_to_matrix_respects_a_subset_and_its_order():
78
+ from pepdata.amino_acid import AminoAcid
79
+ from pepdata.amino_acid_alphabet import dict_to_amino_acid_matrix
80
+
81
+ alphabet = [AminoAcid("Cysteine", "Cys", "C"), AminoAcid("Alanine", "Ala", "A")]
82
+ matrix = dict_to_amino_acid_matrix(blosum62_dict, alphabet=alphabet)
83
+ 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()
@@ -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,5 +0,0 @@
1
- dist
2
- docs
3
- pepdata
4
- scripts
5
- tests
@@ -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()
@@ -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