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.

Source code in vpeleaderboard/data/src/basico_model.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class BasicoModel(SysBioModel):
    """
    Model that loads SBML models using the basico package.
    """
    sbml_file_path: Optional[str] = Field(None, description="Path to an SBML files folder")
    simulation_results: Optional[pd.DataFrame] = None
    name: Optional[str] = Field("", description="Name of the model")
    description: Optional[str] = Field("", description="Description of the model")

    copasi_model: Optional[object] = None
    model_config = {"arbitrary_types_allowed": True}

    @model_validator(mode="after")
    def validate_sbml_file_path(self):
        """
        Validate that the SBML folder exists and contains XML files.

        Args:
            sbml_file_path (str): The path to the SBML folder.

        Returns:
            ModelData: The validated instance of the class.

        Raises:
            ValueError: If the folder path is missing or does not contain XML files.
        """
        if not self.sbml_file_path:
            raise ValueError("SBML folder path must be provided.")

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

        xml_files = [f for f in os.listdir(self.sbml_file_path) if f.endswith(".xml")]
        if not xml_files:
            raise ValueError(f"No SBML files found in {self.sbml_file_path}.")
        return self

    def get_model_metadata(self, sbml_file: str) -> Dict[str, Union[str, int]]:
        """
        Retrieve metadata for a single SBML model.

        Args:
            sbml_file (str): The name of the SBML file in the folder.

        Returns:
            Dict[str, Union[str, int]]: A dictionary containing metadata of the SBML model.
        """
        file_path = os.path.join(self.sbml_file_path, sbml_file)
        copasi_model = basico.load_model(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(sbml_file)

Retrieve metadata for a single SBML model.

Parameters:

Name Type Description Default
sbml_file str

The name of the SBML file in the folder.

required

Returns:

Type Description
Dict[str, Union[str, int]]

Dict[str, Union[str, int]]: A dictionary containing metadata of the SBML model.

Source code in vpeleaderboard/data/src/basico_model.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def get_model_metadata(self, sbml_file: str) -> Dict[str, Union[str, int]]:
    """
    Retrieve metadata for a single SBML model.

    Args:
        sbml_file (str): The name of the SBML file in the folder.

    Returns:
        Dict[str, Union[str, int]]: A dictionary containing metadata of the SBML model.
    """
    file_path = os.path.join(self.sbml_file_path, sbml_file)
    copasi_model = basico.load_model(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.

Parameters:

Name Type Description Default
sbml_file_path str

The path to the SBML folder.

required

Returns:

Name Type Description
ModelData

The validated instance of the class.

Raises:

Type Description
ValueError

If the folder path is missing or does not contain XML files.

Source code in vpeleaderboard/data/src/basico_model.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@model_validator(mode="after")
def validate_sbml_file_path(self):
    """
    Validate that the SBML folder exists and contains XML files.

    Args:
        sbml_file_path (str): The path to the SBML folder.

    Returns:
        ModelData: The validated instance of the class.

    Raises:
        ValueError: If the folder path is missing or does not contain XML files.
    """
    if not self.sbml_file_path:
        raise ValueError("SBML folder path must be provided.")

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

    xml_files = [f for f in os.listdir(self.sbml_file_path) if f.endswith(".xml")]
    if not xml_files:
        raise ValueError(f"No SBML files found in {self.sbml_file_path}.")
    return self