-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimulatingData.m
378 lines (298 loc) · 11.1 KB
/
SimulatingData.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
function [I,O] = SimulatingData(model_type,protocol,params,V,temperature)
%--------------------------------------------------------------------------------------------------------------------------------------
% In this function the initial conditions are identified for the model type and appropriate MexFunction for model is called (with model parameters
% passed to MexFunction) to simulate current in response to specified protocol.
%Temperature Converted to Kelvins
T = 273.15+temperature;
%Initial conditions for each model (using model type defined in modeldata.m)
if model_type==2||model_type==27||model_type==16||model_type==6
IC = [0.0,0.0,0.0,0.0];
end
if model_type==13||model_type==19||model_type==10||model_type==11||model_type==15||model_type==30||model_type==24||model_type==35
IC = [0.0,0.0,0.0];
end
if model_type==5
IC = [1.0,0.0,0.0,0.0,0.0];
end
if model_type==4
IC = [1.0,0.0,0.0];
end
if model_type==3||model_type==91||model_type==7||model_type==22||model_type==8||model_type==18||model_type==21||model_type==23||model_type==25||model_type==28||model_type==29||model_type==9||model_type==1||model_type==2999
IC = [0.0];
end
if model_type==12||model_type==20||model_type==26
IC = [0.0,0.0];
end
%-----------------------------------------------------------------------------------------------------------------------------------------%
% Defines protocol number and protocol length (ms) for each protocol
%-----------------------------------------------------------------------------------------------------------------------------------------%
cd ..
% For non-sine wave protocol the protocol is also passed as additional parameters, avoiding detailed protocol description in Mex function
ProtocolLength = (length(V)/10);
if strcmp(protocol,'sine_wave')==1
protocol_number=1;
end
if strcmp(protocol,'ap')==1
protocol_number=7;
cd Protocols
vv=importdata('ap_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'activation_kinetics_1')==1
protocol_number=9;
cd Protocols
vv=importdata('activation_kinetics_1_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'activation_kinetics_2')==1
protocol_number=11;
cd Protocols
vv=importdata('activation_kinetics_2_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'inactivation')==1
protocol_number=12;
cd Protocols
vv=importdata('inactivation_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'deactivation')==1
protocol_number=13;
cd Protocols
vv=importdata('deactivation_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'steady_activation')==1
protocol_number=14;
cd Protocols
vv=importdata('steady_activation_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'grandi_2hz')==1
protocol_number=18;
cd Protocols
vv=importdata('grandi_2hz_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'grandi_fast')==1
protocol_number=19;
cd Protocols
vv=importdata('grandi_fast_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
if strcmp(protocol,'repeated_activation_step')==1
protocol_number=20;
cd Protocols
vv=importdata('repeated_activation_step_protocol.mat');
cd ..
temp_con = params(end);
params = [params(1:end-1),vv',temp_con];
end
cd Code
%-----------------------------------------------------------------------------------------------------------------------------------------%
% Protocol number is added to start of parameter vector to be passed in mex function
%-----------------------------------------------------------------------------------------------------------------------------------------%
params = [protocol_number,params];
%-----------------------------------------------------------------------------------------------------------------------------------------%
% Using the approriate mex function as determined by the model type, the time vector, initial conditions and parameter vector (including the
% initial element being the protocol_number corresponding to the protocol being simulated) is passed to the mex function. The solution X
% is the probability of being in the open/activated state where there is just one vector, or the solutions of the probability of being in
% multiple different activated or the inactivated state where there are multiple solution outputs.
%-----------------------------------------------------------------------------------------------------------------------------------------%
if model_type==1
X=MexAslanidi([0:0.1:ProtocolLength],IC,params);
end
if model_type==13||model_type==19
X=MexLiu([0:0.1:ProtocolLength],IC,params);
end
if model_type==5
X=MexDiVeroliRT([0:0.1:ProtocolLength],IC,params);
end
if model_type==3
X=MexCourtemanche([0:0.1:ProtocolLength],IC,params);
end
if model_type==16
X=MexMazhari([0:0.1:ProtocolLength],IC,params);
end
if model_type==35
X=MexHH([0:0.1:ProtocolLength],IC,params);
end
if model_type==26
[X1,X2]=MexTenTusscher([0:0.1:ProtocolLength],IC,params);
X=X1;
end
if model_type==2
X=MexClancy([0:0.1:ProtocolLength],IC,params);
end
if model_type==4
X=MexDiVeroliPT([0:0.1:ProtocolLength],IC,params);
end
if model_type==27||model_type==6
X=MexWang([0:0.1:ProtocolLength],IC,params);
end
if model_type==29||model_type==25
X=MexShannon([0:0.1:ProtocolLength],IC,params);
end
if model_type==2999
X=MexZengTol([0:0.1:ProtocolLength],IC,params);
end
if model_type==7
X=MexFox([0:0.1:ProtocolLength],IC,params);
end
if model_type==8
X=MexGrandi([0:0.1:ProtocolLength],IC,params);
end
if model_type==9
X=MexHund([0:0.1:ProtocolLength],IC,params);
end
if model_type==10
[X1,X2,X3]=MexInada([0:0.1:ProtocolLength],IC,params);
X=[X1,X2,X3];
end
if model_type==11
[X1,X2,X3]=MexKurata([0:0.1:ProtocolLength],IC,params);
X=[X1,X2,X3];
end
if model_type==12
[X1,X2]=MexLindblad([0:0.1:ProtocolLength],IC,params);
X=[X1,X2];
end
if model_type==15
[X1,X2,X3]=MexMatsuoka([0:0.1:ProtocolLength],IC,params);
X=[X1,X2,X3];
end
if model_type==18
X=MexNygren([0:0.1:ProtocolLength],IC,params);
end
if model_type==20
[X1,X2]=MexOHara([0:0.1:ProtocolLength],IC,params);
X=[X1,X2];
end
if model_type==21
X=MexPriebe([0:0.1:ProtocolLength],IC,params);
end
if model_type==22
X=MexRamirez([0:0.1:ProtocolLength],IC,params);
end
if model_type==23||model_type==28
X=MexSeemann([0:0.1:ProtocolLength],IC,params);
end
if model_type==24
[X1,X2,X3]=MexSeveri([0:0.1:ProtocolLength],IC,params);
X=[X1,X2,X3];
end
if model_type==30
[X1,X2,X3]=MexZhang([0:0.1:ProtocolLength],IC,params);
X=[X1,X2,X3];
end
if model_type==2999
X=MexZengTol([0:0.1:ProtocolLength],IC,params);
end
%Calculates reversal potential using Nernst equation to be used in current calculation equation. Temperature, extracellular and intracellular potassium concentration correspond to those used in experiment.
F = 96485;
R = 8314;
K_i = 130;
k_o = 4;
erev = ((R*T)/F)*log(k_o/K_i);
O = ones(length(X),1);
Vr = O.*erev;
%-----------------------------------------------------------------------------------------------------------------------------------------%
% Current calculations.
% For Markov models, current is calculated according to
% I = g*O*(V-Vr)
% where the conductance g is the final parameter in the parameter set for each model and O is the probability of being in the open state,
% which corresponds to the solution X for these models.
% Similarly, the current formulation for Hodgkin-Huxley style models is typically of the form
% I = g*Xr*Rr*(V-Vr)
% so for model for which the output of the Mex function X represents Xr*Rr,
% the current can be expressed in the same way as for the Markov model formulations.
if model_type==2||model_type==27||model_type==13||model_type==19||model_type==5||model_type==16||model_type==4||model_type==6||model_type==14||model_type==35
I = params(length(params)).*X.*(V-Vr);
O=X;
end
if model_type==12
I = params(length(params)).*X1.*X2.*(V-Vr);
O=X1.*X2;
end
if model_type==20
Rkr = ones(length(X),1)./((ones(length(X),1)+params(16).*exp((V.*params(17)))).*(ones(length(X),1)+params(18).*exp((V.*params(19)))));
A_fast = ones(length(X),1)./(ones(length(X),1)+params(2).*exp((V.*params(3))));
A_slow = 1-A_fast;
I = params(length(params)).*((A_fast.*X1)+(A_slow.*X2)).*Rkr.*(V-Vr);
O=((A_fast.*X1)+(A_slow.*X2)).*Rkr;
end
if model_type==3||model_type==7
Rkr = ones(length(X),1)./(ones(length(X),1)+params(9).*exp((V.*params(10))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==26
I=params(length(params)).*(X1.*X2.*(V-Vr));
O = X1.*X2;
end
if model_type==18||model_type==21
Rkr = ones(length(X),1)./(ones(length(X),1)+params(8).*exp((V.*params(9))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==23||model_type==28
Rkr = ones(length(X),1)./(ones(length(X),1)+params(6).*exp((V.*params(7))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==8
Rkr = ones(length(X),1)./(ones(length(X),1)+params(11).*exp((V.*params(12))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==9||model_type==25||model_type==29||model_type==2999
Rkr = ones(length(X),1)./(ones(length(X),1)+params(10).*exp((V.*params(11))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==1
Rkr = ones(length(X),1)./(ones(length(X),1)+params(7).*exp((V.*params(8))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==10
I=params(length(params)).*(params(20).*X1 + (1-params(20)).*X2).*X3.*(V-Vr);
O=(params(20).*X1 + (1-params(20)).*X2).*X3;
end
if model_type==11
I=params(length(params)).*(params(18).*X1 + (1-params(18)).*X2).*X3.*(V-Vr);
O=(params(18).*X1 + (1-params(18)).*X2).*X3;
end
if model_type==24
I=params(length(params)).*(params(17).*X1 + ((1-params(17)).*X2)).*X3.*(V-Vr);
O=(params(17).*X1 + ((1-params(17)).*X2)).*X3;
end
if model_type==15
I=params(length(params)).*(params(22).*X1 + (1-params(22)).*X2).*X3.*(V-Vr);
O=(params(22).*X1 + (1-params(22)).*X2).*X3;
end
if model_type==22
Rkr = params(10)+(params(11).*ones(length(X),1))./(ones(length(X),1)+params(12).*exp((V.*params(13))));
I=params(length(params)).*(X.*Rkr.*(V-Vr));
O=X.*Rkr;
end
if model_type==30
I=params(length(params)).*(params(15).*X1 + (1-params(15)).*X2).*X3.*(V-Vr);
O=(params(15).*X1 + (1-params(15)).*X2).*X3;
end