-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadexptdata.m
executable file
·204 lines (195 loc) · 5.71 KB
/
loadexptdata.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
function [ mfamodel ] = loadexptdata( mfamodel,filename,expname,append )
%[MFAMODEL] = LOADEXPTDATA(MFAMODEL,FILENAME,EXPNAME,APPEND) reads the
% experimental data contained within FILENAME and creates a
% DATA structure to be included in MFAMODEL. the DATA structure
% contains a list of measured FLUXES, MSDATA, POOL SIZES, and
% the TRACER scheme for the labeling experiment EXPTNAME. The
% MSDATA may be corrected for natural abundance of unlabeled
% atoms based on options specified in MFAMODEL. APPEND allows
% integration of multiple data sets for improved flux
% estimation accuracy based on COMPLETE-MFA.
% Written by Saratram Gopalakrishnan on 09/09/2016 at 102 MRL, Penn State
flux = struct('name',[],'val',[],'std',[],'on',[]);
pool = struct('name',[],'val',[],'std',[],'on',false);
msdata = struct('name',[],'emu',[],'met',[],'mdv',[],'std',[],'mdvreg',[],'time',[],'on',true);
tracer = struct('met',[],'trc',[]);
trc = struct('name',[],'frac',[],'atmdv',[]);
data = struct('name',expname,'flux',[],'pool',[],'msdata',[],'tracer',[],'on',true);
% Reading expts file
[~,~,raw1] = xlsread(filename,'MSData');
[~,~,raw2] = xlsread(filename,'FluxData');
[~,~,raw3] = xlsread(filename,'TracerData');
% fluxes
flxs = raw2(2:end,:);
for i = 1:length(flxs(:,1))
f1 = flux;
f1.name = flxs(i,1);
f1.val = flxs{i,2};
f1.std = flxs{i,3};
f1.on = true;
data.flux = [data.flux,f1];
end
% pools
data.pool = pool;
if ~mfamodel.options.ss
[~,~,raw4] = xlsread(filename,'PoolData');
raw4 = raw4(2:end,:);
for i = 1:length(raw4(:,1))
p1 = poo1;
p1.name = raw4(i,1);
p1.val = raw4{i,2};
p1.std = raw4{i,3};
p1.on = true;
data.pool = [data.pool,p1];
end
end
% tracers
if mfamodel.options.sim_na
defc = [98.9184,1.0816]/100;
else
defc = [1,0];
end
u = unique(raw3(2:end,1));
for i = 1:length(u)
tr1 = tracer;
tr1.met = u(i);
tx = raw3(ismember(raw3(:,1),u(i)),:);
f = 0;
for j = 1:length(tx(:,1))
tc1 = trc;
tc1.name = tx(j,2);
tc1.frac = tx{j,3};
f = f + tc1.frac;
nc = tx{j,4};
tc1.atmdv = zeros(nc,2);
lpos = tx{j,5};
if ischar(lpos)
lpos = str2num(lpos);
end
pur = tx{j,6}/100;
for k = 1:nc
if ismember(k,lpos)
tc1.atmdv(k,:) = [(1-pur),pur];
else
tc1.atmdv(k,:) = defc;
end
end
end
tr1.trc = [tr1.trc,tc1];
if f < 1
tc1 = trc;
tc1.name = {['U-13C ',u{i}]};
tc1.frac = 1-f;
tc1.atmdv = zeros(nc,2);
for k = 1:nc
tc1.atmdv(k,:) = defc;
end
tr1.trc = [tr1.trc,tc1];
end
data.tracer = [data.tracer,tr1];
end
% MS Data
MDV = raw1(2:end,:);
for i = 1:length(MDV(:,1))
m1 = msdata;
m1.name = MDV(i,1);
m1.emu = MDV(i,2);
[m1.met{1},at] = emu2info(m1.emu{1});
l = length(at);
mz = str2num(MDV{i,4});
if ischar(MDV{i,5})
sz = str2num(MDV{i,5});
elseif isnumeric(MDV{i,5})
sz = MDV{i,5};
end
if length(sz)==1
sz = sz*ones(1,length(mz));
end
atms = decode_fragformula(char(MDV{i,3}));
atms(1) = atms(1) - l;
m1.mdvreg = gen_nat_dil(atms);
if mfamodel.options.fcor
m1.std = sz(1:l+1);
uc = m1.mdvreg(1:length(mz));
M = zeros(length(uc));
M(1,:) = uc;
M = M';
for k = 2:length(uc)
M(k:end,k) = M(k-1:end-1,k-1);
end
cr = M\(mz');
%if length(cr)<(l+1)
% cr((length(cr)+1):(l+1)) = 0;
%end
cr = cr/sum(cr(1:l+1));
m1.mdv = [cr(1:l+1)]';
m1.mdvreg = 1;
else
m1.std = sz;
m1.mdv = mz;
end
if mfamodel.options.default_sd
mx = m1.mdv;
ms = min(0.25,max(0.005,mx));
m1.std = 0.003 + ((0.005-0.003)/(0.25-0.005))*(ms-0.005);
end
if ~mfamodel.options.ss
m1.time = MDV{i,6}/60;
end
data.msdata = [data.msdata,m1];
end
if append
mfamodel.data = [mfamodel.data,data];
else
mfamodel.data = data;
end
mfamodel.level = 3;
end
% Helper Function to split EMU into metabolites and atom positions
function [name,atom_ids] = emu2info(emu_id)
emu = char(emu_id);
pos = strfind(emu,'-');
name = emu(1:(pos(end)-1));
atoms = emu((pos(end)+1):end);
atoms = regexp(atoms,',','split');
atoms = strtrim(atoms);
atom_i = char(atoms);
atom_ids = str2num(atom_i);
if size(atom_ids,1) > 1
atom_ids = atom_ids';
end
end
% Helper Function to generate labeling distribution based on natural
% abundance
function y = gen_nat_dil(atm_f)
at{1,1} = [0.989184 0.010816]; %c
at{2,1} = [0.999844 0.000156]; %h
at{3,1} = [0.99758 0.00038 0.00204]; %o
at{4,1} = [0.996337 0.003663]; %n
at{6,1} = [0.9222 0.0469 0.0309]; %si
at{5,1} = [0.95039 0.0075 0.0421 0 0.0002]; %s
at{7,1} = 1; %p
y = 1;
for i = 1:1:length(atm_f)
for j = 1:1:atm_f(i)
y = conv2(y,at{i,1});
end
end
y = y(y>eps);
end
% Helper function to convert fragment formula into atom types
function y = decode_fragformula(string)
atoms = {'c','h','o','n','s','si','p'};
y = zeros(1,length(atoms));
a = string;
for i = 1:1:length(y)
a = regexp(a,char(atoms(length(y)+1-i)),'split');
if length(a) > 1
if isempty(char(a(2)))
a{2} = '1';
end
y(length(y) + 1 - i) = str2num(char(a(2)));
end
a = char(a(1));
end
end