0001 function printFluxes(model, fluxes, onlyExchange, cutOffFlux, outputFile,outputString,metaboliteList)
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 if nargin<3
0039 onlyExchange=true;
0040 end
0041 if nargin<4
0042 cutOffFlux=10^-8;
0043 end
0044 if isempty(cutOffFlux)
0045 cutOffFlux=10^-8;
0046 end
0047 if nargin<5
0048 fid=1;
0049 else
0050 if ~isempty(outputFile)
0051 outputFile=char(outputFile);
0052 fid=fopen(outputFile,'w');
0053 else
0054 fid=1;
0055 end
0056 end
0057 if nargin<6 || isempty(outputString)
0058 outputString='%rxnID\t(%rxnName):\t%flux\n';
0059 else
0060 outputString=char(outputString);
0061 end
0062 if nargin<7
0063 metaboliteList={};
0064 else
0065 metaboliteList=convertCharArray(metaboliteList);
0066 end
0067 if isempty(fluxes)
0068 EM='Empty vector of fluxes, solveLP possibly returned infeasible';
0069 dispEM(EM);
0070 elseif size(fluxes,1)~=numel(model.rxns)
0071 EM='The number of fluxes and the number of reactions must be the same';
0072 dispEM(EM);
0073 end
0074
0075
0076 if ~isempty(metaboliteList)
0077 I=ismember(upper(model.metNames),upper(metaboliteList));
0078 [~, K]=find(model.S(I,:));
0079
0080
0081 toDelete=true(numel(model.rxns),1);
0082 toDelete(K)=false;
0083 model=removeReactions(model,toDelete);
0084 fluxes(toDelete,:)=[];
0085 end
0086
0087 if onlyExchange==true
0088 fprintf(fid,'EXCHANGE FLUXES:\n');
0089 else
0090 fprintf(fid,'FLUXES:\n');
0091 end
0092
0093
0094 toDelete=abs(fluxes)<cutOffFlux;
0095 toDelete=all(toDelete,2);
0096 model=removeReactions(model,toDelete,true,true);
0097 fluxes(toDelete,:)=[];
0098
0099 if any(strfind(outputString,'%eqn'))
0100
0101 eqn=constructEquations(model);
0102 else
0103 eqn=cell(numel(model.rxns),1);
0104 eqn(:)={''};
0105 end
0106 if any(strfind(outputString,'%element'))
0107
0108 cModel=model;
0109 cModel.metNames=cModel.metFormulas;
0110 cModel.metNames(cellfun(@isempty,cModel.metNames))={'?'};
0111 element=constructEquations(cModel);
0112 else
0113 element=cell(numel(model.rxns),1);
0114 element(:)={''};
0115 end
0116
0117 if any(strfind(outputString,'%unbalanced')) || any(strfind(outputString,'%lumped'))
0118 balanceStructure=getElementalBalance(model);
0119 end
0120
0121 unbalanced=cell(numel(model.rxns),1);
0122 unbalanced(:)={''};
0123 if any(strfind(outputString,'%unbalanced'))
0124 unbalanced(balanceStructure.balanceStatus==0)={'(*)'};
0125 unbalanced(balanceStructure.balanceStatus<0)={'(-)'};
0126 end
0127
0128 lumped=cell(numel(model.rxns),1);
0129 lumped(:)={''};
0130 if any(strfind(outputString,'%lumped'))
0131 for i=1:numel(model.rxns)
0132 leftGroup='';
0133 rightGroup='';
0134 for j=1:numel(balanceStructure.elements.names)
0135 I=balanceStructure.leftComp(i,j);
0136 if I~=0
0137 if I==1
0138 leftGroup=[leftGroup balanceStructure.elements.abbrevs{j}];
0139 else
0140 leftGroup=[leftGroup balanceStructure.elements.abbrevs{j} num2str(I)];
0141 end
0142 end
0143 I=balanceStructure.rightComp(i,j);
0144 if I~=0
0145 if I==1
0146 rightGroup=[rightGroup balanceStructure.elements.abbrevs{j}];
0147 else
0148 rightGroup=[rightGroup balanceStructure.elements.abbrevs{j} num2str(I)];
0149 end
0150 end
0151 end
0152 if model.rev(i)
0153 lumped{i}=[leftGroup ' <=> ' rightGroup];
0154 else
0155 lumped{i}=[leftGroup ' => ' rightGroup];
0156 end
0157 end
0158 end
0159
0160 for i=1:numel(model.rxns)
0161
0162
0163 reactants=model.S(:,i)<0;
0164 products=model.S(:,i)>0;
0165
0166
0167 if (onlyExchange==false || (~any(reactants) || ~any(products)))
0168 printString=outputString;
0169
0170
0171 printString=strrep(printString,'%rxnID',model.rxns{i});
0172 printString=strrep(printString,'%eqn',eqn{i});
0173 printString=strrep(printString,'%rxnName',model.rxnNames{i});
0174 printString=strrep(printString,'%lower',num2str(model.lb(i)));
0175 printString=strrep(printString,'%upper',num2str(model.ub(i)));
0176 printString=strrep(printString,'%obj',num2str(model.c(i)));
0177 printString=strrep(printString,'%flux',num2str(fluxes(i,:)));
0178 printString=strrep(printString,'%element',element{i});
0179 printString=strrep(printString,'%unbalanced',unbalanced{i});
0180 printString=strrep(printString,'%lumped',lumped{i});
0181 fprintf(fid,printString);
0182 end
0183 end
0184
0185 if fid~=1
0186 fprintf('File successfully saved.\n');
0187 fclose(fid);
0188 end
0189 end