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)
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 if ~iscell(equations) 0020 equations={equations}; 0021 end 0022 0023 metabolites={}; 0024 0025 %Replace the the direction arrows and plus signs with a weird character 0026 %that will be used for parsing 0027 equations=strrep(equations,' <=> ', '€'); 0028 equations=strrep(equations,' => ', '€'); 0029 equations=strrep(equations,' + ', '€'); 0030 equations=strtrim(equations); 0031 0032 for i=1:numel(equations) 0033 %Split each equation in possible metabolites 0034 candidates=regexp(equations{i},'€','split'); 0035 0036 %If the splitting character is at the end (if exchange rxns), then an 0037 %empty string will exist together with the real ones. Remove it 0038 candidates(cellfun(@isempty,candidates))=[]; 0039 0040 %Now remove the potential coefficient before each metabolite 0041 for j=1:numel(candidates) 0042 %If the metabolite has a coefficient it will look as 'number name' 0043 space=strfind(candidates{j},' '); 0044 0045 if isempty(space) 0046 %Add the metabolite 0047 metabolites=[metabolites;candidates(j)]; 0048 else 0049 potNumber=candidates{j}(1:space(1)); 0050 %I use str2double here which can't deal with fractions (1/3 glc 0051 %and so on). I do this because I don't want to risk calling 0052 %functions 0053 [~,isNumber]=str2num(potNumber); 0054 0055 if isNumber==1 0056 %Remove the coefficient 0057 metName=candidates{j}(space(1)+1:end); 0058 metabolites=[metabolites;metName]; 0059 else 0060 %The metabolite name contained spaces 0061 metabolites=[metabolites;candidates(j)]; 0062 end 0063 end 0064 end 0065 end 0066 0067 metabolites=strtrim(metabolites); 0068 0069 %Upper/lower case is treated as different names. This should be checked for 0070 %later since it's bad modelling practice 0071 metabolites=unique(metabolites); 0072 0073 end