Skip to content

Commit 8bb7e61

Browse files
committed
Update plastchem.py
1 parent 90cd4c6 commit 8bb7e61

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/pyobo/identifier_utils/api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from __future__ import annotations
44

55
import logging
6+
from collections.abc import Callable
67
from functools import lru_cache, wraps
7-
from typing import Annotated, ClassVar
8+
from typing import Annotated, ClassVar, ParamSpec, TypeVar
89

910
import bioregistry
1011
import click
@@ -266,7 +267,11 @@ def _parse_str_or_curie_or_uri_helper(
266267
return rv
267268

268269

269-
def wrap_norm_prefix(f):
270+
S = ParamSpec("S")
271+
T = TypeVar("T")
272+
273+
274+
def wrap_norm_prefix(f: Callable[S, T]) -> Callable[S, T]:
270275
"""Decorate a function that take in a prefix to auto-normalize, or return None if it can't be normalized."""
271276

272277
@wraps(f)

src/pyobo/sources/plastchem.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from collections import Counter
44
from collections.abc import Iterable
5+
from typing import Any
56

67
import pandas as pd
78
from tabulate import tabulate
@@ -19,8 +20,10 @@
1920
from pyobo.utils.path import ensure_path
2021

2122
__all__ = ["PlastChemGetter"]
23+
2224
PREFIX = "plastchem"
2325
URL = "https://zenodo.org/records/10701706/files/plastchem_db_v1.0.xlsx?download=1"
26+
VERSION = "1.0"
2427

2528
# See page 45 of the report for explanation
2629
HAZARD_LISTS = {
@@ -49,7 +52,7 @@ class PlastChemGetter(Obo):
4952
"""An ontology representation of PlastChem."""
5053

5154
ontology = PREFIX
52-
static_version = "1.0"
55+
static_version = VERSION
5356
typedef = [
5457
TYPEDEF,
5558
has_inchi,
@@ -72,14 +75,15 @@ def get_terms() -> Iterable[Term]:
7275
term.append_parent(HAZARD_LIST_ROOT)
7376
yield term
7477

75-
echa_counter = Counter()
78+
echa_counter: Counter[str] = Counter()
7679
echa_examples = {}
77-
function_counter = Counter()
80+
function_counter: Counter[str] = Counter()
7881
function_examples = {}
7982
chebi_grounder = get_grounder("chebi")
8083

81-
path = ensure_path(PREFIX, url=URL)
84+
path = ensure_path(PREFIX, url=URL, version=VERSION)
8285
df = pd.read_excel(path, sheet_name="Full database", dtype=str, skiprows=1)
86+
# TODO group by CAS number and add alt-id annotations
8387
for _, row in df.iterrows():
8488
if pd.isna(row["plastchem_ID"]):
8589
continue
@@ -120,6 +124,8 @@ def get_terms() -> Iterable[Term]:
120124
elif match := chebi_grounder.get_best_match(echa_grouping.rstrip("s")):
121125
echa_examples[echa_grouping] = match.curie, match.name
122126

127+
# TODO add hazard lists?
128+
123129
# NIAS means non-intentionally added substance
124130
for func in _get_sep(row, "Harmonized_functions"):
125131
func = func.replace("_", " ").lower()
@@ -223,11 +229,11 @@ def get_terms() -> Iterable[Term]:
223229
}
224230

225231

226-
def _get_sep(row, key):
232+
def _get_sep(row: dict[str, Any], key: str) -> list[str]:
227233
if pd.notna(row[key]):
228234
return row[key].split(";")
229235
return []
230236

231237

232238
if __name__ == "__main__":
233-
PlastChemGetter.cli()
239+
PlastChemGetter.cli(["--owl", "--obo", "--force"])

0 commit comments

Comments
 (0)