Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ mafft binary
.gitattributes export-ignore
.gitignore export-ignore
.github export-ignore
*.mat filter=lfs diff=lfs merge=lfs -text
3 changes: 2 additions & 1 deletion INIT/runINIT.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [outModel, deletedRxns, metProduction, fValue]=runINIT(model,rxnScores,presentMets,essentialRxns,prodWeight,allowExcretion,noRevLoops)
function [outModel, deletedRxns, metProduction, fValue]=runINIT(model,rxnScores,presentMets,essentialRxns,prodWeight,allowExcretion,noRevLoops,params)
% runINIT
% Generates a model using the INIT algorithm, based on proteomics and/or
% transcriptomics and/or metabolomics and/or metabolic tasks. This is the
Expand Down Expand Up @@ -38,6 +38,7 @@
% problem significantly more computationally intensive to
% solve (two more integer constraints per reversible reaction)
% (optional, default false)
% params parameter structure for use by optimizeProb
%
% outModel the resulting model structure
% deletedRxns reactions which were deleted by the algorithm
Expand Down
7 changes: 6 additions & 1 deletion core/FSEOF.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@
A2=char(model.rxns(num)); %enzyme ID
A3=char(model.rxnNames(num)); %enzyme Name
if isfield(model,'subSystems') && ~isempty(model.subSystems{num});
A4=char(strjoin(model.subSystems{num,1},';')); %Subsystems
if ~any(cellfun(@(x) iscell(x), model.subSystems));
subSys = cellfun(@(x) {x}, model.subSystems, 'uni', 0);
else
subSys = model.subSystems;
end
A4=char(strjoin(subSys{num},';')); %Subsystems
else
A4='';
end
Expand Down
4 changes: 2 additions & 2 deletions core/addExchangeRxns.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
end
if isfield(model,'subSystems')
fillerSub = filler;
if iscell(model.subSystems(1,1))
fillerSub = repmat({fillerSub},numel(J),1);
if any(cellfun(@(x) iscell(x), model.subSystems))
fillerSub(:)={{''}};
end
model.subSystems=[model.subSystems;fillerSub];
end
Expand Down
49 changes: 36 additions & 13 deletions core/addRxns.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@
nOldRxns=numel(model.rxns);
filler=cell(nRxns,1);
filler(:)={''};
cellfiller=cellfun(@(x) cell(0,0),filler,'UniformOutput',false);
cellfiller=cell(nRxns,1);
cellfiller(:)={{''}};
largeFiller=cell(nOldRxns,1);
largeFiller(:)={''};
celllargefiller=cellfun(@(x) cell(0,0),largeFiller,'UniformOutput',false);
largeCellFiller=cell(nOldRxns,1);
largeCellFiller(:)={{''}};

%***Add everything to the model except for the equations.
if numel(rxnsToAdd.equations)~=nRxns
Expand Down Expand Up @@ -350,24 +352,45 @@
end

