Skip to content

Commit 1c13e47

Browse files
authored
Merge pull request #95 from EnzymeML/94-fetch-rhea-for-23-butanediol-dehydrogenase-fails
Refactor ChEBI models to ignore extra fields
2 parents a0fde0f + 77d9979 commit 1c13e47

2 files changed

Lines changed: 18 additions & 49 deletions

File tree

pyenzyme/fetcher/chebi.py

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
ChEBI database by ID and map it to the PyEnzyme data model (v2).
66
"""
77

8-
import requests
98
import re
10-
from typing import Optional, Dict, List
11-
from pydantic import BaseModel, Field, RootModel
9+
from typing import Dict, List, Optional
10+
11+
import requests
12+
from pydantic import BaseModel, ConfigDict, RootModel
13+
1214
from pyenzyme.versions import v2
1315

1416

@@ -20,70 +22,31 @@ def __init__(self, message: str, cause: Optional[Exception] = None):
2022
self.cause = cause
2123

2224

23-
class ChEBIName(BaseModel):
24-
"""Individual name/synonym entry."""
25-
26-
name: str
27-
status: str
28-
type: str
29-
source: str
30-
ascii_name: str
31-
adapted: bool
32-
language_code: str
33-
34-
35-
class ChEBINames(BaseModel):
36-
"""Names and synonyms structure. All name types are optional."""
37-
38-
SYNONYM: Optional[List[ChEBIName]] = None
39-
IUPAC_NAME: Optional[List[ChEBIName]] = Field(None, alias="IUPAC NAME")
40-
INN: Optional[List[ChEBIName]] = None
41-
42-
43-
class ChEBIChemicalData(BaseModel):
44-
"""Chemical formula and mass data."""
45-
46-
formula: str
47-
charge: int
48-
mass: str
49-
monoisotopic_mass: str
50-
51-
5225
class ChEBIStructure(BaseModel):
53-
"""Chemical structure information. All structure fields may be null."""
26+
"""Chemical structure information."""
27+
28+
model_config = ConfigDict(extra="ignore")
5429

55-
id: int
5630
smiles: Optional[str] = None
5731
standard_inchi: Optional[str] = None
5832
standard_inchi_key: Optional[str] = None
59-
wurcs: Optional[str] = None
60-
is_r_group: bool
6133

6234

6335
class ChEBIEntryData(BaseModel):
6436
"""Core data structure for a ChEBI entry."""
6537

66-
id: int
67-
chebi_accession: str
68-
name: str
38+
model_config = ConfigDict(extra="ignore")
39+
6940
ascii_name: str
70-
stars: int
71-
definition: str
72-
names: ChEBINames
73-
chemical_data: ChEBIChemicalData
7441
default_structure: Optional[ChEBIStructure] = None
75-
modified_on: str
76-
secondary_ids: List[str]
77-
is_released: bool
7842

7943

8044
class ChEBIEntryResult(BaseModel):
8145
"""Individual ChEBI entry result."""
8246

47+
model_config = ConfigDict(extra="ignore")
48+
8349
standardized_chebi_id: str
84-
primary_chebi_id: str
85-
exists: bool
86-
id_type: str
8750
data: ChEBIEntryData
8851

8952

@@ -96,6 +59,8 @@ class ChEBIApiResponse(RootModel[Dict[str, ChEBIEntryResult]]):
9659
class ChebiSearchResult(BaseModel):
9760
"""Individual search result structure."""
9861

62+
model_config = ConfigDict(extra="ignore")
63+
9964
_source: Dict[str, str] # Contains chebi_accession field
10065

10166

tests/integration/test_fetcher.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from pyenzyme.fetcher.chebi import fetch_chebi
34
from pyenzyme.fetcher.pdb import fetch_pdb
45
from pyenzyme.fetcher.pubchem import fetch_pubchem
@@ -22,6 +23,9 @@ def test_fetch_chebi_to_small_molecule(self):
2223
== "https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:15377"
2324
)
2425

26+
def test_fetch_chebi_wo_defintion(self):
27+
fetch_rhea("RHEA:75423", vessel_id="v0")
28+
2529
def test_fetch_chebi_to_small_molecule_with_id(self):
2630
small_molecule = fetch_chebi("CHEBI:15377", smallmol_id="s1")
2731
assert small_molecule is not None

0 commit comments

Comments
 (0)