# 17.1.1.3.2.3. cobra.io.mat¶

Helpers to interface with Matlab models.

## 17.1.1.3.2.3.1. Module Contents¶

### 17.1.1.3.2.3.1.1. Functions¶

 Extract the compartment from the id string. Translate an array x into a MATLAB cell array. load_matlab_model(infile_path, variable_name=None, inf=inf) Load a cobra model stored as a .mat file. save_matlab_model(model, file_name, varname=None) Save the cobra model as a .mat file. Obtain a metabolite id from a Matlab model. create_mat_dict(model) Create a dict mapping model attributes to arrays. from_mat_struct(mat_struct, model_id=None, inf=inf) Create a model from the COBRA toolbox struct. _check(result) Ensure success of a pymatbridge operation. model_to_pymatbridge(model, variable_name=’model’, matlab=None) Send the model to a MATLAB workspace through pymatbridge.
cobra.io.mat.scipy_sparse[source]
cobra.io.mat._bracket_re[source]
cobra.io.mat._underscore_re[source]
cobra.io.mat._get_id_compartment(id)[source]

Extract the compartment from the id string.

cobra.io.mat._cell(x)[source]

Translate an array x into a MATLAB cell array.

cobra.io.mat.load_matlab_model(infile_path, variable_name=None, inf=inf)[source]

Load a cobra model stored as a .mat file.

Parameters
• infile_path (str) – path to the file to to read

• variable_name (str, optional) – The variable name of the model in the .mat file. If this is not specified, then the first MATLAB variable which looks like a COBRA model will be used

• inf (value) – 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.

Returns

The resulting cobra model

Return type

cobra.core.Model.Model

cobra.io.mat.save_matlab_model(model, file_name, varname=None)[source]

Save the cobra model as a .mat file.

This .mat file can be used directly in the MATLAB version of COBRA.

Parameters
• model (cobra.core.Model.Model object) – The model to save

• file_name (str or file-like object) – The file to save to

• varname (string) – The name of the variable within the workspace

cobra.io.mat.create_mat_metabolite_id(model)[source]

Obtain a metabolite id from a Matlab model.

cobra.io.mat.create_mat_dict(model)[source]

Create a dict mapping model attributes to arrays.

cobra.io.mat.from_mat_struct(mat_struct, model_id=None, inf=inf)[source]

Create a model from the COBRA toolbox struct.

The struct will be a dict read in by scipy.io.loadmat

cobra.io.mat._check(result)[source]

Ensure success of a pymatbridge operation.

cobra.io.mat.model_to_pymatbridge(model, variable_name='model', matlab=None)[source]

Send the model to a MATLAB workspace through pymatbridge.

This model can then be manipulated through the COBRA toolbox

Parameters
• variable_name (str) – The variable name to which the model will be assigned in the MATLAB workspace

• matlab (None or pymatbridge.Matlab instance) – The MATLAB workspace to which the variable will be sent. If this is None, then this will be sent to the same environment used in IPython magics.