cobra.io.mat#
Provide functions for I/O in MATLAB (.mat) format.
Attributes#
Functions#
|
Extract the compartment from the id string. |
|
Translate an iterable x into a MATLAB cell array. |
|
Turn an ndarray (cell) to a list of strings. |
|
Turn an ndarray (cell) to a list of floats. |
|
Load a cobra model stored as a .mat file. |
|
Save the cobra model as a .mat file. |
|
Process mat structure annotations in place. |
|
Process mat structure notes in place. |
|
Process mat structure annotations in place. |
|
Process mat structure notes in place. |
|
Create a dictionary mapping model attributes to arrays. |
|
Create a model from the cobratoolbox struct. |
Module Contents#
- cobra.io.mat.scipy_sparse = None#
- cobra.io.mat.logger#
- cobra.io.mat.MET_MATLAB_TO_PROVIDERS#
- cobra.io.mat.MET_PROVIDERS_TO_MATLAB#
- cobra.io.mat.MET_NOTES_TO_MATLAB#
- cobra.io.mat.MET_MATLAB_TO_NOTES#
- cobra.io.mat.RXN_MATLAB_TO_PROVIDERS#
- cobra.io.mat.RXN_PROVIDERS_TO_MATLAB#
- cobra.io.mat.CONFIDENCE_STR = 'Confidence Level'#
- cobra.io.mat.RXN_MATLAB_TO_NOTES#
- cobra.io.mat.RXN_NOTES_TO_MATLAB#
- cobra.io.mat.GENE_MATLAB_TO_PROVIDERS#
- cobra.io.mat.GENE_PROVIDERS_TO_MATLAB#
- cobra.io.mat.DICT_GENE = 'DICT_GENE'#
- cobra.io.mat.DICT_GENE_REV = 'DICT_GENE_REV'#
- cobra.io.mat.DICT_MET = 'DICT_MET'#
- cobra.io.mat.DICT_MET_REV = 'DICT_MET_REV'#
- cobra.io.mat.DICT_MET_NOTES = 'DICT_MET_NOTES'#
- cobra.io.mat.DICT_MET_NOTES_REV = 'DICT_MET_NOTES_REV'#
- cobra.io.mat.DICT_REACTION = 'DICT_REACTION'#
- cobra.io.mat.DICT_REACTION_REV = 'DICT_REACTION_REV'#
- cobra.io.mat.DICT_REACTION_NOTES = 'DICT_REACTION_NOTES'#
- cobra.io.mat.DICT_REACTION_NOTES_REV = 'DICT_REACTION_NOTES_REV'#
- cobra.io.mat._bracket_re#
- cobra.io.mat._underscore_re#
- cobra.io.mat._pubmed_re#
- cobra.io.mat._punctuation_re#
- cobra.io.mat._double_punctuation_re#
- cobra.io.mat._ec_re#
- cobra.io.mat._chebi_re#
- cobra.io.mat._sbo_re#
- cobra.io.mat._cell(x: Iterable[str]) numpy.ndarray[source]#
Translate an iterable x into a MATLAB cell array.
- Parameters:
x (iterable of str) – The data iterable to convert to cell array.
- Returns:
The converted cell array compatible with MATLAB.
- Return type:
- cobra.io.mat._cell_to_str_list(m_cell: numpy.ndarray, empty_value: str | None = None, pattern_split: Pattern | None = None, str_prefix: str = '') List[source]#
Turn an ndarray (cell) to a list of strings.
- Parameters:
m_cell (np.ndarray)
empty_value (str, optional) – What value to replace empty cells with. Default None.
pattern_split (Pattern, optional) – Regular expression to use to split the expression. Used for annotations. Default None.
str_prefix (str, optional) – A prefix that will be added to each value in the list if present. Default “”.
- Returns:
A list of processed strings.
- Return type:
List
- cobra.io.mat._cell_to_float_list(m_cell: numpy.ndarray, empty_value: float | None = None, inf_value: float | None = None) List[source]#
Turn an ndarray (cell) to a list of floats.
- Parameters:
- Returns:
A list of processed floats.
- Return type:
List
- cobra.io.mat.load_matlab_model(infile_path: str | pathlib.Path | IO, variable_name: str | None = None, inf: float = np.inf) cobra.core.Model[source]#
Load a cobra model stored as a .mat file.
- Parameters:
infile_path (str or Path or filehandle) – File path or descriptor of the .mat file describing the cobra model.
variable_name (str, optional) – The variable name of the model in the .mat file. If None, then the first MATLAB variable which looks like a COBRA model will be used (default None).
inf (float, optional) – The value to use for infinite bounds. Some solvers do not handle infinite values so for using those, set this to a high numeric value (default numpy.inf).
- Returns:
The cobra model as represented in the .mat file.
- Return type:
- Raises:
ImportError – If scipy is not found in the Python environment.
IOError – If no COBRA model is found in the .mat file.
- cobra.io.mat.save_matlab_model(model: cobra.core.Model, file_name: str | pathlib.Path | IO, varname: str | None = None) None[source]#
Save the cobra model as a .mat file.
This .mat file can be used directly in cobratoolbox.
- Parameters:
model (cobra.Model) – The cobra model to represent.
file_name (str or file-like or Path) – File path or descriptor that the MATLAB representation should be written to.
varname (str, optional) – The name of the variable within the MATLAB workspace. Model ID is used if available, else ‘exported_model’ is used (default None).
- cobra.io.mat.mat_parse_annotations(target_list: List[cobra.core.Object], mat_struct: numpy.ndarray, d_replace: str = DICT_MET) None[source]#
Process mat structure annotations in place.
Will process mat structured annotations and add them to a list of new entities (metabolites, reactions, genes) in a format based on identifiers.org.
- Parameters:
target_list (list[cobra.Object]) – A list of cobra objects, including metabolites, reactions or genes. The annotations will be added to these lists.
mat_struct (np.ndarray) – A darray that includes the data imported from matlab file.
d_replace (str) – A string that points to the dictionary of converstions between MATLAB and providers. Default DICT_MET (for metabolite).
- cobra.io.mat.mat_parse_notes(target_list: List[cobra.core.Object], mat_struct: numpy.ndarray, d_replace: str = DICT_REACTION_NOTES) None[source]#
Process mat structure notes in place.
Will process mat structured notes and add them to a list of new entities (metabolites, reactions, genes) in a format based on identifiers.org.
- Parameters:
target_list (list[cobra.Object]) – A list of cobra objects, including metabolites, reactions or genes. The notes will be added to these lists.
mat_struct (np.ndarray) – A darray that includes the data imported from matlab file.
d_replace (str) – A string that points to the dictionary of converstions between MATLAB and notes. Default DICT_REACTION_NOTES (for reactions).
- cobra.io.mat.annotations_to_mat(mat_dict: collections.OrderedDict, annotation_list: List[Dict], d_replace: str = DICT_MET_REV) None[source]#
Process mat structure annotations in place.
Will process mat structured annotations and add them to a list of new entities (metabolites, reactions, genes) in a format based on identifiers.org.
- Parameters:
mat_dict (OrderedDict) – An ordered dictionary having model attributes as keys and their respective values represented as arrays, as the values. Annotations will be inserted into this OrderdDict.
annotation_list (list[Dict]) – A list of cobra annotations, in the form of a dictionary.
d_replace (str) – A string that points to the dictionary of converstions between MATLAB and providers. Default DICT_MET_REV (for metabolite).
- cobra.io.mat.notes_to_mat(mat_dict: collections.OrderedDict, note_list: List[Dict], d_replace: str = DICT_MET_REV) None[source]#
Process mat structure notes in place.
Will process mat structured annotations and add them to a list of new entities (metabolites, reactions, genes) in a format based on identifiers.org.
- Parameters:
mat_dict (OrderedDict) – An ordered dictionary having model attributes as keys and their respective values represented as arrays, as the values. Annotations will be inserted into this OrderdDict.
note_list (list[Dict]) – A list of cobra annotations, in the form of a dictionary.
d_replace (str) – A string that points to the dictionary of converstions between MATLAB and providers. Default DICT_MET_REV (for metabolite).
- cobra.io.mat.create_mat_dict(model: cobra.core.Model) collections.OrderedDict[source]#
Create a dictionary mapping model attributes to arrays.
- Parameters:
model (cobra.Model) – The model to create dictionary for.
- Returns:
The ordered dictionary having model attributes as keys and their respective values represented as arrays, as the values.
- Return type:
OrderedDict
- cobra.io.mat.from_mat_struct(mat_struct: numpy.ndarray, model_id: str | None = None, inf: float = np.inf) cobra.core.Model[source]#
Create a model from the cobratoolbox struct.
- Parameters:
mat_struct (numpy.ndarray) – The numpy.ndarray that most likely contains the model, being chosen by load_matlab_file after loading the matlab structure via scipy_io.loadmat.
model_id (str, optional) – The ID of the model generated. If None, will try to look for ID in model’s description. If multiple IDs are found, the first one is used. If no IDs are found, will use ‘imported_model’ (default None).
inf (float, optional) – The value to use for infinite bounds. Some solvers do not handle infinite values so for using those, set this to a high numeric value (default numpy.inf).
- Returns:
The model as represented in .mat file.
- Return type: