[3af7d7]: / aiagents4pharma / talk2biomodels / tools / load_biomodel.py

Download this file

39 lines (33 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
"""
Function for loading the BioModel.
"""
from typing import Annotated, Any, Union
from pydantic import BaseModel, BeforeValidator
from ..models.basico_model import BasicoModel
def ensure_biomodel_id(value: Any) -> Any:
"""
Ensure that the biomodel_id is an integer or a string starting with 'BIOMD' or 'MODEL'.
"""
if isinstance(value, int):
return value
if isinstance(value, str) and (value.startswith("BIOMD") or value.startswith("MODEL")):
return value
raise ValueError("biomodel_id must be an integer or a string starting with 'BIOMD' or 'MODEL'.")
class ModelData(BaseModel):
"""
Base model for the model data.
"""
biomodel_id: Annotated[Union[int, str], BeforeValidator(ensure_biomodel_id)] = None
# sbml_file_path: Optional[str] = None
use_uploaded_sbml_file: bool = False
def load_biomodel(sys_bio_model, sbml_file_path=None):
"""
Load the BioModel.
"""
model_object = None
if sys_bio_model.biomodel_id:
model_object = BasicoModel(biomodel_id=sys_bio_model.biomodel_id)
elif sbml_file_path:
model_object = BasicoModel(sbml_file_path=sbml_file_path)
return model_object