0001 function [taskReport essentialRxns taskStructure]=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 if nargin<3
0047 printOutput=true;
0048 end
0049 if nargin<4
0050 printOnlyFailed=false;
0051 end
0052 if nargin<5
0053 getEssential=false;
0054 end
0055
0056
0057 model.b=zeros(numel(model.mets),2);
0058
0059 modelMets=upper(strcat(model.metNames,'[',model.comps(model.metComps),']'));
0060 if ~isfield(model,'unconstrained')
0061 fprintf('WARNING: 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.\n');
0062 end
0063
0064
0065 if nargin<6
0066 taskStructure=parseTaskList(inputFile);
0067 end
0068
0069 essentialRxns=false(numel(model.rxns),numel(taskStructure));
0070
0071 tModel=model;
0072 taskReport=[];
0073 for i=1:numel(taskStructure)
0074 taskReport.id{i,1}=taskStructure(i).id;
0075 taskReport.description{i,1}=taskStructure(i).description;
0076
0077 if ~isempty(taskStructure(i).inputs)
0078 [I J]=ismember(upper(taskStructure(i).inputs),modelMets);
0079 J=J(I);
0080 K=ismember(upper(taskStructure(i).inputs),'ALLMETS');
0081 L=~cellfun('isempty',strfind(upper(taskStructure(i).inputs),'ALLMETSIN'));
0082
0083
0084 if ~all(I|K|L)
0085 fprintf(['ERROR: Could not find all inputs in "[' taskStructure(i).id '] ' taskStructure(i).description '"\n']);
0086 taskReport.ok(i,1)=false;
0087 tModel=model;
0088 continue;
0089 end
0090 if numel(J)~=numel(unique(J))
0091 throw(MException('',['The constraints on some input(s) in "[' taskStructure(i).id '] ' taskStructure(i).description '" are defined more than one time']));
0092 end
0093
0094 if any(K)
0095
0096
0097
0098 if K(1)==0
0099 fprintf(['WARNING: 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\n']);
0100 end
0101
0102
0103 tModel.b(:,1)=taskStructure(i).UBin(find(K,1))*-1;
0104 end
0105
0106 if any(L)
0107 L=find(L);
0108 for j=1:numel(L)
0109
0110 compartment=upper(taskStructure(i).inputs{L(j)}(11:end-1));
0111
0112 C=find(ismember(upper(model.comps),compartment));
0113 if any(C)
0114
0115 tModel.b(model.metComps==C,1)=taskStructure(i).UBin(L(j))*-1;
0116 else
0117 throw(MException('',['The compartment defined for ALLMETSIN in "[' taskStructure(i).id '] ' taskStructure(i).description '" does not exist']));
0118 end
0119 end
0120 end
0121
0122 if any(J)
0123 tModel.b(J,1)=taskStructure(i).UBin(I)*-1;
0124 tModel.b(J,2)=taskStructure(i).LBin(I)*-1;
0125 end
0126 end
0127
0128 if ~isempty(taskStructure(i).outputs)
0129 [I J]=ismember(upper(taskStructure(i).outputs),modelMets);
0130 J=J(I);
0131 K=ismember(upper(taskStructure(i).outputs),'ALLMETS');
0132 L=~cellfun('isempty',strfind(upper(taskStructure(i).outputs),'ALLMETSIN'));
0133
0134
0135 if ~all(I|K|L)
0136 fprintf(['ERROR: Could not find all outputs in "[' taskStructure(i).id '] ' taskStructure(i).description '"\n']);
0137 taskReport.ok(i,1)=false;
0138 tModel=model;
0139 continue;
0140 end
0141 if numel(J)~=numel(unique(J))
0142 throw(MException('',['The constraints on some output(s) in "[' taskStructure(i).id '] ' taskStructure(i).description '" are defined more than one time']));
0143 end
0144
0145 if any(K)
0146
0147
0148
0149 if K(1)==0
0150 fprintf(['WARNING: 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\n']);
0151 end
0152
0153
0154 tModel.b(:,2)=taskStructure(i).UBout(find(K,1));
0155 end
0156
0157 if any(L)
0158 L=find(L);
0159 for j=1:numel(L)
0160
0161 compartment=upper(taskStructure(i).outputs{L(j)}(11:end-1));
0162
0163 C=find(ismember(upper(model.comps),compartment));
0164 if any(C)
0165
0166 tModel.b(model.metComps==C,2)=taskStructure(i).UBout(L(j));
0167 else
0168 throw(MException('',['The compartment defined for ALLMETSIN in "[' taskStructure(i).id '] ' taskStructure(i).description '" does not exist']));
0169 end
0170 end
0171 end
0172
0173 if any(J)
0174 tModel.b(J,1)=taskStructure(i).LBout(I);
0175 tModel.b(J,2)=taskStructure(i).UBout(I);
0176 end
0177 end
0178
0179 if ~isempty(taskStructure(i).equations)
0180 rxn.equations=taskStructure(i).equations;
0181 rxn.lb=taskStructure(i).LBequ;
0182 rxn.ub=taskStructure(i).UBequ;
0183 rxn.rxns=strcat({'TEMPORARY_'},num2str((1:numel(taskStructure(i).equations))'));
0184
0185
0186 tModel=addRxns(tModel,rxn,3,[],true);
0187 end
0188
0189 if ~isempty(taskStructure(i).changed)
0190 tModel=setParam(tModel,'lb',taskStructure(i).changed,taskStructure(i).LBrxn);
0191 tModel=setParam(tModel,'ub',taskStructure(i).changed,taskStructure(i).UBrxn);
0192 end
0193
0194
0195 sol=solveLP(tModel);
0196 if ~isempty(sol.x)
0197 if ~taskStructure(i).shouldFail
0198 taskReport.ok(i,1)=true;
0199 if printOnlyFailed==false && printOutput==true
0200 fprintf(['PASS: [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0201 end
0202
0203 if getEssential==true
0204 [crap taskEssential]=getEssentialRxns(tModel);
0205
0206
0207 essentialRxns(taskEssential(taskEssential<=numel(model.rxns)),i)=true;
0208 end
0209 else
0210 taskReport.ok(i,1)=false;
0211 if printOutput==true
0212 fprintf(['PASS (should fail): [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0213 end
0214 end
0215 else
0216 if ~taskStructure(i).shouldFail
0217 taskReport.ok(i,1)=false;
0218 if printOutput==true
0219 fprintf(['FAIL: [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0220 end
0221 else
0222 taskReport.ok(i,1)=true;
0223 if printOnlyFailed==false && printOutput==true
0224 fprintf(['FAIL (should fail): [' taskStructure(i).id '] ' taskStructure(i).description '\n']);
0225 end
0226 end
0227 end
0228 if taskStructure(i).printFluxes
0229 sol=solveLP(tModel,1);
0230 if ~isempty(sol.x)
0231 printFluxes(tModel,sol.x,false,10^-6,[],'%rxnID (%eqn):%flux\n');
0232 fprintf('\n');
0233 end
0234 end
0235 tModel=model;
0236 end
0237 end