0001 function [taskReport, essentialRxns, taskStructure, essentialFluxes]=checkTasks(model,inputFile,printOutput,printOnlyFailed,getEssential,taskStructure)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 if nargin<3 || isempty(printOutput)
0049 printOutput=true;
0050 end
0051 if nargin<4 || isempty(printOnlyFailed)
0052 printOnlyFailed=false;
0053 end
0054 if nargin<5 || isempty(getEssential)
0055 getEssential=false;
0056 end
0057
0058
0059 model.b=zeros(numel(model.mets),2);
0060
0061 modelMets=upper(strcat(model.metNames,'[',model.comps(model.metComps),']'));
0062 if ~isfield(model,'unconstrained')
0063 EM='Exchange metabolites should normally not be removed from the model when using checkTasks. Inputs and outputs are defined in the task file instead. Use importModel(file,false) to import a model with exchange metabolites remaining';
0064 dispEM(EM,false);
0065 end
0066
0067
0068 if nargin<6
0069 taskStructure=parseTaskList(inputFile);
0070 end
0071
0072 essentialRxns=false(numel(model.rxns),numel(taskStructure));
0073 essentialFluxes = NaN(numel(model.rxns),numel(taskStructure));
0074
0075 tModel=model;
0076 taskReport=[];
0077 for i=1:numel(taskStructure)
0078 taskReport.id{i,1}=taskStructure(i).id;
0079 taskReport.description{i,1}=taskStructure(i).description;
0080
0081 if ~isempty(taskStructure(i).inputs)
0082 [I, J]=ismember(upper(taskStructure(i).inputs),modelMets);
0083 J=J(I);
0084 K=ismember(upper(taskStructure(i).inputs),'ALLMETS');
0085 L=~cellfun('isempty',strfind(upper(taskStructure(i).inputs),'ALLMETSIN'));
0086
0087
0088 if ~all(I|K|L)
0089 fprintf(['ERROR: Could not find all inputs in "[' taskStructure(i).id '] ' taskStructure(i).description '"\n']);
0090 taskReport.ok(i,1)=false;
0091 tModel=model;
0092 continue;
0093 end
0094 if numel(J)~=numel(unique(J))
0095 EM=['The constraints on some input(s) in "[' taskStructure(i).id '] ' taskStructure(i).description '" are defined more than one time'];
0096 dispEM(EM);
0097 end
0098
0099 if any(K)
0100
0101
0102
0103 if K(1)==0
0104 EM=['ALLMETS is used as an input in "[' taskStructure(i).id '] ' taskStructure(i).description '" but it it not the first metabolite in the list. Constraints defined for the metabolites before it will be over-written'];
0105 dispEM(EM,false);
0106 end
0107
0108
0109 tModel.b(:,1)=taskStructure(i).UBin(find(K,1))*-1;
0110 end
0111
0112 if any(L)
0113 L=find(L);
0114 for j=1:numel(L)
0115
0116 compartment=upper(taskStructure(i).inputs{L(j)}(11:end-1));
0117
0118 C=find(ismember(upper(model.comps),compartment));
0119 if any(C)
0120
0121 tModel.b(model.metComps==C,1)=taskStructure(i).UBin(L(j))*-1;
0122 else
0123 EM=['The compartment defined for ALLMETSIN in "[' taskStructure(i).id '] ' taskStructure(i).description '" does not exist'];
0124 dispEM(EM);
0125 end
0126 end
0127 end
0128
0129 if any(J)
0130 tModel.b(J,1)=taskStructure(i).UBin(I)*-1;
0131 tModel.b(J,2)=taskStructure(i).LBin(I)*-1;
0132 end
0133 end
0134
0135 if ~isempty(taskStructure(i).outputs)
0136 [I, J]=ismember(upper(taskStructure(i).outputs),modelMets);
0137 J=J(I);
0138 K=ismember(upper(taskStructure(i).outputs),'ALLMETS');
0139 L=~cellfun('isempty',strfind(upper(taskStructure(i).outputs),'ALLMETSIN'));
0140
0141
0142 if ~all(I|K|L)
0143 fprintf(['ERROR: Could not find all outputs in "[' taskStructure(i).id '] ' taskStructure(i).description '"\n']);
0144 taskReport.ok(i,1)=false;
0145 tModel=model;
0146 continue;
0147 end
0148 if numel(J)~=numel(unique(J))
0149 EM=['The constraints on some output(s) in "[' taskStructure(i).id '] ' taskStructure(i).description '" are defined more than one time'];
0150 dispEM(EM);
0151 end
0152
0153 if any(K)
0154
0155
0156
0157 if K(1)==0
0158 EM=['ALLMETS is used as an output in "[' taskStructure(i).id '] ' taskStructure(i).description '" but it it not the first metabolite in the list. Constraints defined for the metabolites before it will be over-written'];
0159 dispEM(EM,false);
0160 end
0161
0162
0163 tModel.b(:,2)=taskStructure(i).UBout(find(K,1));
0164 end
0165
0166 if any(L)
0167 L=find(L);
0168 for j=1:numel(L)
0169
0170 compartment=upper(taskStructure(i).outputs{L(j)}(11:end-1));
0171
0172 C=find(ismember(upper(model.comps),compartment));
0173 if any(C)
0174
0175 tModel.b(model.metComps==C,2)=taskStructure(i).UBout(L(j));
0176 else
0177 EM=['The compartment defined for ALLMETSIN in "[' taskStructure(i).id '] ' taskStructure(i).description '" does not exist'];
0178 dispEM(EM);
0179 end
0180 end
0181 end
0182
0183 if any(J)
0184
0185
0186
0187 I = find(I);
0188 nonzero_LBin = tModel.b(J,2) < 0;
0189 nonzero_LBout = taskStructure(i).LBout(I) > 0;
0190 if any(nonzero_LBin & nonzero_LBout)
0191 EM=['The IN LB and OUT LB in "[' taskStructure(i).id '] ' taskStructure(i).description '" cannot be nonzero for the same metabolite'];
0192 dispEM(EM);
0193 end
0194 tModel.b(J(nonzero_LBout),1)=taskStructure(i).LBout(I(nonzero_LBout));
0195 tModel.b(J,2)=taskStructure(i).UBout(I);
0196 end
0197 end
0198
0199 if ~isempty(taskStructure(i).equations)
0200 rxn.equations=taskStructure(i).equations;
0201 rxn.lb=taskStructure(i).LBequ;
0202 rxn.ub=taskStructure(i).UBequ;
0203 rxn.rxns=strcat({'TEMPORARY_'},num2str((1:numel(taskStructure(i).equations))'));
0204
0205
0206 tModel=addRxns(tModel,rxn,3,[],true);
0207 end
0208
0209 if ~isempty(taskStructure(i).changed)
0210 tModel=setParam(tModel,'lb',taskStructure(i).changed,taskStructure(i).LBrxn);
0211 tModel=setParam(tModel,'ub',taskStructure(i).changed,taskStructure(i).UBrxn);
0212 end
0213
0214
0215 sol=solveLP(tModel);
0216 if ~isempty(sol.x)
0217
0218 essentialFluxes(:,i) = sol.x(1:numel(model.rxns));
0219
0220 if ~taskStructure(i).shouldFail
0221 taskReport.ok(i,1)=true;
0222 if printOnlyFailed==false && printOutput==true
0223 fprintf(['PASS: [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0224 end
0225
0226 if getEssential==true
0227 [~, taskEssential]=getEssentialRxns(tModel);
0228
0229
0230 essentialRxns(taskEssential(taskEssential<=numel(model.rxns)),i)=true;
0231 end
0232 else
0233 taskReport.ok(i,1)=false;
0234 if printOutput==true
0235 fprintf(['PASS (should fail): [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0236 end
0237 end
0238 else
0239 if ~taskStructure(i).shouldFail
0240 taskReport.ok(i,1)=false;
0241 if printOutput==true
0242 fprintf(['FAIL: [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0243 end
0244 else
0245 taskReport.ok(i,1)=true;
0246 if printOnlyFailed==false && printOutput==true
0247 fprintf(['FAIL (should fail): [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0248 end
0249 end
0250 end
0251 if taskStructure(i).printFluxes && ~isempty(sol.x)
0252 sol=solveLP(tModel,1);
0253 if ~isempty(sol.x)
0254 printFluxes(tModel,sol.x,false,10^-6,[],'%rxnID (%eqn):%flux\n');
0255 fprintf('\n');
0256 end
0257 end
0258 tModel=model;
0259 end
0260 end