This example demonstrates using COBRA toolbox commands in MATLAB from python through pymatbridge.
In [1]:
%load_ext pymatbridge
In [2]:
import cobra.test
m = cobra.test.create_test_model("textbook")
The model_to_pymatbridge function will send the model to the workspace with the given variable name.
In [3]:
from cobra.io.mat import model_to_pymatbridge
model_to_pymatbridge(m, variable_name="model")
Now in the MATLAB workspace, the variable name 'model' holds a COBRA toolbox struct encoding the model.
In [4]:
%%matlab
model
First, we have to initialize the COBRA toolbox in MATLAB.
In [5]:
%%matlab --silent
warning('off'); % this works around a pymatbridge bug
addpath(genpath('~/cobratoolbox/'));
initCobraToolbox();
Commands from the COBRA toolbox can now be run on the model
In [6]:
%%matlab
optimizeCbModel(model)
FBA in the COBRA toolbox should give the same result as cobrapy
In [7]:
%time
m.optimize().f
Out[7]: