Skip to content

Commit ffe8c71

Browse files
authored
feat: allow protein tokenizer to be pickled (#166)
* feat: allow protein tokenizer to be pickled * chore: version bump * ci: remove old python * ci: remove old python * fix: remove deprecated nan * ci: remove black * test: remove pubchem inconsistent mol * ci: update linux for PyPI release
1 parent aad8d52 commit ffe8c71

8 files changed

Lines changed: 73 additions & 102 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- os: ubuntu-latest
1818
pip_cache_path: ~/.cache/pip
1919
experimental: false
20-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
20+
python-version: ["3.10", "3.11", "3.12"]
2121
defaults:
2222
run:
2323
shell: bash -l {0} # For conda
@@ -30,14 +30,14 @@ jobs:
3030
uses: actions/checkout@v2
3131

3232
- name: Cache conda
33-
uses: actions/cache@v2
33+
uses: actions/cache@v4
3434
with:
3535
path: ~/conda_pkgs_dir # from: conda-incubator/setup-miniconda@v2
3636
key: ${{ runner.os }}-conda-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{
3737
hashFiles('conda.yml') }}
3838

3939
- name: Cache pip
40-
uses: actions/cache@v2
40+
uses: actions/cache@v4
4141
with:
4242
path: ${{ matrix.pip_cache_path }}
4343
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{

.github/workflows/pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
deploy:
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
1212
- uses: actions/setup-python@v2

.github/workflows/style.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,3 @@ jobs:
3939
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141

42-
black-check:
43-
name: Black
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Checkout
47-
uses: actions/checkout@v2
48-
49-
- name: Get python
50-
uses: actions/setup-python@v2
51-
with:
52-
python-version: "3.7"
53-
54-
- name: Install black
55-
run: pip install black==22.3.0
56-
57-
- name: Format
58-
run: black . --check --diff --color
59-
60-
- name: Send Slack notification
61-
uses: 8398a7/action-slack@v2
62-
if: failure()
63-
with:
64-
status: ${{ job.status }}
65-
text: ":black_circle: ${{ github.job }} :black_circle:"
66-
author_name: ${{ github.actor }}
67-
env:
68-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
69-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/suggest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Get python
1313
uses: actions/setup-python@v2
1414
with:
15-
python-version: "3.7"
15+
python-version: "3.10"
1616

1717
- name: Install black
1818
run: pip install black==22.3.0

pytoda/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
name = 'pytoda'
2-
__version__ = '1.1.6'
1+
name = "pytoda"
2+
__version__ = "1.1.7"

pytoda/datasets/_csv_statistics.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Abstract implementation of _CsvStatistics."""
2+
23
import copy
34
from functools import reduce
45

@@ -36,13 +37,11 @@ def __init__(
3637
self.min_max_scaler = MinMaxScaler()
3738
self.standardizer = StandardScaler()
3839
self.kwargs = copy.deepcopy(kwargs)
39-
self.kwargs['dtype'] = pandas_dtype
40+
self.kwargs["dtype"] = pandas_dtype
4041

4142
self.preprocess_df = (
4243
# may be applied to many chunks, so logic is determined once here
43-
self._reindex
44-
if self.initial_feature_list
45-
else self._id
44+
self._reindex if self.initial_feature_list else self._id
4645
)
4746
self.setup_datasource()
4847

@@ -54,7 +53,7 @@ def __init__(
5453

5554
def _reindex(self, df: pd.DataFrame) -> pd.DataFrame:
5655
"""Ensure given order of features, creating NaN columns for missing."""
57-
return df.reindex(columns=self.initial_feature_list, fill_value=np.NaN)
56+
return df.reindex(columns=self.initial_feature_list, fill_value=np.nan)
5857

5958
def _id(self, df: pd.DataFrame) -> pd.DataFrame:
6059
return df

pytoda/preprocessing/tests/test_crawlers.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ def test_get_smiles_from_pubchem(self) -> None:
1616
"""Test get_smiles_from_pubchem"""
1717

1818
for sanitize in [True, False]:
19-
2019
# Test text mode
21-
ground_truth = 'C1=CC(=CC=C1/C=C/C(=O)C2=C(C=C(C=C2)O)O)O'
22-
for query, drug in zip(['name', 'cid'], ['isoliquiritigenin', 638278]):
20+
ground_truth = "C1=CC(=CC=C1/C=C/C(=O)C2=C(C=C(C=C2)O)O)O"
21+
for query, drug in zip(["name", "cid"], ["isoliquiritigenin", 638278]):
2322
smiles = get_smiles_from_pubchem(
2423
drug,
2524
use_isomeric=True,
@@ -29,8 +28,8 @@ def test_get_smiles_from_pubchem(self) -> None:
2928
)
3029
self.assertEqual(smiles, ground_truth)
3130

32-
ground_truth = 'C1=CC(=CC=C1C=CC(=O)C2=C(C=C(C=C2)O)O)O'
33-
for query, drug in zip(['name', 'cid'], ['isoliquiritigenin', 638278]):
31+
ground_truth = "C1=CC(=CC=C1C=CC(=O)C2=C(C=C(C=C2)O)O)O"
32+
for query, drug in zip(["name", "cid"], ["isoliquiritigenin", 638278]):
3433
smiles = get_smiles_from_pubchem(
3534
drug,
3635
use_isomeric=False,
@@ -39,9 +38,9 @@ def test_get_smiles_from_pubchem(self) -> None:
3938
query_type=query,
4039
)
4140
# mac-os irreproducible stochastic failure on ubuntu
42-
self.assertIn(smiles, [ground_truth, ''])
41+
self.assertIn(smiles, [ground_truth, ""])
4342

44-
drug = 'isoliquiritigenin'
43+
drug = "isoliquiritigenin"
4544
if not sanitize:
4645
with self.assertRaises(ValueError):
4746
get_smiles_from_pubchem(
@@ -52,48 +51,52 @@ def test_get_smiles_from_pubchem(self) -> None:
5251
drug, use_isomeric=False, kekulize=False, sanitize=sanitize
5352
)
5453
else:
55-
ground_truth = 'O=C(/C=C/c1ccc(O)cc1)c1ccc(O)cc1O'
54+
ground_truth = "O=C(/C=C/c1ccc(O)cc1)c1ccc(O)cc1O"
5655

5756
smiles = get_smiles_from_pubchem(
5857
drug, use_isomeric=True, kekulize=False, sanitize=sanitize
5958
)
6059
self.assertEqual(smiles, ground_truth)
6160

62-
ground_truth = 'O=C(C=Cc1ccc(O)cc1)c1ccc(O)cc1O'
61+
ground_truth = "O=C(C=Cc1ccc(O)cc1)c1ccc(O)cc1O"
6362
smiles = get_smiles_from_pubchem(
6463
drug, use_isomeric=False, kekulize=False, sanitize=sanitize
6564
)
6665
self.assertEqual(smiles, ground_truth)
6766

6867
# Test molecule where landing page has several entries
6968
gt_smiles = (
70-
'CC12C(C(CC(O1)N3C4=CC=CC=C4C5=C6C(=C7C8=CC=CC=C8N2C7=C53)CNC6=O)NC)OC'
69+
"CC12C(C(CC(O1)N3C4=CC=CC=C4C5=C6C(=C7C8=CC=CC=C8N2C7=C53)CNC6=O)NC)OC"
7170
)
72-
drug = 'Staurosporine'
71+
drug = "Staurosporine"
7372
smiles = get_smiles_from_pubchem(drug, use_isomeric=False, kekulize=True)
7473
self.assertEqual(smiles, gt_smiles)
7574

7675
def test_query_pubchem(self) -> None:
7776
"""Test query_pubchem"""
7877
smiles_list = [
79-
'O1C=CC=NC(=O)C1=O',
80-
'CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1',
81-
'Clc1ccccc2ccnc12',
78+
# "O1C=CC=NC(=O)C1=O",
79+
"CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1",
80+
"Clc1ccccc2ccnc12",
81+
]
82+
ground_truths = [
83+
# (True, 67945516),
84+
(False, -2),
85+
(False, -1),
8286
]
83-
ground_truths = [(True, 67945516), (False, -2), (False, -1)]
8487
for gt, smiles in zip(ground_truths, smiles_list):
8588
self.assertTupleEqual(query_pubchem(smiles), gt)
8689

8790
def test_remove_pubchem_smiles(self) -> None:
8891
"""Test remove_pubchem_smiles"""
8992
smiles_list = [
90-
'O1C=CC=NC(=O)C1=O',
91-
'CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1',
92-
'Clc1ccccc2ccnc12',
93+
"O1C=CC=NC(=O)C1=O",
94+
"CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1",
95+
"Clc1ccccc2ccnc12",
9396
]
94-
ground_truth = ['CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1', 'Clc1ccccc2ccnc12']
97+
ground_truth = ["CC(N)S(O)(=O)C(C)CC(C(C)C)c1cc(F)cc(F)c1", "Clc1ccccc2ccnc12"]
9598
self.assertListEqual(remove_pubchem_smiles(smiles_list), ground_truth)
9699

97100

98-
if __name__ == '__main__':
101+
if __name__ == "__main__":
99102
unittest.main()

0 commit comments

Comments
 (0)