Skip to content

Basico Model

BasicoModel class for loading SBML models using the basico package.

BasicoModel

Bases: SysBioModel

Model that loads SBML models using the basico package. Ensures a single instance per component.

Source code in vpeleaderboard/data/src/basico_model.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class BasicoModel(SysBioModel):
    """
    Model that loads SBML models using the basico package.
    Ensures a single instance per component.
    """
    sbml_file_path: str = Field(..., description="Path to an SBML file ")
    simulation_results: Optional[Any] = Field(None, exclude=True)
    name: Optional[str] = ""
    description: Optional[str] = ""
    copasi_model: Optional[object] = Field(None, exclude=True)

    def __init__(self, sbml_file_path: str ,
                 name: Optional[str] = "", description: Optional[str] = ""):
        super().__init__(sbml_file_path=sbml_file_path,
                         name=name, description=description)
        # sbml_file_path = os.path.abspath(sbml_file_path)
        self.sbml_file_path = sbml_file_path
        self.validate_sbml_file_path()

    def validate_sbml_file_path(self):
        """
        Validate that the SBML folder exists and contains XML files.
        """
        if not self.sbml_file_path:
            raise ValueError("SBML file must be provided.")

        if not os.path.exists(self.sbml_file_path):
            raise ValueError(f"SBML file not found: {self.sbml_file_path}")

    def get_model_metadata(self) -> Dict[str, Union[str, int]]:
        """
        Retrieve metadata for a single SBML model.
        """
        # file_path = os.path.join(self.sbml_file_path)
        copasi_model = basico.load_model(self.sbml_file_path)
        model_name = basico.model_info.get_model_name(model=copasi_model)
        species_count = len(basico.model_info.get_species(model=copasi_model))
        parameter_count = len(basico.model_info.get_parameters(model=copasi_model))
        model_description = basico.model_info.get_notes(model=copasi_model)

        return {
            "Model Name": model_name,
            "Number of Species": species_count,
            "Number of Parameters": parameter_count,
            "Description": model_description.strip()

        }

get_model_metadata()

Retrieve metadata for a single SBML model.

Source code in vpeleaderboard/data/src/basico_model.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def get_model_metadata(self) -> Dict[str, Union[str, int]]:
    """
    Retrieve metadata for a single SBML model.
    """
    # file_path = os.path.join(self.sbml_file_path)
    copasi_model = basico.load_model(self.sbml_file_path)
    model_name = basico.model_info.get_model_name(model=copasi_model)
    species_count = len(basico.model_info.get_species(model=copasi_model))
    parameter_count = len(basico.model_info.get_parameters(model=copasi_model))
    model_description = basico.model_info.get_notes(model=copasi_model)

    return {
        "Model Name": model_name,
        "Number of Species": species_count,
        "Number of Parameters": parameter_count,
        "Description": model_description.strip()

    }

validate_sbml_file_path()

Validate that the SBML folder exists and contains XML files.

Source code in vpeleaderboard/data/src/basico_model.py
36
37
38
39
40
41
42
43
44
def validate_sbml_file_path(self):
    """
    Validate that the SBML folder exists and contains XML files.
    """
    if not self.sbml_file_path:
        raise ValueError("SBML file must be provided.")

    if not os.path.exists(self.sbml_file_path):
        raise ValueError(f"SBML file not found: {self.sbml_file_path}")