if isfield(rxnsToAdd,'subSystems')
if numel(rxnsToAdd.subSystems)~=nRxns
EM='rxnsToAdd.subSystems must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
% Has to be cell array
if ischar(rxnsToAdd.subSystems)
rxnsToAdd.subSystems = {rxnsToAdd.subSystems};
end
% If all nested cells are 1x1, then unnest
if all(cellfun(@(x) iscell(x) && isscalar(x), rxnsToAdd.subSystems))
rxnsToAdd.subSystems = transpose([rxnsToAdd.subSystems{:}]);
end
for i=1:numel(rxnsToAdd.subSystems)
if ischar(rxnsToAdd.subSystems{i})
rxnsToAdd.subSystems{i}=rxnsToAdd.subSystems(i);
% Cell array should now be as simple as possible. Check if it is nested
subSysRxnsNested = any(cellfun(@(x) iscell(x), rxnsToAdd.subSystems));
if isfield(newModel,'subSystems')
subSysModelNested = any(cellfun(@(x) iscell(x), newModel.subSystems));
else
subSysModelNested = subSysRxnsNested;
if subSysRxnsNested
newModel.subSystems=largeCellFiller;
else
newModel.subSystems=largeFiller;
end
end
%Fill with standard if it doesn't exist
if ~isfield(newModel,'subSystems')
newModel.subSystems=celllargefiller;
if subSysRxnsNested && ~subSysModelNested
% Make all existing subSystems nested
newModel.subSystems = cellfun(@(x) {x}, newModel.subSystems, 'uni', 0);
elseif ~subSysRxnsNested && subSysModelNested
rxnsToAdd.subSystems = cellfun(@(x) {x}, rxnsToAdd.subSystems, 'uni', 0);
end
if numel(rxnsToAdd.subSystems)~=nRxns
EM='rxnsToAdd.subSystems must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
end
newModel.subSystems=[newModel.subSystems;rxnsToAdd.subSystems(:)];
else
%Fill with standard if it doesn't exist
%Fill with standard if it does not exist
if isfield(newModel,'subSystems')
newModel.subSystems=[newModel.subSystems;cellfiller];
if any(cellfun(@(x) iscell(x), newModel.subSystems))
newModel.subSystems=[newModel.subSystems;cellfiller];
else
newModel.subSystems=[newModel.subSystems;filler];
end
end
end
if isfield(rxnsToAdd,'rxnMiriams')
Expand Down
10 changes: 7 additions & 3 deletions core/addTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@
model.eccodes=[model.eccodes;filler];
end
if isfield(model,'subSystems')
ssFiller=filler;
isNested = any(cellfun(@(x) iscell(x), model.subSystems));
ssFiller = filler;
if isRev==1
ssFiller(:)={{['Transport between ' fromComp ' and ' toComps{i}]}};
ssFiller(:) = {['Transport between ' fromComp ' and ' toComps{i}]};
else
ssFiller(:)={{['Transport from ' fromComp ' to ' toComps{i}]}};
ssFiller(:) = {['Transport from ' fromComp ' to ' toComps{i}]};
end
if isNested
ssFiller = cellfun(@(x) {x}, ssFiller, 'uni', 0);
end
model.subSystems=[model.subSystems;ssFiller];
end
Expand Down
8 changes: 4 additions & 4 deletions core/checkModelStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ function checkModelStruct(model,throwErrors,trimWarnings)
end
end
if isfield(model,'subSystems')
for i=1:numel(model.subSystems)
if ~iscell(model.subSystems{i,1})
EM='The "subSystems" field must be a cell array';
isNested = any(cellfun(@(x) iscell(x), model.subSystems));
isCellStr = any(cellfun(@(x) ischar(x), model.subSystems));
if ~xor(isNested,isCellStr)
EM='The "subSystems" field must be a cell array of chars, *or* a cell array of cell arrays of chars';
dispEM(EM,throwErrors);
end
end
end
if isfield(model,'eccodes')
Expand Down
20 changes: 10 additions & 10 deletions core/compareMultipleModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@
fprintf('*** Done \n\n')


%% Flatten models' subSystems field
% Convert from cell array of cells to cell array of strings
% NOTE: this function currently only recognizes one subSystem per reaction;
% additional subSystems will be ignored!
for i = 1:numel(models)
cells = cellfun(@iscell,models{i}.subSystems);
models{i}.subSystems(cells) = cellfun(@(s) s{1}, models{i}.subSystems(cells), 'UniformOutput', false);
end


%% Compare models structure & function based on high-dimensional methods
% Compare number of reactions in each subsystem in each model using a heatmap
field = 'subSystems';
Expand All @@ -110,6 +100,16 @@
fprintf('\nWARNING: At least one model does not contain the field "subSystems". \n')
fprintf(' Skipping subsystem comparison. \n\n')
else
%% Flatten model subSystems field
% Convert from cell array of cells to cell array of strings
% NOTE: this function currently only recognizes one subSystem per reaction;
% additional subSystems will be ignored!
for i = 1:numel(models)
if any(cellfun(@(x) iscell(x), models{i}.subSystems));
cells = cellfun(@iscell,models{i}.subSystems);
models{i}.subSystems(cells) = cellfun(@(s) s{1}, models{i}.subSystems(cells), 'UniformOutput', false);
end
end
[id,compMat] = compareModelField(models,field);
compStruct.subsystems.ID = id;
compStruct.subsystems.matrix = compMat;
Expand Down
45 changes: 26 additions & 19 deletions core/copyToComps.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@
%
% Usage: model=copyToComps(model,toComps,rxns,deleteOriginal,compNames,compOutside)

if nargin<3
rxns=model.rxns;
elseif ~islogical(rxns) && ~isnumeric(rxns)
rxns=convertCharArray(rxns);
arguments
model (1,1) struct
toComps {emptyOrTextOrCellOfText}
rxns = model.rxns
deleteOriginal {emptyOrLogicalScalar} = false
compNames {emptyOrTextOrCellOfText} = toComps
compOutside {emptyOrTextOrCellOfText} = '';
end
if nargin<4
deleteOriginal=false;

