printRxnFormula

PURPOSE ^

printRxnFormula Print the reaction formulas for a list of reactions

SYNOPSIS ^

function formulas = printRxnFormula(model,rxnAbbrList,printFlag,lineChangeFlag,metNameFlag,fid,directionFlag)

DESCRIPTION ^

printRxnFormula Print the reaction formulas for a list of reactions


INPUTS
 model             COBRA model structure

OPTIONAL INPUTS
 rxnAbbrList       Abbrs of reactions whose formulas are to be printed
 printFlag         Print formulas or just return them (Default = true)
 lineChangeFlag    Append a line change at the end of each line
                   (Default = true)
 metNameFlag       print full met names instead of abbreviations 
                   (Default = false)
 fid               Optional file identifier for printing in files
 directionFlag     Checks directionality of reaction. See Note.
                   (Default = true)

OUTPUT
 formulas          Cell array containing formulas of specified reactions

 NOTE: Reactions that have an upperbound <= 0 and lowerbound < 0 will have
 its directionality reversed unless directionFlag = false.

 Markus Herrgard 11/17/05

 04/30/08 Ronan Fleming
 altered code since findRxnIDs used abbreviations not names of reactions

 10/11/09 Jeff Orth
 added metNameFlag option

 03/10/10 Richard Que
 added lb < 0 requirement for reversing directionality

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function formulas = printRxnFormula(model,rxnAbbrList,printFlag,lineChangeFlag,metNameFlag,fid,directionFlag)
0002 %printRxnFormula Print the reaction formulas for a list of reactions
0003 %
0004 %
0005 %INPUTS
0006 % model             COBRA model structure
0007 %
0008 %OPTIONAL INPUTS
0009 % rxnAbbrList       Abbrs of reactions whose formulas are to be printed
0010 % printFlag         Print formulas or just return them (Default = true)
0011 % lineChangeFlag    Append a line change at the end of each line
0012 %                   (Default = true)
0013 % metNameFlag       print full met names instead of abbreviations
0014 %                   (Default = false)
0015 % fid               Optional file identifier for printing in files
0016 % directionFlag     Checks directionality of reaction. See Note.
0017 %                   (Default = true)
0018 %
0019 %OUTPUT
0020 % formulas          Cell array containing formulas of specified reactions
0021 %
0022 % NOTE: Reactions that have an upperbound <= 0 and lowerbound < 0 will have
0023 % its directionality reversed unless directionFlag = false.
0024 %
0025 % Markus Herrgard 11/17/05
0026 %
0027 % 04/30/08 Ronan Fleming
0028 % altered code since findRxnIDs used abbreviations not names of reactions
0029 %
0030 % 10/11/09 Jeff Orth
0031 % added metNameFlag option
0032 %
0033 % 03/10/10 Richard Que
0034 % added lb < 0 requirement for reversing directionality
0035 
0036 if (nargin < 2)
0037     rxnAbbrList = model.rxns;
0038 end
0039 if (nargin < 3)
0040     printFlag = true;
0041 end
0042 if (nargin < 4)
0043     lineChangeFlag = true;
0044 end
0045 if (nargin <5)
0046     metNameFlag = false;
0047 end
0048 if (nargin < 6)
0049     fid = 1;
0050 end
0051 if (nargin < 7)
0052     directionFlag = true;
0053 end
0054 
0055 if (~iscell(rxnAbbrList))
0056     if (strcmp(rxnAbbrList,'all'))
0057         rxnAbbrList = model.rxns;
0058     else
0059         rxnAbbrTmp = rxnAbbrList;
0060         clear rxnAbbrList;
0061         rxnAbbrList{1} = rxnAbbrTmp;
0062     end
0063 end
0064 
0065 for i = 1:length(rxnAbbrList);
0066 
0067     rxnAbbr = rxnAbbrList{i};
0068 
0069     rxnID = findRxnIDs(model,rxnAbbr);
0070 
0071     if (printFlag)
0072         fprintf(fid,'%s\t',rxnAbbr);
0073     end
0074     
0075     if (rxnID > 0)
0076 
0077         Srxn = full(model.S(:,rxnID));
0078 
0079         if directionFlag && (isfield(model,'ub') && model.ub(rxnID) <= 0) && (isfield(model,'lb') && model.lb(rxnID) < 0)
0080             Srxn = -Srxn;
0081         end
0082 
0083         Sprod = (Srxn(Srxn > 0));
0084         if metNameFlag
0085             prodMets = model.metNames(Srxn > 0);
0086         else
0087             prodMets = model.mets(Srxn > 0);
0088         end
0089         
0090         Sreact = (Srxn(Srxn < 0));
0091         if metNameFlag
0092             reactMets = model.metNames(Srxn < 0);
0093         else
0094             reactMets = model.mets(Srxn < 0);
0095         end
0096         
0097         formulaStr = '';
0098         for j = 1:length(reactMets)
0099             if (j > 1)
0100                 if (printFlag)
0101                     fprintf(fid,'+ ');
0102                 end
0103                 formulaStr = [formulaStr '+ '];
0104             end
0105             if (abs(Sreact(j)) ~= 1)
0106                 if (printFlag)
0107                     fprintf(fid,'%f %s ',abs(Sreact(j)),reactMets{j});
0108                 end
0109                 formulaStr = [formulaStr num2str(abs(Sreact(j))) ' ' reactMets{j} ' '];
0110             else
0111                 if (printFlag)
0112                     fprintf(fid,'%s ',reactMets{j});
0113                 end
0114                 formulaStr = [formulaStr reactMets{j} ' '];
0115             end
0116         end
0117 
0118         if (model.rev(rxnID))
0119             if (printFlag)
0120                 fprintf(fid,'\t<=>\t');
0121             end
0122             formulaStr = [formulaStr ' <=> '];
0123         else
0124             if (printFlag)
0125                 fprintf(fid,'\t->\t');
0126             end
0127             formulaStr = [formulaStr ' -> '];
0128         end
0129         
0130         if 0
0131             if length(formulaStr)>200
0132                 %most probably this is the biomass reaction
0133                 if (printFlag)
0134                     fprintf(fid,'\n');
0135                 end
0136             end
0137         end
0138         
0139         for j = 1:length(prodMets)
0140             if (j > 1)
0141                 if (printFlag)
0142                     fprintf(fid,'+ ');
0143                 end
0144                 formulaStr = [formulaStr '+ '];
0145             end
0146             if (Sprod(j) ~= 1)
0147                 if (printFlag)
0148                     fprintf(fid,'%f %s ',Sprod(j),prodMets{j});
0149                 end
0150                 formulaStr = [formulaStr num2str(Sprod(j)) ' ' prodMets{j} ' '];
0151             else
0152                 if (printFlag)
0153                     fprintf(fid,'%s ',prodMets{j});
0154                 end
0155                 formulaStr = [formulaStr prodMets{j} ' '];
0156             end
0157         end
0158         if (printFlag) & 0
0159             fprintf('\t.');
0160         end
0161         
0162     else
0163         if (printFlag)
0164             fprintf(fid,'not in model');
0165         end
0166         formulaStr = 'NA';
0167     end
0168     if (printFlag)
0169         if (rxnID > 0) && (isfield(model,'grRules'))
0170             if (isempty(model.grRules{rxnID}))
0171                 fprintf('\t');
0172             else
0173                 fprintf('\t%s',model.grRules{rxnID});
0174             end
0175         end
0176         if (lineChangeFlag)
0177             fprintf(fid,'\n');
0178         end
0179     end
0180     formulas{i} = formulaStr;
0181 
0182 end
0183 formulas = formulas';

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003