22
33from collections import Counter
44from collections .abc import Iterable
5+ from typing import Any
56
67import pandas as pd
78from tabulate import tabulate
1920from pyobo .utils .path import ensure_path
2021
2122__all__ = ["PlastChemGetter" ]
23+
2224PREFIX = "plastchem"
2325URL = "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
2629HAZARD_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
232238if __name__ == "__main__" :
233- PlastChemGetter .cli ()
239+ PlastChemGetter .cli ([ "--owl" , "--obo" , "--force" ] )
0 commit comments