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