/
loadIdentifiedModel.m
44 lines (40 loc) · 1.23 KB
/
loadIdentifiedModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function model = loadIdentifiedModel(filename, directory)
% Load a single cobra toolbox model saved as a filename.mat file, then
% rename the model structure 'model' while retaining the original name of
% the model structure in model.modelID
%
% USAGE:
%
% model = loadIdentifiedModel(filename, directory)
%
% INPUTS:
% filename: name of the .mat file containing cobra toolbox model structure
% directory: directory where the .mat file resides.
%
% OUTPUT:
% model: COBRA model structure
%
% .. Author: - Ronan Fleming
if ~exist('directory','var')
directory=pwd;
end
matFile=[directory filesep filename '.mat'];
%get the id of the model from the filename
whosFile=whos('-file',matFile);
modelName=whosFile.name;
%load the .mat file
load(matFile);
%rename the variable of the model to the standard, i.e. 'model'
model=eval(modelName);
%model.rev should be depreciated as it duplicates model.lb and model.ub
if isfield(model,'rev')
model=rmfield(model,'rev');
end
if isfield(model,'osense')
model.osense=cast(model.osense,'double');
end
%stamp the model with the ID of the file
model.modelID=modelName;
if isempty(strmatch(model.modelID, filename))
warning('fileName.mat and modelStructureName.mat did not match')
end