-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathparseRxnEqu.m
More file actions
executable file
·73 lines (62 loc) · 2.3 KB
/
Copy pathparseRxnEqu.m
File metadata and controls
executable file
·73 lines (62 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function metabolites=parseRxnEqu(equations)
% 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)
if ~iscell(equations)
equations={equations};
end
metabolites={};
%Replace the the direction arrows and plus signs with a weird character
%that will be used for parsing
equations=strrep(equations,' <=> ', '€');
equations=strrep(equations,' => ', '€');
equations=strrep(equations,' + ', '€');
equations=strtrim(equations);
for i=1:numel(equations)
%Split each equation in possible metabolites
candidates=regexp(equations{i},'€','split');
%If the splitting character is at the end (if exchange rxns), then an
%empty string will exist together with the real ones. Remove it
candidates(cellfun(@isempty,candidates))=[];
%Now remove the potential coefficient before each metabolite
for j=1:numel(candidates)
%If the metabolite has a coefficient it will look as 'number name'
space=strfind(candidates{j},' ');
if isempty(space)
%Add the metabolite
metabolites=[metabolites;candidates(j)];
else
potNumber=candidates{j}(1:space(1));
%I use str2double here which can't deal with fractions (1/3 glc
%and so on). I do this because I don't want to risk calling
%functions
[~,isNumber]=str2num(potNumber);
if isNumber==1
%Remove the coefficient
metName=candidates{j}(space(1)+1:end);
metabolites=[metabolites;metName];
else
%The metabolite name contained spaces
metabolites=[metabolites;candidates(j)];
end
end
end
end
metabolites=strtrim(metabolites);
%Upper/lower case is treated as different names. This should be checked for
%later since it's bad modelling practice
metabolites=unique(metabolites);
end