diff --git a/INIT/ftINIT.m b/INIT/ftINIT.m
index e9d6a9b4..29654b29 100644
--- a/INIT/ftINIT.m
+++ b/INIT/ftINIT.m
@@ -54,9 +54,7 @@
% useScoresForTasks true if the calculated reaction scored should be
% used as weights when fitting to tasks (optional, default
% true)
-% paramsFT parameter structure as used by getMILPParams. This
-% is for the fitTasks step. For the INIT algorithm,
-% see params (optional, default [])
+% paramsFT *obsolete option*
% verbose if true, the MILP progression will be shown.
% (optional, default false)
%
diff --git a/INIT/ftINITFillGaps.m b/INIT/ftINITFillGaps.m
index 5673c3e6..6b1aa471 100644
--- a/INIT/ftINITFillGaps.m
+++ b/INIT/ftINITFillGaps.m
@@ -23,7 +23,7 @@
% reference tModel.
% The solver will try to maximize the sum of the
% scores for the included reactions
-% params parameter structure as used by getMILPParams
+% params *obsolete option*
% verbose if true, the MILP progression will be shown.
%
% addedRxns the rxns added
diff --git a/INIT/ftINITFillGapsForAllTasks.m b/INIT/ftINITFillGapsForAllTasks.m
index 0fdbe898..fbee4782 100644
--- a/INIT/ftINITFillGapsForAllTasks.m
+++ b/INIT/ftINITFillGapsForAllTasks.m
@@ -18,7 +18,7 @@
% reactions (optional, default is -1 for all reactions)
% taskStructure structure with the tasks, as from parseTaskList. If
% this is supplied then inputFile is ignored
-% params parameter structure as used by getMILPParams
+% params *obsolete option*
% verbose if true, the MILP progression will be shown.
%
%
diff --git a/INIT/ftINITFillGapsMILP.m b/INIT/ftINITFillGapsMILP.m
index 45fb5a9f..cc66f33c 100644
--- a/INIT/ftINITFillGapsMILP.m
+++ b/INIT/ftINITFillGapsMILP.m
@@ -12,7 +12,7 @@
% with the same number of elements as reactions in the model,
% of a vector of indexes for the reactions that should be
% minimized (optional, default model.rxns)
-% params parameter structure as used by getMILPParams (optional)
+% params *obsolete option*
% scores vector of weights for the reactions. Negative scores
% should not have flux. Positive scores are not possible in this
% implementation, and they are changed to max(scores(scores<0)).
diff --git a/INIT/getINITModel.m b/INIT/getINITModel.m
index e48bf1a2..37c16e9f 100644
--- a/INIT/getINITModel.m
+++ b/INIT/getINITModel.m
@@ -1,10 +1,10 @@
-function [model, metProduction, essentialRxnsForTasks, addedRxnsForTasks, deletedDeadEndRxns, deletedRxnsInINIT, taskReport]=getINITModel(refModel, tissue, celltype, hpaData, arrayData, metabolomicsData, taskFile, useScoresForTasks, printReport, taskStructure, params, paramsFT)
+function [model, metProduction, essentialRxnsForTasks, addedRxnsForTasks, deletedDeadEndRxns, deletedRxnsInINIT, taskReport]=getINITModel(refModel, tissue, celltype, hpaData, arrayData, metabolomicsData, taskFile, useScoresForTasks, printReport, taskStructure)
% getINITModel_legacy
% Generates a model using the INIT algorithm, based on proteomics and/or
% transcriptomics and/or metabolomics and/or metabolic tasks. This is the original
% implementation of tINIT, which is replaced by ftINIT.
%
-% Input:
+% Input:
% refModel a model structure. The model should be in the
% closed form (no exchange reactions open). Import
% using import(filename,false). If the model is not
@@ -53,15 +53,8 @@
% as an alternative way to define tasks when Excel
% sheets are not suitable. Overrides taskFile (optional,
% default [])
-% params parameter structure as used by getMILPParams. This is
-% for the INIT algorithm. For the the MILP problems
-% solved to fit tasks, see paramsFT (optional, default [])
-% paramsFT parameter structure as used by getMILPParams. This is
-% for the fitTasks step. For the INIT algorithm, see
-% params (optional, default [])
%
-%
-% Output:
+% Output:
% model the resulting model structure
% metProduction array that indicates which of the
% metabolites in metabolomicsData that could be
diff --git a/INIT/runINIT.m b/INIT/runINIT.m
index 33ddaac0..ca064f50 100644
--- a/INIT/runINIT.m
+++ b/INIT/runINIT.m
@@ -1,4 +1,4 @@
-function [outModel, deletedRxns, metProduction, fValue]=runINIT(model,rxnScores,presentMets,essentialRxns,prodWeight,allowExcretion,noRevLoops,params)
+function [outModel, deletedRxns, metProduction, fValue]=runINIT(model,rxnScores,presentMets,essentialRxns,prodWeight,allowExcretion,noRevLoops)
% runINIT
% Generates a model using the INIT algorithm, based on proteomics and/or
% transcriptomics and/or metabolomics and/or metabolic tasks. This is the
@@ -38,8 +38,6 @@
% problem significantly more computationally intensive to
% solve (two more integer constraints per reversible reaction)
% (optional, default false)
-% params parameter structure as used by getMILPParams (optional,
-% default [])
%
% outModel the resulting model structure
% deletedRxns reactions which were deleted by the algorithm
diff --git a/core/consumeSomething.m b/core/consumeSomething.m
index a9c7f1ee..5ec896cb 100755
--- a/core/consumeSomething.m
+++ b/core/consumeSomething.m
@@ -19,7 +19,7 @@
% fluxes instead of the sum. Slower, but can be
% used if the sum gives too many fluxes (optional, default
% false)
-% params parameter structure as used by getMILPParams (optional)
+% params *obsolete option*
% ignoreIntBounds true if internal bounds (including reversibility)
% should be ignored. Exchange reactions are not affected.
% This can be used to find unbalanced solutions which are
diff --git a/core/fillGaps.m b/core/fillGaps.m
index bf19411b..da0d81c9 100755
--- a/core/fillGaps.m
+++ b/core/fillGaps.m
@@ -1,4 +1,4 @@
-function [newConnected, cannotConnect, addedRxns, newModel, exitFlag]=fillGaps(model,models,allowNetProduction,useModelConstraints,supressWarnings,rxnScores,params)
+function [newConnected, cannotConnect, addedRxns, newModel, exitFlag]=fillGaps(model,models,allowNetProduction,useModelConstraints,supressWarnings,rxnScores)
% fillGaps
% Uses template model(s) to fill gaps in a model
%
@@ -24,7 +24,6 @@
% The solver will try to maximize the sum of the
% scores for the included reactions (optional, default
% is -1 for all reactions)
-% params parameter structure as used by getMILPParams (optional)
%
% newConnected cell array with the reactions that could be
% connected. This is not calulated if
diff --git a/core/fitTasks.m b/core/fitTasks.m
index 0a8cca96..9963f9e7 100755
--- a/core/fitTasks.m
+++ b/core/fitTasks.m
@@ -1,4 +1,4 @@
-function [outModel, addedRxns]=fitTasks(model,refModel,inputFile,printOutput,rxnScores,taskStructure,params)
+function [outModel, addedRxns]=fitTasks(model,refModel,inputFile,printOutput,rxnScores,taskStructure)
% fitTasks
% Fills gaps in a model by including reactions from a reference model,
% so that the resulting model can perform all the tasks in a task list
@@ -17,7 +17,6 @@
% reactions (optional, default is -1 for all reactions)
% taskStructure structure with the tasks, as from parseTaskList. If
% this is supplied then inputFile is ignored (optional)
-% params parameter structure as used by getMILPParams (optional)
%
%
% Output:
diff --git a/core/getMinNrFluxes.m b/core/getMinNrFluxes.m
index 137e90b3..6c9ca5e2 100755
--- a/core/getMinNrFluxes.m
+++ b/core/getMinNrFluxes.m
@@ -8,7 +8,7 @@
% with the same number of elements as reactions in the model,
% of a vector of indexes for the reactions that should be
% minimized (optional, default model.rxns)
-% params parameter structure as used by getMILPParams (optional)
+% params *obsolete option*
% scores vector of weights for the reactions. Negative scores
% should not have flux. Positive scores are not possible in this
% implementation, and they are changed to max(scores(scores<0)).
diff --git a/core/makeSomething.m b/core/makeSomething.m
index 4a5a753f..1b9b2ab8 100755
--- a/core/makeSomething.m
+++ b/core/makeSomething.m
@@ -21,7 +21,7 @@
% false)
% allowExcretion allow for excretion of all other metabolites (optional,
% default true)
-% params parameter structure as used by getMILPParams (optional)
+% params *obsolete option*
% ignoreIntBounds true if internal bounds (including reversibility)
% should be ignored. Exchange reactions are not affected.
% This can be used to find unbalanced solutions which are
diff --git a/core/randomSampling.m b/core/randomSampling.m
index 0e41a308..9c48431c 100755
--- a/core/randomSampling.m
+++ b/core/randomSampling.m
@@ -42,13 +42,18 @@
% Output:
% solutions matrix with the solutions
% goodRxns double vector of indexes of those reactions
-% that are not involved in loops and can be used
-% as random objective functions
+% that are not involved in loops or always carry
+% zero flux and can be used as random objective
+% functions
%
-% The solutions are generated by maximizing (with random weights) for a
-% random set of three reactions. For reversible reactions it randomly
+% Note: The solutions are generated by maximizing (with random weights) for
+% a random set of three reactions. For reversible reactions it randomly
% chooses between maximizing and minimizing.
%
+% If the model is a GECKO v3+ ecModel, then usage_prot reactions are not
+% selected for sampling, instead focusing on sampling from the metabolic
+% aspects that form the solution space.
+%
% Usage: solutions = randomSampling(model, nSamples, replaceBoundsWithInf,...
% supressErrors, runParallel, goodRxns, minFlux)
@@ -94,35 +99,39 @@
warning('The model objective function cannot reach a non-zero value. This might be intended, so randomSampling will continue, but this could indicate problems with your model')
end
-[~,hsSol]=solveLP(model);
nRxns = numel(model.rxns);
%Reactions which can be involved in loops should not be optimized for.
%Check which reactions reach an arbitary high upper bound
if nargin<6 || isempty(goodRxns)
- goodRxns = true(numel(model.rxns),numel(model.rxns));
- goodRxns = num2cell(goodRxns,1);
+ revRxns = transpose(find(model.lb < 0));
+ fwdRxns = transpose(find(model.ub > 0));
+ rxnList = [fwdRxns,revRxns];
+ objList = [ones(numel(fwdRxns),1);-ones(numel(revRxns),1)];
+ testSol = zeros(numel(objList),1);
PB = ProgressBar2(nRxns,'Prepare goodRxns not involved in loops','cli');
- parfor (i=1:nRxns)
- testModel=setParam(model,'eq',model.rxns(i),1000);
- sol=solveLP(testModel,0,[],hsSol);
+
+ parfor i = 1:numel(objList)
+ testModel=setParam(model,'obj',rxnList(i),objList(i));
+ sol=solveLP(testModel,0);
if ~isempty(sol.f)
- notGood = abs(sol.x)>999;
- goodRxns{i}(notGood)=false;
- else
- %If the reaction is reversible, also check in that direction
- if model.rev(i)
- testModel=setParam(model,'eq',model.rxns(i),-1000);
- sol=solveLP(testModel,0,[],hsSol);
- if ~isempty(sol.f)
- notGood = abs(sol.x)>999;
- goodRxns{i}(notGood)=false;
- end
- end
+ testSol(i) = sol.x(rxnList(i));
end
count(PB);
end
- goodRxns = cell2mat(goodRxns);
- goodRxns = find(prod(goodRxns,2));
+ testSol = testSol.*objList;
+ goodRxns = true(nRxns,1);
+ % Filter out reactions that can reach (-)1000 (= involved in loop)
+ goodRxns(fwdRxns(testSol(1:numel(fwdRxns)) > 999)) = false;
+ goodRxns(revRxns(testSol(numel(fwdRxns)+1:end) > 999)) = false;
+ testSol(revRxns) = testSol(revRxns) + testSol(numel(fwdRxns)+1:end);
+ % Filter out reactions that cannot carry flux
+ goodRxns(testSol(1:nRxns) == 0) = false;
+ % In ecModels do not sample from usage_prot reactions
+ if isfield(model,'ec')
+ usageRxns = startsWith(model.rxns,'usage_prot_');
+ goodRxns(usageRxns) = false;
+ end
+ goodRxns = find(goodRxns);
end
%Reserve space for a solution matrix
@@ -139,13 +148,16 @@
while lt(0,badSolutions)
rxns = randsample(numel(goodRxns),nObjRxns);
tmpModel.c = zeros(numel(tmpModel.rxns),1);
+
multipliers = randsample([-1 1],nObjRxns,true);
- multipliers(tmpModel.rev(goodRxns(rxns))==0) = 1;
+ multipliers(tmpModel.ub(goodRxns(rxns))<0) = 1;
+
tmpModel.c(goodRxns(rxns)) = rand(nObjRxns,1).*multipliers;
+
if true(minFlux)
- sol=solveLP(tmpModel,1,[],hsSol);
+ sol=solveLP(tmpModel,1);
else
- sol=solveLP(tmpModel,0,[],hsSol);
+ sol=solveLP(tmpModel,0);
end
if any(sol.x) && abs(sol.f)>10^-8
sols{i} = sol.x;
diff --git a/core/setParam.m b/core/setParam.m
index c341b914..e24ad2ca 100755
--- a/core/setParam.m
+++ b/core/setParam.m
@@ -123,4 +123,9 @@
end
end
end
+if any(ismember(paramType,{'lb','ub','unc'}))
+ invalidBound = model.lb(indexes) > model.ub(indexes);
+ if any(invalidBound)
+ error(['Invalid set of bounds for reaction(s): ', strjoin(model.rxns(indexes(invalidBound)),', '), '.'])
+ end
end
diff --git a/doc/INIT/ftINIT.html b/doc/INIT/ftINIT.html
index fed102da..3c05d6e0 100644
--- a/doc/INIT/ftINIT.html
+++ b/doc/INIT/ftINIT.html
@@ -82,9 +82,7 @@
DESCRIPTION
SOURCE CODE % useScoresForTasks true if the calculated reaction scored should be
0055
0056
-0057
-0058
-0059
-0060
-0061
-0062
-0063
-0064
-0065
-0066
-0067
-0068
-0069
-0070
-0071
-0072
-0073
-0074
-0075
-0076
-0077
-0078
-0079
-0080
-0081
-0082
-0083
-0084
-0085
-0086
-0087
-0088
-0089
-0090
-0091
-0092
-0093
-0094
-0095
-0096
-0097 if nargin < 5
-0098 transcrData = [];
-0099 end
-0100 if nargin < 6
-0101 metabolomicsData = [];
-0102 end
-0103 if nargin < 7 || isempty(INITSteps)
-0104 INITSteps = getINITSteps([],'1+1');
-0105 end
-0106 if nargin < 8 || isempty(removeGenes)
-0107 removeGenes = true;
-0108 end
-0109 if nargin < 9 || isempty(useScoresForTasks)
-0110 useScoresForTasks = true;
-0111 end
-0112 if nargin < 10
-0113 paramsFT = [];
-0114 end
-0115
-0116 if nargin < 11
-0117 verbose = false;
-0118 end
-0119
-0120
-0121
-0122
-0123
-0124
-0125
-0126
-0127
-0128
-0129
-0130
-0131 if (~isempty(metabolomicsData))
-0132 if length(unique(upper(metabolomicsData))) ~= length(metabolomicsData)
-0133 dispEM('Metabolomics contains the same metabolite multiple times');
-0134 end
-0135 metData = false(numel(metabolomicsData), length(prepData.minModel.rxns));
-0136 for i=1:numel(metabolomicsData)
-0137
-0138 metSel = ismember(upper(prepData.refModel.metNames),upper(metabolomicsData{i}));
-0139 prodRxnsSel = any(prepData.refModel.S(metSel,:) > 0,1) | ...
-0140 (any(prepData.refModel.S(metSel,:) < 0,1) & prepData.refModel.rev.');
-0141
-0142 prepData.groupIds;
-0143 [~,ia,ib] = intersect(prepData.minModel.rxns,prepData.refModel.rxns);
-0144 grpIdsMerged = nan(length(prepData.minModel.rxns),1);
-0145 grpIdsMerged(ia) = prepData.groupIds(ib);
-0146
-0147 groupIdsPos = unique(prepData.groupIds(prodRxnsSel));
-0148 groupIdsPos = groupIdsPos(groupIdsPos ~= 0);
-0149
-0150 posRxns = prepData.refModel.rxns(prodRxnsSel);
-0151 directMatch = ismember(prepData.minModel.rxns, posRxns).';
-0152
-0153 metData(i,:) = ismember(grpIdsMerged, groupIdsPos).' | directMatch;
-0154 end
-0155 metData = sparse(metData);
-0156 else
-0157 metData = [];
-0158 end
-0159
-0160
-0161 origRxnScores = scoreComplexModel(prepData.refModel,hpaData,transcrData,tissue,celltype);
-0162 origRxnScores(origRxnScores > -0.1 & origRxnScores <= 0) = -0.1;
-0163 origRxnScores(origRxnScores < 0.1 & origRxnScores > 0) = 0.1;
-0164
-0165 rxnsTurnedOn = false(length(prepData.minModel.rxns),1);
-0166 fluxes = zeros(length(prepData.minModel.rxns),1);
+0057
+0058
+0059
+0060
+0061
+0062
+0063
+0064
+0065
+0066
+0067
+0068
+0069
+0070
+0071
+0072
+0073
+0074
+0075
+0076
+0077
+0078
+0079
+0080
+0081
+0082
+0083
+0084
+0085
+0086
+0087
+0088
+0089
+0090
+0091
+0092
+0093
+0094
+0095 if nargin < 5
+0096 transcrData = [];
+0097 end
+0098 if nargin < 6
+0099 metabolomicsData = [];
+0100 end
+0101 if nargin < 7 || isempty(INITSteps)
+0102 INITSteps = getINITSteps([],'1+1');
+0103 end
+0104 if nargin < 8 || isempty(removeGenes)
+0105 removeGenes = true;
+0106 end
+0107 if nargin < 9 || isempty(useScoresForTasks)
+0108 useScoresForTasks = true;
+0109 end
+0110 if nargin < 10
+0111 paramsFT = [];
+0112 end
+0113
+0114 if nargin < 11
+0115 verbose = false;
+0116 end
+0117
+0118
+0119
+0120
+0121
+0122
+0123
+0124
+0125
+0126
+0127
+0128
+0129 if (~isempty(metabolomicsData))
+0130 if length(unique(upper(metabolomicsData))) ~= length(metabolomicsData)
+0131 dispEM('Metabolomics contains the same metabolite multiple times');
+0132 end
+0133 metData = false(numel(metabolomicsData), length(prepData.minModel.rxns));
+0134 for i=1:numel(metabolomicsData)
+0135
+0136 metSel = ismember(upper(prepData.refModel.metNames),upper(metabolomicsData{i}));
+0137 prodRxnsSel = any(prepData.refModel.S(metSel,:) > 0,1) | ...
+0138 (any(prepData.refModel.S(metSel,:) < 0,1) & prepData.refModel.rev.');
+0139
+0140 prepData.groupIds;
+0141 [~,ia,ib] = intersect(prepData.minModel.rxns,prepData.refModel.rxns);
+0142 grpIdsMerged = nan(length(prepData.minModel.rxns),1);
+0143 grpIdsMerged(ia) = prepData.groupIds(ib);
+0144
+0145 groupIdsPos = unique(prepData.groupIds(prodRxnsSel));
+0146 groupIdsPos = groupIdsPos(groupIdsPos ~= 0);
+0147
+0148 posRxns = prepData.refModel.rxns(prodRxnsSel);
+0149 directMatch = ismember(prepData.minModel.rxns, posRxns).';
+0150
+0151 metData(i,:) = ismember(grpIdsMerged, groupIdsPos).' | directMatch;
+0152 end
+0153 metData = sparse(metData);
+0154 else
+0155 metData = [];
+0156 end
+0157
+0158
+0159 origRxnScores = scoreComplexModel(prepData.refModel,hpaData,transcrData,tissue,celltype);
+0160 origRxnScores(origRxnScores > -0.1 & origRxnScores <= 0) = -0.1;
+0161 origRxnScores(origRxnScores < 0.1 & origRxnScores > 0) = 0.1;
+0162
+0163 rxnsTurnedOn = false(length(prepData.minModel.rxns),1);
+0164 fluxes = zeros(length(prepData.minModel.rxns),1);
+0165
+0166 rxnsToIgnoreLastStep = [1;1;1;1;1;1;1;1];
0167
-0168 rxnsToIgnoreLastStep = [1;1;1;1;1;1;1;1];
-0169
-0170
-0171
-0172
-0173
-0174 fluxes = ones(length(prepData.minModel.rxns), 1).*0.1;
-0175
-0176 for initStep = 1:length(INITSteps)
-0177 disp(['ftINIT: Running step ' num2str(initStep)])
-0178 stp = INITSteps{initStep};
-0179
-0180 if any ((rxnsToIgnoreLastStep - stp.RxnsToIgnoreMask) < 0)
-0181 dispEM('RxnsToIgnoreMask may not cover rxns not covered in previous steps, but the other way around is fine.');
-0182 end
-0183 rxnsToIgnoreLastStep = stp.RxnsToIgnoreMask;
+0168
+0169
+0170
+0171
+0172 fluxes = ones(length(prepData.minModel.rxns), 1).*0.1;
+0173
+0174 for initStep = 1:length(INITSteps)
+0175 disp(['ftINIT: Running step ' num2str(initStep)])
+0176 stp = INITSteps{initStep};
+0177
+0178 if any ((rxnsToIgnoreLastStep - stp.RxnsToIgnoreMask) < 0)
+0179 dispEM('RxnsToIgnoreMask may not cover rxns not covered in previous steps, but the other way around is fine.');
+0180 end
+0181 rxnsToIgnoreLastStep = stp.RxnsToIgnoreMask;
+0182
+0183 mm = prepData.minModel;
0184
-0185 mm = prepData.minModel;
-0186
-0187 if (~isempty(stp.MetsToIgnore))
-0188 if (~isempty(stp.MetsToIgnore.simpleMets))
-0189
-0190
-0191
-0192 metsToRem = ismember(mm.metNames,stp.MetsToIgnore.simpleMets.mets);
-0193 compsToKeep = find(ismember(mm.comps, stp.MetsToIgnore.simpleMets.compsToKeep));
-0194 metsToRem = metsToRem & ~ismember(mm.metComps, compsToKeep);
-0195 mm.S(metsToRem,:) = 0;
-0196 end
-0197 end
-0198
-0199
-0200 rxnsToIgnore = getRxnsFromPattern(stp.RxnsToIgnoreMask, prepData);
-0201 rxnScores = groupRxnScores(prepData.minModel, origRxnScores, prepData.refModel.rxns, prepData.groupIds, rxnsToIgnore);
-0202
-0203 essentialRxns = prepData.essentialRxns;
-0204 toRev = false(numel(mm.rxns),1);
-0205
-0206 if strcmp(stp.HowToUsePrevResults, 'exclude')
-0207 rxnScores(rxnsTurnedOn) = 0;
-0208 elseif strcmp(stp.HowToUsePrevResults, 'essential')
-0209
-0210
-0211
-0212
-0213 rev = mm.rev == 1;
-0214 toRev = rxnsTurnedOn & rev & fluxes < 0;
-0215 mm = reverseRxns(mm, mm.rxns(toRev));
-0216
-0217
-0218 mm.rev(rxnsTurnedOn) = 0;
-0219 mm.lb(rxnsTurnedOn) = 0;
-0220
-0221 essentialRxns = unique([prepData.essentialRxns;mm.rxns(rxnsTurnedOn)]);
-0222 end
-0223
-0224
-0225 mipGap = 1;
-0226 first = true;
-0227 success = false;
-0228 fullMipRes = [];
-0229 for rn = 1:length(stp.MILPParams)
-0230 params = stp.MILPParams{rn};
-0231 if ~isfield(params, 'MIPGap')
-0232 params.MIPGap = 0.0004;
-0233 end
-0234
-0235 if ~isfield(params, 'TimeLimit')
-0236 params.TimeLimit = 5000;
-0237 end
-0238
-0239 if ~first
-0240
-0241
-0242
-0243
-0244 params.MIPGap = min(max(params.MIPGap, stp.AbsMIPGaps{rn}/abs(lastObjVal)),1);
-0245 params.seed = 1234;
-0246
-0247 if mipGap <= params.MIPGap
-0248 success = true;
-0249 break;
-0250 else
-0251 disp(['MipGap too high, trying with a different run. MipGap = ' num2str(mipGap) ' New MipGap Limit = ' num2str(params.MIPGap)])
-0252 end
-0253 end
+0185 if (~isempty(stp.MetsToIgnore))
+0186 if (~isempty(stp.MetsToIgnore.simpleMets))
+0187
+0188
+0189
+0190 metsToRem = ismember(mm.metNames,stp.MetsToIgnore.simpleMets.mets);
+0191 compsToKeep = find(ismember(mm.comps, stp.MetsToIgnore.simpleMets.compsToKeep));
+0192 metsToRem = metsToRem & ~ismember(mm.metComps, compsToKeep);
+0193 mm.S(metsToRem,:) = 0;
+0194 end
+0195 end
+0196
+0197
+0198 rxnsToIgnore = getRxnsFromPattern(stp.RxnsToIgnoreMask, prepData);
+0199 rxnScores = groupRxnScores(prepData.minModel, origRxnScores, prepData.refModel.rxns, prepData.groupIds, rxnsToIgnore);
+0200
+0201 essentialRxns = prepData.essentialRxns;
+0202 toRev = false(numel(mm.rxns),1);
+0203
+0204 if strcmp(stp.HowToUsePrevResults, 'exclude')
+0205 rxnScores(rxnsTurnedOn) = 0;
+0206 elseif strcmp(stp.HowToUsePrevResults, 'essential')
+0207
+0208
+0209
+0210
+0211 rev = mm.rev == 1;
+0212 toRev = rxnsTurnedOn & rev & fluxes < 0;
+0213 mm = reverseRxns(mm, mm.rxns(toRev));
+0214
+0215
+0216 mm.rev(rxnsTurnedOn) = 0;
+0217 mm.lb(rxnsTurnedOn) = 0;
+0218
+0219 essentialRxns = unique([prepData.essentialRxns;mm.rxns(rxnsTurnedOn)]);
+0220 end
+0221
+0222
+0223 mipGap = 1;
+0224 first = true;
+0225 success = false;
+0226 fullMipRes = [];
+0227 for rn = 1:length(stp.MILPParams)
+0228 params = stp.MILPParams{rn};
+0229 if ~isfield(params, 'MIPGap')
+0230 params.MIPGap = 0.0004;
+0231 end
+0232
+0233 if ~isfield(params, 'TimeLimit')
+0234 params.TimeLimit = 5000;
+0235 end
+0236
+0237 if ~first
+0238
+0239
+0240
+0241
+0242 params.MIPGap = min(max(params.MIPGap, stp.AbsMIPGaps{rn}/abs(lastObjVal)),1);
+0243 params.seed = 1234;
+0244
+0245 if mipGap <= params.MIPGap
+0246 success = true;
+0247 break;
+0248 else
+0249 disp(['MipGap too high, trying with a different run. MipGap = ' num2str(mipGap) ' New MipGap Limit = ' num2str(params.MIPGap)])
+0250 end
+0251 end
+0252
+0253 first = false;
0254
-0255 first = false;
-0256
-0257
-0258 try
-0259
-0260
-0261
-0262 startVals = [];
-0263 if ~isempty(fullMipRes)
-0264 startVals = fullMipRes.full;
-0265 end
-0266 [deletedRxnsInINIT1, metProduction,fullMipRes,rxnsTurnedOn1,fluxes1] = ftINITInternalAlg(mm,rxnScores,metData,essentialRxns,5,stp.AllowMetSecr,stp.PosRevOff,params, startVals, fluxes, verbose);
-0267
-0268 fluxes1(toRev) = -fluxes1(toRev);
-0269
-0270 mipGap = fullMipRes.mipgap;
-0271 lastObjVal = fullMipRes.obj;
-0272 catch e
-0273 mipGap = Inf;
-0274 lastObjVal = Inf;
-0275 end
-0276
-0277 success = mipGap <= params.MIPGap;
-0278 end
-0279
-0280 if ~success
-0281 dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]);
-0282 end
-0283
-0284
-0285 rxnsTurnedOn = rxnsTurnedOn | rxnsTurnedOn1.';
-0286
-0287
-0288
-0289
-0290
-0291
-0292
-0293 fluxesOld = fluxes;
-0294 fluxes = fluxes1;
-0295
-0296
-0297
-0298
-0299
-0300
-0301
-0302 end
-0303
-0304
-0305
-0306 essential = ismember(prepData.minModel.rxns,prepData.essentialRxns);
-0307
-0308
-0309 rxnsToIgn = rxnScores == 0;
-0310 deletedRxnsInINITSel = ~(rxnsTurnedOn | rxnsToIgn | essential);
-0311 deletedRxnsInINIT = prepData.minModel.rxns(deletedRxnsInINITSel);
-0312
-0313
-0314
-0315 groupIdsRemoved = prepData.groupIds(ismember(prepData.refModel.rxns, deletedRxnsInINIT));
-0316 groupIdsRemoved = groupIdsRemoved(groupIdsRemoved ~= 0);
-0317 rxnsToRem = union(prepData.refModel.rxns(ismember(prepData.groupIds,groupIdsRemoved)), deletedRxnsInINIT);
+0255
+0256 try
+0257
+0258
+0259
+0260 startVals = [];
+0261 if ~isempty(fullMipRes)
+0262 startVals = fullMipRes.full;
+0263 end
+0264 [deletedRxnsInINIT1, metProduction,fullMipRes,rxnsTurnedOn1,fluxes1] = ftINITInternalAlg(mm,rxnScores,metData,essentialRxns,5,stp.AllowMetSecr,stp.PosRevOff,params, startVals, fluxes, verbose);
+0265
+0266 fluxes1(toRev) = -fluxes1(toRev);
+0267
+0268 mipGap = fullMipRes.mipgap;
+0269 lastObjVal = fullMipRes.obj;
+0270 catch e
+0271 mipGap = Inf;
+0272 lastObjVal = Inf;
+0273 end
+0274
+0275 success = mipGap <= params.MIPGap;
+0276 end
+0277
+0278 if ~success
+0279 dispEM(['Failed to find good enough solution within the time frame. MIPGap: ' num2str(mipGap)]);
+0280 end
+0281
+0282
+0283 rxnsTurnedOn = rxnsTurnedOn | rxnsTurnedOn1.';
+0284
+0285
+0286
+0287
+0288
+0289
+0290
+0291 fluxesOld = fluxes;
+0292 fluxes = fluxes1;
+0293
+0294
+0295
+0296
+0297
+0298
+0299
+0300 end
+0301
+0302
+0303
+0304 essential = ismember(prepData.minModel.rxns,prepData.essentialRxns);
+0305
+0306
+0307 rxnsToIgn = rxnScores == 0;
+0308 deletedRxnsInINITSel = ~(rxnsTurnedOn | rxnsToIgn | essential);
+0309 deletedRxnsInINIT = prepData.minModel.rxns(deletedRxnsInINITSel);
+0310
+0311
+0312
+0313 groupIdsRemoved = prepData.groupIds(ismember(prepData.refModel.rxns, deletedRxnsInINIT));
+0314 groupIdsRemoved = groupIdsRemoved(groupIdsRemoved ~= 0);
+0315 rxnsToRem = union(prepData.refModel.rxns(ismember(prepData.groupIds,groupIdsRemoved)), deletedRxnsInINIT);
+0316
+0317 initModel = removeReactions(prepData.refModel,rxnsToRem,false,true);
0318
-0319 initModel = removeReactions(prepData.refModel,rxnsToRem,false,true);
-0320
-0321
-0322 unusedMets = initModel.mets(all(initModel.S == 0,2));
-0323 initModel = removeMets(initModel, setdiff(unusedMets, prepData.essentialMetsForTasks));
-0324
-0325
-0326
-0327
-0328
-0329
-0330
-0331
-0332
-0333
-0334
-0335
-0336 initModel.id = 'INITModel';
-0337
-0338
-0339 if ~isempty(prepData.taskStruct)
-0340
-0341
-0342
-0343
-0344
-0345
-0346
-0347
-0348
-0349
-0350
-0351
-0352
-0353 exchRxns = getExchangeRxns(prepData.refModel);
-0354 refModelNoExc = removeReactions(prepData.refModelWithBM,exchRxns,false,true);
-0355 exchRxns = getExchangeRxns(initModel);
-0356 initModelNoExc = removeReactions(closeModel(initModel),exchRxns,false,true);
-0357
-0358 if useScoresForTasks == true
-0359
-0360 [~,ia,ib] = intersect(refModelNoExc.rxns,prepData.refModel.rxns);
-0361 rxnScores2nd = NaN(length(refModelNoExc.rxns),1);
-0362 rxnScores2nd(ia) = origRxnScores(ib);
-0363
-0364 [outModel,addedRxnMat] = ftINITFillGapsForAllTasks(initModelNoExc,refModelNoExc,[],true,min(rxnScores2nd,-0.1),prepData.taskStruct,paramsFT,verbose);
-0365 else
-0366 [outModel,addedRxnMat] = ftINITFillGapsForAllTasks(initModelNoExc,refModelNoExc,[],true,[],prepData.taskStruct,paramsFT,verbose);
-0367 end
-0368
-0369
-0370
-0371
-0372
-0373 addedRxnsForTasks = refModelNoExc.rxns(any(addedRxnMat,2));
-0374 else
-0375 outModel = initModel;
-0376 addedRxnMat = [];
-0377 addedRxnsForTasks = {};
-0378 end
-0379
-0380
-0381 model = outModel;
-0382
-0383
-0384
-0385
-0386
-0387
-0388
-0389
-0390
-0391
-0392
-0393
-0394
-0395
-0396 exchRxns = getExchangeRxns(prepData.refModel);
-0397 deletedRxnsInINIT = setdiff(prepData.refModel.rxns,union(union(initModel.rxns, addedRxnsForTasks), exchRxns));
-0398 outModel = removeReactions(prepData.refModel, deletedRxnsInINIT, true);
-0399
-0400
-0401
-0402
-0403
-0404 if ( removeGenes )
-0405 [~, geneScores] = scoreComplexModel(outModel,hpaData,transcrData,tissue,celltype);
-0406 outModel = removeLowScoreGenes(outModel,geneScores);
-0407 end
-0408
+0319
+0320 unusedMets = initModel.mets(all(initModel.S == 0,2));
+0321 initModel = removeMets(initModel, setdiff(unusedMets, prepData.essentialMetsForTasks));
+0322
+0323
+0324
+0325
+0326
+0327
+0328
+0329
+0330
+0331
+0332
+0333
+0334 initModel.id = 'INITModel';
+0335
+0336
+0337 if ~isempty(prepData.taskStruct)
+0338
+0339
+0340
+0341
+0342
+0343
+0344
+0345
+0346
+0347
+0348
+0349
+0350
+0351 exchRxns = getExchangeRxns(prepData.refModel);
+0352 refModelNoExc = removeReactions(prepData.refModelWithBM,exchRxns,false,true);
+0353 exchRxns = getExchangeRxns(initModel);
+0354 initModelNoExc = removeReactions(closeModel(initModel),exchRxns,false,true);
+0355
+0356 if useScoresForTasks == true
+0357
+0358 [~,ia,ib] = intersect(refModelNoExc.rxns,prepData.refModel.rxns);
+0359 rxnScores2nd = NaN(length(refModelNoExc.rxns),1);
+0360 rxnScores2nd(ia) = origRxnScores(ib);
+0361
+0362 [outModel,addedRxnMat] = ftINITFillGapsForAllTasks(initModelNoExc,refModelNoExc,[],true,min(rxnScores2nd,-0.1),prepData.taskStruct,paramsFT,verbose);
+0363 else
+0364 [outModel,addedRxnMat] = ftINITFillGapsForAllTasks(initModelNoExc,refModelNoExc,[],true,[],prepData.taskStruct,paramsFT,verbose);
+0365 end
+0366
+0367
+0368
+0369
+0370
+0371 addedRxnsForTasks = refModelNoExc.rxns(any(addedRxnMat,2));
+0372 else
+0373 outModel = initModel;
+0374 addedRxnMat = [];
+0375 addedRxnsForTasks = {};
+0376 end
+0377
+0378
+0379 model = outModel;
+0380
+0381
+0382
+0383
+0384
+0385
+0386
+0387
+0388
+0389
+0390
+0391
+0392
+0393
+0394 exchRxns = getExchangeRxns(prepData.refModel);
+0395 deletedRxnsInINIT = setdiff(prepData.refModel.rxns,union(union(initModel.rxns, addedRxnsForTasks), exchRxns));
+0396 outModel = removeReactions(prepData.refModel, deletedRxnsInINIT, true);
+0397
+0398
+0399
+0400
+0401
+0402 if ( removeGenes )
+0403 [~, geneScores] = scoreComplexModel(outModel,hpaData,transcrData,tissue,celltype);
+0404 outModel = removeLowScoreGenes(outModel,geneScores);
+0405 end
+0406
+0407
+0408 model = outModel;
0409
-0410 model = outModel;
+0410 end
0411
-0412 end
-0413
-0414
-0415 function [rxnS, geneS] = printScores(model,name,hpaData,transcrData,tissue,celltype)
-0416 [a, b] = scoreComplexModel(model,hpaData,transcrData,tissue,celltype);
-0417 rxnS = mean(a);
-0418 geneS = mean(b,'omitnan');
-0419 fprintf([name ':\n']);
-0420 fprintf(['\t' num2str(numel(model.rxns)) ' reactions, ' num2str(numel(model.genes)) ' genes\n']);
-0421 fprintf(['\tMean reaction score: ' num2str(rxnS) '\n']);
-0422 fprintf(['\tMean gene score: ' num2str(geneS) '\n']);
-0423 fprintf(['\tReactions with positive scores: ' num2str(100*sum(a>0)/numel(a)) '%%\n\n']);
-0424 end
-0425
-0426 function rxnsToIgnore = getRxnsFromPattern(rxnsToIgnorePattern, prepData)
-0427 rxnsToIgnore = false(length(prepData.toIgnoreExch),1);
-0428 if rxnsToIgnorePattern(1) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreExch; end;
-0429 if rxnsToIgnorePattern(2) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreImportRxns; end;
-0430 if rxnsToIgnorePattern(3) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreSimpleTransp; end;
-0431 if rxnsToIgnorePattern(4) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreAdvTransp; end;
-0432 if rxnsToIgnorePattern(5) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreSpont; end;
-0433 if rxnsToIgnorePattern(6) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreS; end;
-0434 if rxnsToIgnorePattern(7) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreCustomRxns; end;
-0435 if rxnsToIgnorePattern(8) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreAllWithoutGPRs; end;
-0436 end
-0437
+0412
+0413 function [rxnS, geneS] = printScores(model,name,hpaData,transcrData,tissue,celltype)
+0414 [a, b] = scoreComplexModel(model,hpaData,transcrData,tissue,celltype);
+0415 rxnS = mean(a);
+0416 geneS = mean(b,'omitnan');
+0417 fprintf([name ':\n']);
+0418 fprintf(['\t' num2str(numel(model.rxns)) ' reactions, ' num2str(numel(model.genes)) ' genes\n']);
+0419 fprintf(['\tMean reaction score: ' num2str(rxnS) '\n']);
+0420 fprintf(['\tMean gene score: ' num2str(geneS) '\n']);
+0421 fprintf(['\tReactions with positive scores: ' num2str(100*sum(a>0)/numel(a)) '%%\n\n']);
+0422 end
+0423
+0424 function rxnsToIgnore = getRxnsFromPattern(rxnsToIgnorePattern, prepData)
+0425 rxnsToIgnore = false(length(prepData.toIgnoreExch),1);
+0426 if rxnsToIgnorePattern(1) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreExch; end;
+0427 if rxnsToIgnorePattern(2) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreImportRxns; end;
+0428 if rxnsToIgnorePattern(3) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreSimpleTransp; end;
+0429 if rxnsToIgnorePattern(4) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreAdvTransp; end;
+0430 if rxnsToIgnorePattern(5) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreSpont; end;
+0431 if rxnsToIgnorePattern(6) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreS; end;
+0432 if rxnsToIgnorePattern(7) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreCustomRxns; end;
+0433 if rxnsToIgnorePattern(8) rxnsToIgnore = rxnsToIgnore | prepData.toIgnoreAllWithoutGPRs; end;
+0434 end
+0435
Generated by m2html © 2005