/
readCD.m
51 lines (42 loc) · 1.84 KB
/
readCD.m
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
function [r_info] = readCD(parsed)
% Convert the a type of the parsed model structure (orgnised by reaction)
% into the other type of the parsed model structure (organised by property
% (namely, ID, width, colour, etc.)
%
% USAGE:
%
% [r_info] = readCD(parsed)
%
% INPUT:
% parsed: the first type of the parsed model structure outputed by
% `parseCD` function (more user-friendely to modify speicfic
% graphic properties for specific reactions)
%
% OUTPUT:
% r_info: the second type of the parsed model structure (similar to a
% COBRA Matlab structure).
%
% .. Author: - Longfei Mao Oct/2014
parsed_temp=rmfield(parsed,'r_info');
r_info_temp.ID=fieldnames(parsed_temp);
% a={'ID','reactant','product','number','width','color'};
names_l1=fieldnames(parsed);
attribute=fieldnames(parsed.(names_l1{1}))' % retrieve the field names of the first entry of the model structure.
% attribute={'number','width','color'}; % add any attribute names here
for r=1:length(r_info_temp.ID(:,1)); % number of reactions
if strcmp(r_info_temp.ID{r},'r_info')~=1; % excluding the field, 'r_info'.
for e=1:length(attribute); % number of attributes
if isfield(parsed.(r_info_temp.ID{r}),(attribute{e})) % Check if the field name exsits. In some cases, the field name may not appear for some entiries.
for s=1:length(parsed.(r_info_temp.ID{r}).(attribute{e})(1,:))
r_info_temp.(attribute{e})(r,s)=parsed.(r_info_temp.ID{r}).(attribute{e})(1,s)
end
end
end
end
end
if isfield(parsed.r_info,'species')
r_info_temp.species=parsed.r_info.species;
end
r_info=r_info_temp;
r_info=rmfield(r_info,'name');
r_info.ID(:,2:(size(r_info_temp.name,2)+1))=r_info_temp.name(:,:);