if nargin >= 3 && ~islogical(rxns) && ~isnumeric(rxns)
rxns = convertCharArray(rxns);
end
if nargin<5
compNames=toComps;
else
if nargin >= 5
compNames=convertCharArray(compNames);
end
if nargin<6
compOutside=cell(numel(toComps),1);
compOutside(:)={''};
else
if nargin >= 6
compOutside=convertCharArray(compOutside);
if length(compOutside) ~= length(compNames)
error('compOutside and compNames should be of equal size.');
end
end

originalID=model.id;
Expand Down Expand Up @@ -79,15 +81,20 @@
modelToAdd.compMiriams=modelToAdd.compMiriams(J);
end
modelToAdd.metComps=ones(numel(modelToAdd.mets),1);

if isfield(modelToAdd,'metFrom')
modelToAdd = rmfield(modelToAdd,'metFrom');
end
if isfield(modelToAdd,'rxnFrom')
modelToAdd = rmfield(modelToAdd,'rxnFrom');
end
if isfield(modelToAdd,'geneFrom')
modelToAdd = rmfield(modelToAdd,'geneFrom');
end

%Merge the models
model=mergeModels({model;modelToAdd},'metNames');
model=mergeModels({model;modelToAdd},'metNames',[],true);
end

model=rmfield(model,'rxnFrom');
model=rmfield(model,'metFrom');
model=rmfield(model,'geneFrom');

if deleteOriginal==true
model=removeReactions(model,rxns,true,true,true); %Also delete unused compartments
end
Expand Down
28 changes: 16 additions & 12 deletions core/findRAVENroot.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
function [ravenPath, prevDir] = findRAVENroot()
% findRAVENroot
% Finds the root of the RAVEN directory, by searching for the path to
% Finds the root of the RAVEN directory, first by by searching for the path to
% RAVEN2.png. Can also record the current directory, in case a function will
% use the ravenPath to navigate to a precise folder, and it should return to
% the previous directory afterwards. See e.g. optimizeProb calling glpk.

ST=dbstack('-completenames');
prevDir = pwd();
ravenPath = ST(strcmp({ST.name},'findRAVENroot')).file;
rootFound = 0;
while rootFound == 0
isRoot = isfile(fullfile(ravenPath,'RAVEN2.png'));
if isRoot
rootFound = 1;
else
ravenPathOld = ravenPath;
ravenPath = fileparts(ravenPath);
if strcmp(ravenPathOld,ravenPath)
error('Cannot find the RAVEN root directory. Make sure you have not removed the RAVEN2.png file from your RAVEN installation.')
if ispref('RAVEN','ravenPath')
ravenPath = getpref('RAVEN','ravenPath');
else
ravenPath = ST(strcmp({ST.name},'findRAVENroot')).file;
rootFound = 0;
while rootFound == 0
isRoot = isfile(fullfile(ravenPath,'RAVEN2.png'));
if isRoot
rootFound = 1;
else
ravenPathOld = ravenPath;
ravenPath = fileparts(ravenPath);
if strcmp(ravenPathOld,ravenPath)
error('Cannot find the RAVEN root directory. Make sure you have not removed the RAVEN2.png file from your RAVEN installation.')
end
end
end
end
9 changes: 3 additions & 6 deletions core/fitTasks.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
% the result.
%
% Usage: [outModel, addedRxns]=fitTasks(model,refModel,inputFile,printOutput,...
% rxnScores,taskStructure,params)
% rxnScores,taskStructure)

if nargin<4
printOutput=true;
Expand All @@ -48,9 +48,6 @@
if nargin<6
taskStructure=[];
end
if nargin<7
params=[];
end

if isempty(taskStructure) && ~isfile(inputFile)
error('Task file %s cannot be found',string(inputFile));
Expand Down Expand Up @@ -266,9 +263,9 @@
%Only do gap-filling if it cannot be solved
failed=false;
try
[~, ~, newRxns, newModel, exitFlag]=fillGaps(tModel,refModel,false,true,supressWarnings,rxnScores,params);
[~, ~, newRxns, newModel, exitFlag]=fillGaps(tModel,refModel,false,true,supressWarnings,rxnScores);
if exitFlag==-2
EM=['"[' taskStructure(i).id '] ' taskStructure(i).description '" was aborted before reaching optimality. Consider increasing params.maxTime\n'];
EM=['"[' taskStructure(i).id '] ' taskStructure(i).description '" was aborted before reaching optimality.\n'];
dispEM(EM,false);
end
catch
Expand Down
Loading
Loading