Home > RAVEN > parseRxnEqu.m

parseRxnEqu

PURPOSE ^

parseRxnEqu

SYNOPSIS ^

function metabolites=parseRxnEqu(equations)

DESCRIPTION ^

 parseRxnEqu
   Gets all metabolite names from a cell array of equations

   metabolites=parseRxnEqu(equations)

   equations     A cell array with equation strings

   metabolites   A cell array with the involved metabolites

   The equations should be written like:
   1 A + 3 B (=> or <=>) 5C + 2 D

   If the equation is expressed as for example '... + (n-1) starch' then 
   '(n-1) starch' will be interpreted as one metabolite

   Usage: metabolites=parseRxnEqu(equations)

   Rasmus Agren, 2012-05-27

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function metabolites=parseRxnEqu(equations)
0002 % parseRxnEqu
0003 %   Gets all metabolite names from a cell array of equations
0004 %
0005 %   metabolites=parseRxnEqu(equations)
0006 %
0007 %   equations     A cell array with equation strings
0008 %
0009 %   metabolites   A cell array with the involved metabolites
0010 %
0011 %   The equations should be written like:
0012 %   1 A + 3 B (=> or <=>) 5C + 2 D
0013 %
0014 %   If the equation is expressed as for example '... + (n-1) starch' then
0015 %   '(n-1) starch' will be interpreted as one metabolite
0016 %
0017 %   Usage: metabolites=parseRxnEqu(equations)
0018 %
0019 %   Rasmus Agren, 2012-05-27
0020 %
0021 
0022 if ~iscell(equations)
0023     equations={equations};
0024 end
0025 
0026 metabolites={};
0027 
0028 %Replace the the direction arrows and plus signs with a weird character
0029 %that will be used for parsing
0030 equations=strrep(equations,' <=> ', '¤');
0031 equations=strrep(equations,' => ', '¤');
0032 equations=strrep(equations,' + ', '¤');
0033 equations=strtrim(equations);
0034 
0035 for i=1:numel(equations)
0036     %Split each equation in possible metabolites
0037     candidates=regexp(equations{i},'¤','split');
0038     
0039     %If the splitting character is at the end (if exchange rxns), then an
0040     %empty string will exist together with the real ones. Remove it
0041     candidates(cellfun(@isempty,candidates))=[];
0042     
0043     %Now remove the potential coefficient before each metabolite
0044     for j=1:numel(candidates)
0045         %If the metabolite has a coefficient it will look as 'number name'
0046         space=strfind(candidates{j},' ');
0047         
0048         if isempty(space)
0049             %Add the metabolite
0050             metabolites=[metabolites;candidates(j)];
0051         else
0052             potNumber=candidates{j}(1:space(1));
0053             %I use str2double here which can't deal with fractions (1/3
0054             %glc and so on). I do this because I don't want to risk calling
0055             %functions
0056             [crap,isNumber]=str2num(potNumber);
0057             
0058             if isNumber==1
0059                 %Remove the coefficient
0060                 metName=candidates{j}(space(1)+1:end);
0061                 metabolites=[metabolites;metName];
0062             else
0063                 %The metabolite name contained spaces
0064                 metabolites=[metabolites;candidates(j)];
0065             end
0066         end
0067     end
0068 end
0069 
0070 metabolites=strtrim(metabolites);
0071 
0072 %Upper/lower case is treated as different names. This should be checked for
0073 %later since it's bad modelling practice
0074 metabolites=unique(metabolites);
0075 
0076 end

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