-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_Kload.m
More file actions
244 lines (181 loc) · 7.65 KB
/
Copy pathrun_Kload.m
File metadata and controls
244 lines (181 loc) · 7.65 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
% run K+ loading experiments with and without MK crosstalk
close all;
clear all;
% simulation 1 (no MK cross talk)
pars1 = set_params();
Kin1.Kin_type = 'long_simulation';
Kin1.Meal = 1;
Kin1.KCL = 1;
MealInfo1.t_breakfast = 7; % enter the hour at which to have breakfast in 24 hour format: for ex: 0 = midnight, 8 = 8am, 15 = 3pm
MealInfo1.t_lunch = 13; % break between mealtimes has to be more than 6 hours for the C_insulin function to work properly
MealInfo1.t_dinner = 19;
MealInfo1.K_amount = 100/3; %120/3; % how much K is ingested PER MEAL 3 times a day
MealInfo1.meal_type = 'Kload';
% get SS intial condition
disp('get sim 1 SS')
IG_file1 = './IGdata/KregSS.mat';
[SSdata1, exitflag1, residual1] = getSS(IG_file1, pars1, Kin1, ...
'MealInfo', {MealInfo1.t_breakfast, MealInfo1.t_lunch, MealInfo1.t_dinner,...
MealInfo1.K_amount, MealInfo1.meal_type});
if exitflag1 <=0
disp('residuals')
disp(residual1)
end
disp('sim 1 SS finished')
% run simulation 1
days = 14; % number of days to run the simulation for
opts = odeset('MaxStep', 20);
x0 = SSdata1;
x_p0 = zeros(size(SSdata1));
t0 = 0;
tf = days*1440; %+ pars1.tchange;%1*1440 + pars1.tchange;
tspan = t0:0.5:tf;
disp('start sim 1')
[T1,X1] = ode15i(@(t,x,x_p) k_reg_mod(t,x,x_p, pars1, ...
'Kin_type', {Kin1.Kin_type, Kin1.Meal, Kin1.KCL}, ...
'MealInfo', {MealInfo1.t_breakfast, MealInfo1.t_lunch, MealInfo1.t_dinner,...
MealInfo1.K_amount, MealInfo1.meal_type}), ...
tspan, x0, x_p0, opts);
disp('sim 1 finished')
% simulation 2 (dt K secretion MKX)
disp('get sim 2 SS')
pars2 = set_params();
Kin2.Kin_type = 'long_simulation';%'gut_Kin';%'Preston_SS';
Kin2.Meal = 1;
Kin2.KCL = 1;
MealInfo2.t_breakfast = 7; % enter the hour at which to have breakfast in 24 hour format: for ex: 0 = midnight, 8 = 8am, 15 = 3pm
MealInfo2.t_lunch = 13; % break between mealtimes has to be more than 6 hours for the C_insulin function to work properly
MealInfo2.t_dinner = 19;
MealInfo2.K_amount = 100/3; %120/3;
MealInfo2.meal_type = 'Kload';
MKX_type = 1; %0 if not doing MK cross talk, 1:dtKsec, 2:cdKsec, 3:cdKreab
MKX_slope = 0.1; % should be -0.1 for cdKreab
if MKX_type
IG_file2 = './IGdata/KregSS_MK.mat';
else
IG_file2 = './IGdata/KregSS.mat';
end
% get SS intitial condition
[SSdata2, exitflag2, residual2] = getSS(IG_file2, pars2, Kin2,...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo2.t_breakfast, MealInfo2.t_lunch, MealInfo2.t_dinner,...
MealInfo2.K_amount, MealInfo2.meal_type});
if exitflag2 <= 0
disp(residual2)
end
% run simulation 2
x0 = SSdata2;
x_p0 = zeros(size(SSdata2));
disp('start simulation 2')
[T2,X2] = ode15i(@(t,x,x_p) k_reg_mod(t,x,x_p, pars2, ...
'Kin_type', {Kin2.Kin_type, Kin2.Meal, Kin2.KCL}, ...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo2.t_breakfast, MealInfo2.t_lunch, MealInfo2.t_dinner,...
MealInfo2.K_amount, MealInfo2.meal_type}), ...
tspan, x0, x_p0, opts);
disp('simulation 2 finished')
% simulation 3 (cd K secretion MKX)
disp('get sim 3 SS')
pars3 = set_params();
Kin3.Kin_type = 'long_simulation';%'gut_Kin';%'Preston_SS';
Kin3.Meal = 1;
Kin3.KCL = 1;
MealInfo3.t_breakfast = 7; % enter the hour at which to have breakfast in 24 hour format: for ex: 0 = midnight, 8 = 8am, 15 = 3pm
MealInfo3.t_lunch = 13; % break between mealtimes has to be more than 6 hours for the C_insulin function to work properly
MealInfo3.t_dinner = 19;
MealInfo3.K_amount = 100/3; %120/3;
MealInfo3.meal_type = 'Kload';
MKX_type = 2; %0 if not doing MK cross talk, 1:dtKsec, 2:cdKsec, 3:cdKreab
MKX_slope = 0.1; % should be -0.1 for cdKreab
if MKX_type
IG_file3 = './IGdata/KregSS_MK.mat';
else
IG_file3 = './IGdata/KregSS.mat';
end
% get SS intitial condition
[SSdata3, exitflag3, residual3] = getSS(IG_file3, pars3, Kin3,...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo3.t_breakfast, MealInfo3.t_lunch, MealInfo3.t_dinner,...
MealInfo3.K_amount, MealInfo3.meal_type});
if exitflag3 <= 0
disp(residual3)
end
% run simulation 3
x0 = SSdata3;
x_p0 = zeros(size(SSdata3));
disp('start simulation 3')
[T3,X3] = ode15i(@(t,x,x_p) k_reg_mod(t,x,x_p, pars3, ...
'Kin_type', {Kin3.Kin_type, Kin3.Meal, Kin3.KCL}, ...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo3.t_breakfast, MealInfo3.t_lunch, MealInfo3.t_dinner,...
MealInfo3.K_amount, MealInfo3.meal_type}), ...
tspan, x0, x_p0, opts);
disp('simulation 3 finished')
% simulation 4 (cd K reabsorption MKX)
disp('get sim 4 SS')
pars4 = set_params();
Kin4.Kin_type = 'long_simulation';%'gut_Kin';%'Preston_SS';
Kin4.Meal = 1;
Kin4.KCL = 1;
MealInfo4.t_breakfast = 7; % enter the hour at which to have breakfast in 24 hour format: for ex: 0 = midnight, 8 = 8am, 15 = 3pm
MealInfo4.t_lunch = 13; % break between mealtimes has to be more than 6 hours for the C_insulin function to work properly
MealInfo4.t_dinner = 19;
MealInfo4.K_amount = 100/3; %120/3;
MealInfo4.meal_type = 'Kload';
MKX_type = 3; %0 if not doing MK cross talk, 1:dtKsec, 2:cdKsec, 3:cdKreab
MKX_slope = -0.1; % should be -0.1 for cdKreab
if MKX_type
IG_file4 = './IGdata/KregSS_MK.mat';
else
IG_file4 = './IGdata/KregSS.mat';
end
% get SS intitial condition
[SSdata4, exitflag4, residual4] = getSS(IG_file4, pars4, Kin4,...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo4.t_breakfast, MealInfo4.t_lunch, MealInfo4.t_dinner,...
MealInfo4.K_amount, MealInfo4.meal_type});
if exitflag4 <= 0
disp(residual4)
end
% run simulation 3
x0 = SSdata4;
x_p0 = zeros(size(SSdata4));
disp('start simulation 4')
[T4,X4] = ode15i(@(t,x,x_p) k_reg_mod(t,x,x_p, pars4, ...
'Kin_type', {Kin4.Kin_type, Kin4.Meal, Kin4.KCL}, ...
'do_M_K_crosstalk', [MKX_type, MKX_slope],...
'MealInfo', {MealInfo4.t_breakfast, MealInfo4.t_lunch, MealInfo4.t_dinner,...
MealInfo4.K_amount, MealInfo4.meal_type}), ...
tspan, x0, x_p0, opts);
disp('simulation 4 finished')
% plot simulation
do_plt = 1;
if do_plt
clear T X params
disp('**plotting simulation results**')
Kin_opts{1} = Kin1;
Kin_opts{2} = Kin2;
Kin_opts{3} = Kin3;
Kin_opts{4} = Kin4;
MealInfo{1} = MealInfo1;
MealInfo{2} = MealInfo2;
MealInfo{3} = MealInfo3;
MealInfo{4} = MealInfo4;
params{1} = pars1;
params{2} = pars2;
params{3} = pars3;
params{4} = pars4;
T{1} = T1;
T{2} = T2;
T{3} = T3;
T{4} = T4;
X{1} = X1;
X{2} = X2;
X{3} = X3;
X{4} = X4;
labels{1} = 'baseline model';
labels{2} = 'MKX-DT-sec';
labels{3} = 'MKX-CD-sec';
labels{4} = 'MKX-CD-reab';
plot_Kload_sim(T,X, params, Kin_opts, labels, tf, MealInfo, days)
end