Io¶
- convertCNAModelToCbModel(cnaModel, printLevel)[source]¶
Function uses the CNAcna2cobra from CellNetAnalyzer to convert a CNA model to a COBRA model
- USAGE
model = convertCNAModelToCbModel (cnaModel, printLevel)
- INPUT
cnaModel – CNA mass-flow project structure
printLevel – verbose level (default: 1)
- OUTPUT
model – COBRA model structure
Note
This functions requires a working installation of CellNetAnalyzer which can be downloaded from https://www2.mpi-magdeburg.mpg.de/projects/cna/cna.html
- convertCbModelToCNAModel(model, printLevel)[source]¶
Function uses the CNAcobra2cna from CellNetAnalyzer to convert a COBRA model to a CNA model
- USAGE
cnaModel = convertCNAModelToCbModel (model, printLevel)
- INPUT
model – COBRA model structure
printLevel – verbose level (default: 1)
- OUTPUT
cnaModel – cnaModel is a CNA mass-flow project structure
Note
This functions requires a working installation of CellNetAnalyzer which can be downloaded from https://www2.mpi-magdeburg.mpg.de/projects/cna/cna.html
- convertCobraLP2mps(LPProblem, name)[source]¶
Creates an MPS (Mathematical Programming System) format ascii file representing the Linear Programming problem given by LPProblem.
- USAGE
OK = convertCobraLP2mps (LPProblem, name)
- INPUT
LPproblem – Structure containing the following fields describing the LP problem to be solved
.A - LHS matrix
.b - RHS vector
.c - Objective coeff vector
.lb - Lower bound vector
.ub - Upper bound vector
.osense - Objective sense (max=-1, min=+1)
.csense - Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
- OPTIONAL INPUT
name – string giving name of LP problem
- OUTPUT
OK – 1 if saving is success, 0 otherwise
- convertModelToEX(model, filename, rxnzero, EXrxns)[source]¶
Converts a Matlab Model to XPA format
- USAGE
convertModelToEX (model, filename, rxnzero, EXrxns)
- INPUTS
model – Model Structure
filename – Filename of Output File (make sure to include ‘.txt’ or ‘.xpa’)
rxnzero – Matrix containing all no flux var rxns (to skip, set=0)
- OPTIONAL INPUT
EXrxns – Exchange reactions
Limitations
Works properly with only integer value reaction coeff. (except for .5 or -.5). Other non-integer value coeff. have to be edited manually
Exchange reactions have to be clumped together in model
If using rxnzero, make sure that EX reactions contain no compounds that are not used in the uncommented reactions
- readCbModel(fileName, varargin)[source]¶
Reads in a constraint-based model. If no arguments are passed to the function, the user will be prompted for a file name. While some fields are necessary for a COBRA model, others are not.
The readCbModel.m function is dependent on another function io/utilities/readSBML.m to use libSBML library (http://sbml.org/Software/libSBML), to parse a SBML-FBCv2 file into a COBRA-Matlab structure. The readCbModel.m function is backward compatible with older SBML versions. A list of fields of a COBRA structure is described in https://github.com/opencobra/cobratoolbox/blob/master/docs/source/notes/COBRAModelFields.md and defined computationally in: src/base/io/definitions/COBRA_structure_fields.tab
- USAGE
model = readCbModel (fileName, varargin)
- OPTIONAL INPUTS
fileName – File name for file to read in (char)
varargin – Optional values as ‘ParameterName’,value pairs with the following available parameters: - fileType: File type for input files: ‘SBML’, ‘SimPheny’,
- ‘SimPhenyPlus’, ‘SimPhenyText’, ‘Matlab’, ‘BiGG’, ‘BiGGSBML’ or ‘Excel’ (Default = ‘Matlab’)
‘SBML’ indicates a file in SBML format
‘SimPheny’ is a set of three files in SimPheny simulation output format
‘SimPhenyPlus’ is the same as ‘SimPheny’ except with additional files containing gene-protein-reaction associations andcompound information
‘SimPhenyText’ is the same as ‘SimPheny’ except with additionaltext file containing gene-protein-reaction associations
Matlab will save the model as a matlab variable file.
BiGG and BIGGSBML indicate that the fileName is a BiGG Model identifier and that the model should be loaded from the BiGG database (requires an Internet connection). BiGG loads it from the BiGG Database mat file, BiGGSBML uses the SBML file.
Excel will save the model as a two sheet Excel Model.
modelDescription: Description of model contents (char), default is the choosen filename
compSymbolList: Compartment Symbol List( cell array)
defaultBound: The default bound value (default 1000)
modelName: .mat file specific identifier, if provided, the specified model (if valid) will be loaded from the given mat file. If not given, the file will be scanned for models and all potential model structs will be provided as options to select from. (default: ‘all’)
- OUTPUT
model – Returns a model in the COBRA format with at least the following fields:
.description - Description of model contents
.rxns - Reaction names
.mets - Metabolite names
.S - Stoichiometric matrix
.lb - Lower bounds
.ub - Upper bounds
.c - Objective coefficients
.osenseStr - the objective sense (‘max’ or
‘min’) * .csense - the constraint senses (‘L’ for
lower than, ‘G’ - greated than, ‘E’ - equal)
.rules - Gene-reaction association rule in computable form
.genes - List of all genes
Examples
- %1) Load a file to be specified in a dialog box:
model = readCbModel;
%2) Load model named ‘iJR904’ in SBML format with maximum flux set %at 1000 (requires file named ‘iJR904.xml’ to exist)
model = readCbModel(‘iJR904’,’fileType’,’SBML’,’defaultBound’, 1000);
%3) Load model named ‘iJR904’ in SimPheny format with maximum flux set %at 500 (requires files named ‘iJR904.rxn’, ‘iJR904.met’, and ‘iJR904.sto’ to exist)
model = readCbModel(‘iJR904’,’fileType’,’SimPheny’,’defaultBound’, 500);
%4) Load model named ‘iJR904’ in SimPheny format with gpr and compound information %(requires files named ‘iJR904.rxn’, ‘iJR904.met’,’iJR904.sto’, %’iJR904_gpr.txt’, and ‘iJR904_cmpd.txt’ to exist)
model = readCbModel(‘iJR904’,’fileType’,’SimPhenyPlus’);
- readMinosSolution(fname)[source]¶
Loads MINOS solution information from file fname. The file is created by MINOS with the run-time option Report file 81. Note that 81 is essential, and the gfortran compiler produces a file named fort.81 (which may be renamed by the script used to run MINOS). Other compilers may generate different generic names.
The optimization problem solved by MINOS is assumed to be
min osense*s(iobj)
st Ax - s = 0 + bounds on x and s,
where A has m rows and n columns.
- USAGE
sol = readMinosSolution (fname)
- INPUT
fname – File
- OUTPUT
sol – Structure
.inform - MINOS exit condition
.m - Number of rows in A
.n - Number of columns in A
.osense - osense
.objrow - Row of A containing a linear objective
.obj - Value of MINOS objective (linear + nonlinear)
.numinf - Number of infeasibilities in x and s.
.suminf - Sum of infeasibilities in x and s.
.xstate - n vector: state of each variable in x.
.sstate - m vector: state of each slack in s.
.x - n vector: value of each variable in x.
.s - m vector: value of each slack in s.
.rc - n vector: reduced gradients for x.
.y - m vector: dual variables for Ax - s = 0.
- readMixedData(file, n_header, n_labels, delimiter, verbose)[source]¶
Read floating point data with row identifiers (text) in the first n columns and m headerlines (text)
- USAGE
[id, data, header] = readMixedData (file, n_header, n_labels, delimiter, verbose)
- INPUTS
file – Filename
n_header – Number of header lines (default 0)
n_labels – Number of label columns (default 1)
delimiter – Delimiter character (default tab)
verbose – Print out the string to be evaluated for debugging (default 0)
- OUTPUTS
id – Identifiers
data – Read data
header – Headers
- sbmlTestModelToMat(originFolder, destFolder)[source]¶
Function to translate a batch of sbml files in .xml format within an originFolder, into COBRA toolbox compatible models, saving each as a .mat file in destFolder containing one ‘model’ structure derived from the corresponding .xml file
- USAGE
sbmlTestModelToMat (originFolder, destFolder)
- INPUT
originFolder – full path to the folder with the input SBML XML files
destFolder – full path to the folder with the COBRA 2.0 toolbox compatible models, one each in a name.mat file where name is derived from the filename of the corresponding input name.xml file
- writeCbModel(model, varargin)[source]¶
Writes out COBRA models in various formats
- USAGE
outmodel = writeCbModel (model, varargin)
- INPUTS
model – Standard COBRA model structure
- OPTIONAL INPUTS
varargin – Optional parameters in ‘Parametername’,value format. Available parameterNames are: * format: File format to be used (‘text’, ‘xls’, ‘mat’(default), ‘expa’, ‘json’ or ‘sbml’)
text will only output data from required fields (with GPR rules converted to string representation) xls is restricted to the fields defined in the xls io documentation. expa will print all reactions with Exchangers being detected by findExcRxns
fileName: File name for output file (optional, default opens dialog box)
compSymbols: List of compartment symbols (Cell array)
compNames: List of compartment names corresponding to compSymbolList (Cell array) If compSymbols and compNames are not provided, they are obtained by default from getDefaultCompartmentSymbols()
- OPTIONAL OUTPUTS:
outmodel: Only useable with sbml export. Will return the sbml structure, otherwise the input COBRA model structure is returned.
Examples
% Write a model in sbml format (a popup will ask for the name) outmodel = writeCbModel(model, ‘format’,’sbml’) % Write a model in the specified format with the given file name outmodel = writeCbModel(model, ‘format’,’mat’, ‘fileName’, ‘TestModel.mat’) % Write a model in xls outmodel = writeCbModel(Recon3D, ‘format’,’xls’,’fileName’,’Recon3D_301_Thiele_2018.xls’);
Note
The writeCbModel function relies on another function io/utilities/writeSBML.m to convert a COBRA-Matlab structure into a libSBML-Matlab structure and then call libSBML to export a FBCv2 file. The current version of the writeSBML.m does not require the SBML toolbox (http://sbml.org/Software/SBMLToolbox).
- writeGDXFromCOBRA(cobraStruct, varargin)[source]¶
Writes a GDX file with the stoichiometric matrix, bounds and reversibility information.
- USAGE
[helpText] = writeGDXFromCOBRA (cobraStruct,…)
- INPUTS
cobraStruct – Model Structure
- OPTIONAL INPUTS
FileName – Name for the generated .gdx file (date and time based name by default)
IncludeSets – Controls inclusion of metabolite and reaction sets in the gdx file (true by default)
IncludeBounds – Controls inclusion of model bounds in the gdx file (true by default)
- OUTPUT
helpText – String with example load
Example
% Default call writeGDXFromCOBRA(cobraStruct);
% Specify a filename writeGDXFromCOBRA(cobraStruct,’FileName’,’mymodel.gdx’);
% Generate smaller size file by taking advantage of “Domain Loading” in gams writeGDXFromCOBRA(cobraStruct,’IncludeSets’,false);
% Don’t include the bounds in generated file writeGDXFromCOBRA(cobraStruct,’IncludeBounds’,false);
Note
Requires ‘wgdx’ to be on path, which is provided by a GAMS installation.
- writeLPProblem(LPProblem, varargin)[source]¶
Creates an MPS (Mathematical Programming System) format ascii file representing the Linear Programming problem given by LPProblem.
- USAGE
OK = writeLPProblem (LPProblem, varargin)
- INPUT
LPproblem – Structure containing the following fields describing the LP problem to be solved
.A - LHS matrix
.b - RHS vector
.c - Objective coeff vector
.lb - Lower bound vector
.ub - Upper bound vector
.osense - Objective sense (max=-1, min=+1)
.csense - Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
- OPTIONAL INPUT
varargin: a list of parameter/value pairs with the following parameters:
‘fileName’ - Name of the output file (e.g. ‘Problem.mps’)
‘solverParams’ - A struct containing the solver parameters if provided
‘outputFormat’ - Currently only ‘mps’ is supported (and default)
‘writeMatrix’ - Only write the Matrix, not the full problem (default true), will be ignored if solver params are provided
- OUTPUT
OK – 1 if saving is success, 0 otherwise
Example
Write a model to a specified fileName: OK = writeLPProblem(LPProblem, ‘fileName’, ‘AFileName.ext’)
Write a model problem using the specified solverParams OK = writeLPProblem(LPProblem, ‘solverParams’, Params)
- writeMinosProblem(LPproblem, precision, modelName, directory, printLevel)[source]¶
Inputs a COBRA LPproblem Matlab structure and outputs a file that can be input to an F90 main program for solution by SQOPT or MINOS.
- USAGE
[directory, fname] = writeMinosProblem (LPproblem, precision, modelName, directory, printLevel)
- INPUTS
LPproblem – Structure containing the following fields describing the LP problem to be solved
.A - LHS matrix
.b - RHS vector
.c - Objective coeff vector
.lb - Lower bound vector
.ub - Upper bound vector
.osense - Objective sense (-1 max, +1 min)
.csense - Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
- OPTIONAL INPUTS
precision – ‘double’ or ‘single’ precision
modelName – name is the problem name (a character string)
directory – the directory where optimization problem file is saved
printLevel – verbose level
- OUTPUT
directory – directory for the file
fname – filename of the optimization problem
Note
BEFORE RUNNING writeMinosProblem DO THIS:
Set modelNo = one of the switch numbers
Set format = 1 or 2
Set name for the chosen modelNo (AT MOST 7 CHARACTERS WITH NO TRAILING BLANKS)
name is the problem name (a character string). A s is appended to name if format==2 (single precision), name.txt is the name of the output file. name is the first line in the output file.