Home > RAVEN > printFluxes.m

printFluxes

PURPOSE ^

printFluxes

SYNOPSIS ^

function printFluxes(model, fluxes, onlyExchange, cutOffFlux, outputFile,outputString,metaboliteList)

DESCRIPTION ^

 printFluxes
   Prints reactions and fluxes to the screen or to a file

   model           a model structure
   fluxes          a vector with fluxes
   onlyExchange    only print exchange fluxes (opt, default true)
   cutOffFlux      only print fluxes with absolute values above or equal to this 
                   value (opt, default 10^-8)
   outputFile      a file to save the print-out to (opt, default is output to
                   the command window)
   outputString    a string that specifies the output of each reaction (opt,
                   default '%rxnID (%rxnName):%flux\n')
   metaboliteList  cell array of metabolite names. Only reactions
                   involving any of these metabolites will be 
                   printed (opt)

   The following codes are available for user-defined output strings:

   %rxnID      reaction ID
   %rxnName    reaction name
   %lower      lower bound
   %upper      upper bound
   %obj        objective coefficient
   %eqn        equation
   %flux       flux
   %element    equation using the metabolite formulas rather than
               metabolite names
   %unbalanced "(*)" if the reaction is unbalanced and "(-)" if it could not
               be parsed
   %lumped     equation where the elemental compositions for the left/right
               hand sides are lumped

   Usage: printFluxes(model, fluxes, onlyExchange, cutOffFlux,
           outputFile,outputString)

   Rasmus Agren, 2013-08-01

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function printFluxes(model, fluxes, onlyExchange, cutOffFlux, outputFile,outputString,metaboliteList)
0002 % printFluxes
0003 %   Prints reactions and fluxes to the screen or to a file
0004 %
0005 %   model           a model structure
0006 %   fluxes          a vector with fluxes
0007 %   onlyExchange    only print exchange fluxes (opt, default true)
0008 %   cutOffFlux      only print fluxes with absolute values above or equal to this
0009 %                   value (opt, default 10^-8)
0010 %   outputFile      a file to save the print-out to (opt, default is output to
0011 %                   the command window)
0012 %   outputString    a string that specifies the output of each reaction (opt,
0013 %                   default '%rxnID (%rxnName):%flux\n')
0014 %   metaboliteList  cell array of metabolite names. Only reactions
0015 %                   involving any of these metabolites will be
0016 %                   printed (opt)
0017 %
0018 %   The following codes are available for user-defined output strings:
0019 %
0020 %   %rxnID      reaction ID
0021 %   %rxnName    reaction name
0022 %   %lower      lower bound
0023 %   %upper      upper bound
0024 %   %obj        objective coefficient
0025 %   %eqn        equation
0026 %   %flux       flux
0027 %   %element    equation using the metabolite formulas rather than
0028 %               metabolite names
0029 %   %unbalanced "(*)" if the reaction is unbalanced and "(-)" if it could not
0030 %               be parsed
0031 %   %lumped     equation where the elemental compositions for the left/right
0032 %               hand sides are lumped
0033 %
0034 %   Usage: printFluxes(model, fluxes, onlyExchange, cutOffFlux,
0035 %           outputFile,outputString)
0036 %
0037 %   Rasmus Agren, 2013-08-01
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 %Only keep reactions involving the defined metabolites
0072 if ~isempty(metaboliteList)
0073     I=ismember(upper(model.metNames),upper(metaboliteList));
0074     [crap K]=find(model.S(I,:));
0075     
0076     %Delete all other reactions
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 %Remove reactions which are below the cut off
0090 toDelete=abs(fluxes)<cutOffFlux;
0091 model=removeRxns(model,toDelete,true,true);
0092 fluxes(toDelete)=[];
0093 
0094 if any(strfind(outputString,'%eqn'))
0095     %Construct the equations
0096     eqn=constructEquations(model);
0097 else
0098     eqn=cell(numel(model.rxns),1);
0099     eqn(:)={''};
0100 end
0101 if any(strfind(outputString,'%element'))
0102     %For printing equations using the composition
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    %Only print if it's an exchange reaction or if all reactions should be
0157    %printed. Exchange reactions only have reactants or only products.
0158    reactants=model.S(:,i)<0;
0159    products=model.S(:,i)>0;
0160    
0161    %Only print if the absolute value is >= cutOffFlux
0162    if (onlyExchange==false || (~any(reactants) || ~any(products)))
0163        printString=outputString;
0164         
0165        %Produce the final string
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

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005