Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 14 additions & 49 deletions pyenzyme/fetcher/chebi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
ChEBI database by ID and map it to the PyEnzyme data model (v2).
"""

import requests
import re
from typing import Optional, Dict, List
from pydantic import BaseModel, Field, RootModel
from typing import Dict, List, Optional

import requests
from pydantic import BaseModel, ConfigDict, RootModel

from pyenzyme.versions import v2


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


class ChEBIName(BaseModel):
"""Individual name/synonym entry."""

name: str
status: str
type: str
source: str
ascii_name: str
adapted: bool
language_code: str


class ChEBINames(BaseModel):
"""Names and synonyms structure. All name types are optional."""

SYNONYM: Optional[List[ChEBIName]] = None
IUPAC_NAME: Optional[List[ChEBIName]] = Field(None, alias="IUPAC NAME")
INN: Optional[List[ChEBIName]] = None


class ChEBIChemicalData(BaseModel):
"""Chemical formula and mass data."""

formula: str
charge: int
mass: str
monoisotopic_mass: str


class ChEBIStructure(BaseModel):
"""Chemical structure information. All structure fields may be null."""
"""Chemical structure information."""

model_config = ConfigDict(extra="ignore")

id: int
smiles: Optional[str] = None
standard_inchi: Optional[str] = None
standard_inchi_key: Optional[str] = None
wurcs: Optional[str] = None
is_r_group: bool


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

id: int
chebi_accession: str
name: str
model_config = ConfigDict(extra="ignore")

ascii_name: str
stars: int
definition: str
names: ChEBINames
chemical_data: ChEBIChemicalData
default_structure: Optional[ChEBIStructure] = None
modified_on: str
secondary_ids: List[str]
is_released: bool


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

model_config = ConfigDict(extra="ignore")

standardized_chebi_id: str
primary_chebi_id: str
exists: bool
id_type: str
data: ChEBIEntryData


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

model_config = ConfigDict(extra="ignore")

_source: Dict[str, str] # Contains chebi_accession field


Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from pyenzyme.fetcher.chebi import fetch_chebi
from pyenzyme.fetcher.pdb import fetch_pdb
from pyenzyme.fetcher.pubchem import fetch_pubchem
Expand All @@ -22,6 +23,9 @@ def test_fetch_chebi_to_small_molecule(self):
== "https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:15377"
)

def test_fetch_chebi_wo_defintion(self):
fetch_rhea("RHEA:75423", vessel_id="v0")

def test_fetch_chebi_to_small_molecule_with_id(self):
small_molecule = fetch_chebi("CHEBI:15377", smallmol_id="s1")
assert small_molecule is not None
Expand Down