# HG changeset patch # User luca_milaz # Date 1720454368 0 # Node ID 29bda13a88a97c42a4b96ea3cd1b659536011ab1 # Parent 58a61b3ebda724fed02c8e1806aa2e3adeb9cd1a Uploaded diff -r 58a61b3ebda7 -r 29bda13a88a9 marea_2_0/marea.xml diff -r 58a61b3ebda7 -r 29bda13a88a9 marea_2_0/model_generator.py --- a/marea_2_0/model_generator.py Mon Jul 08 15:54:21 2024 +0000 +++ b/marea_2_0/model_generator.py Mon Jul 08 15:59:28 2024 +0000 @@ -83,7 +83,7 @@ dataset.to_csv(ARGS.output_folder + name + ".csv", sep = '\t', index = keep_index) -def generate_model(model, cell_name, ras, medium, output_model_format)->cobra.: +def generate_model(model, cell_name, ras, medium, output_model_format): model_new = model.copy() rxns_ids = [] for rxn in model.reactions: diff -r 58a61b3ebda7 -r 29bda13a88a9 marea_2_0/ras_generator.xml --- a/marea_2_0/ras_generator.xml Mon Jul 08 15:54:21 2024 +0000 +++ b/marea_2_0/ras_generator.xml Mon Jul 08 15:59:28 2024 +0000 @@ -9,7 +9,6 @@ lxml svglib reportlab - cobra marea_macros.xml - cobra pandas lxml numpy diff -r 58a61b3ebda7 -r 29bda13a88a9 marea_2_0/utils/cobra_utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marea_2_0/utils/cobra_utils.py Mon Jul 08 15:59:28 2024 +0000 @@ -0,0 +1,33 @@ +import cobra + +def getCOBRAmodel(self, toolDir = ".", customPath :Optional[FilePath] = None, customExtension :Optional[FilePath]=None)->cobra.Model: + if(self is Model.Custom): + return self.load_custom_model(customPath, customExtension) + else: + return cobra.io.read_sbml_model(FilePath(f"{self.name}", FileFormat.XML, prefix = f"{toolDir}/local/COBRA models/").show()) + +def load_custom_model(self, file_path :FilePath, ext :Optional[FileFormat] = None) -> cobra.Model: + """ + Loads a custom model from a file, either in JSON or XML format. + + Args: + file_path : The path to the file containing the custom model. + ext : explicit file extension. Necessary for standard use in galaxy because of its weird behaviour. + + Raises: + DataErr : if the file is in an invalid format or cannot be opened for whatever reason. + + Returns: + cobra.Model : the model, if successfully opened. + """ + ext = ext if ext else file_path.ext + try: + if ext is FileFormat.XML: + return cobra.io.read_sbml_model(file_path.show()) + + if ext is FileFormat.JSON: + return cobra.io.load_json_model(file_path.show()) + + except Exception as e: raise DataErr(file_path, e.__str__()) + raise DataErr(file_path, + f"Fomat \"{file_path.ext}\" is not recognized, only JSON and XML files are supported.") \ No newline at end of file diff -r 58a61b3ebda7 -r 29bda13a88a9 marea_2_0/utils/general_utils.py --- a/marea_2_0/utils/general_utils.py Mon Jul 08 15:54:21 2024 +0000 +++ b/marea_2_0/utils/general_utils.py Mon Jul 08 15:59:28 2024 +0000 @@ -4,7 +4,6 @@ import csv import pickle import lxml.etree as ET -import cobra from enum import Enum from itertools import count @@ -548,37 +547,5 @@ path = customPath if self is Model.Custom else FilePath(f"{self.name}_map", FileFormat.SVG, prefix = f"{toolDir}/local/svg metabolic maps/") self.__raiseMissingPathErr(path) return readSvg(path, customErr = DataErr(path, f"custom map in wrong format")) - - def getCOBRAmodel(self, toolDir = ".", customPath :Optional[FilePath] = None, customExtension :Optional[FilePath]=None)->cobra.Model: - if(self is Model.Custom): - return self.load_custom_model(customPath, customExtension) - else: - return cobra.io.read_sbml_model(FilePath(f"{self.name}", FileFormat.XML, prefix = f"{toolDir}/local/COBRA models/").show()) - - def load_custom_model(self, file_path :FilePath, ext :Optional[FileFormat] = None) -> cobra.Model: - """ - Loads a custom model from a file, either in JSON or XML format. - - Args: - file_path : The path to the file containing the custom model. - ext : explicit file extension. Necessary for standard use in galaxy because of its weird behaviour. - - Raises: - DataErr : if the file is in an invalid format or cannot be opened for whatever reason. - - Returns: - cobra.Model : the model, if successfully opened. - """ - ext = ext if ext else file_path.ext - try: - if ext is FileFormat.XML: - return cobra.io.read_sbml_model(file_path.show()) - - if ext is FileFormat.JSON: - return cobra.io.load_json_model(file_path.show()) - - except Exception as e: raise DataErr(file_path, e.__str__()) - raise DataErr(file_path, - f"Fomat \"{file_path.ext}\" is not recognized, only JSON and XML files are supported.") def __str__(self) -> str: return self.value \ No newline at end of file