-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlipidturnover.html
More file actions
574 lines (489 loc) · 20.2 KB
/
Copy pathlipidturnover.html
File metadata and controls
574 lines (489 loc) · 20.2 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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lipid turnover</title>
<!--MATHJAX typing maths like in latex-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
src="https://cdn.rawgit.com/mathjax/MathJax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- MATHJAX-->
<!-- jQuery -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- JSXgraph -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.99.3/jsxgraphcore.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<!-- style for JSXgraph -->
<style>
.jxgbox {
width:200px;
height:200px;
}
@media screen and (min-width: 600px) {
.jxgbox {
width:250px;
height:250px;
}
}
.pre-x-scrollable {
overflow-x: auto;
word-wrap: normal;
white-space: pre;
}
</style>
<!--<body style="padding-top: 50px;">-->
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0px;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html" class="active">Home</a></li>
</ul>
<p class="navbar-text">Lipid Turnover</p>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<!--CONTENT HERE-->
<div class="col-xs-12 col-sm-12 col-md-12" id="applet">
<h4></h4>
<div class="col-xs-12 col-md-3">
<p>Time</p>
<div class="btn-group" role="group">
<button type="submit" class="btn btn-primary" name="pm" id="minus" data-min-text="min"
onclick="dt=-1;update();">-</button>
<button type="submit" class="btn btn-primary" name="pm"
id="time_info">0.0</button>
<button type="submit" class="btn btn-primary" name="pm" id="plus" data-max-text="max"
onclick="dt=1;update();">+</button>
</div>
<button type="submit" class="btn btn-primary" id="run"
onclick="resetBoard();runLipidTurnover();">Run</button>
<p class="text-info"><small>Use the +/– buttons to change time. Press run to run a new simulation.</small></p>
</div>
<div class="col-xs-12 col-md-7">
<p>Parameters</p>
<div class="input-group">
<span class="input-group-addon" id="inputF0" data-toggle="tooltip" title="initial number of droplets" data-container="body">$F_0$</span>
<input type="text" class="form-control" id="newF0" placeholder="25" value="25" aria-describedby="inputF0">
<span class="input-group-addon" id="inputA0" data-toggle="tooltip" title="initial lipid age" data-container="body">$A_0$</span>
<input type="text" class="form-control" id="newA0" placeholder="0.0" value="0.0" aria-describedby="inputA0">
<span class="input-group-addon" id="inputKin" data-toggle="tooltip" title="Lipid uptake rate. If Kin > 1.0 droplet number will increase, if Kin < 1.0, droplet number will decrease" data-container="body">Rel $K_{in}$</span>
<input type="text" class="form-control" id="newKin" placeholder="1.0" value="1.0" aria-describedby="inputKin">
<span class="input-group-addon" id="inputKout" data-toggle="tooltip" title="Removal rate" data-container="body">$K_{out}$</span>
<input type="text" class="form-control" id="newKout" placeholder="0.70" value="0.70" aria-describedby="inputKout">
</div>
<div class="input-group">
<span class="input-group-addon" id="inputKinMod" data-toggle="tooltip" title="value of Kin between t1 and t2" data-container="body">Rel $K_{in}$ mod</span>
<input type="text" class="form-control" id="newKinMod" placeholder="1.0" value="1.0" aria-describedby="inputKinMod">
<span class="input-group-addon" id="inputKoutMod" data-toggle="tooltip" title="value of Kout between t1 and t2" data-container="body">$K_{out}$ mod</span>
<input type="text" class="form-control" id="newKoutMod" placeholder="0.70" value="0.70" aria-describedby="inputKoutMod">
<span class="input-group-addon" id="inputt1" data-toggle="tooltip" title="beginning of modified Kin and Kout" data-container="body">$t_1$</span>
<input type="text" class="form-control" id="newt1" placeholder="5.0" value="5.0" aria-describedby="inputt1">
<span class="input-group-addon" id="inputt2" data-toggle="tooltip" title="end of modified Kin and Kout" data-container="body">$t_2$</span>
<input type="text" class="form-control" id="newt2" placeholder="10.0" value="10.0" aria-describedby="inputt2">
</div>
</div>
<div class="clearfix visible-md-block"></div>
<div class="col-xs-12 col-md-3">
<h4>Lipid distribution</h4>
<div id="lipidDistributionBox" class="jxgbox"></div>
</div>
<div class="col-xs-12 col-md-3">
<h4>Histogram lipid age</h4>
<div id="lipidHistBox" class="jxgbox"></div>
</div>
<div class="col-xs-12 col-md-3">
<h4>Average lipid age</h4>
<div id="lipidAgeBox" class="jxgbox"></div>
</div>
<div class="col-xs-12 col-md-3">
<h4>Number of lipid droplets</h4>
<div id="numberBox" class="jxgbox"></div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<h4>Lipid Turnover</h4>
<p>Description goes here</p>
</div>
</div><!--row-->
</div><!--container-fluid-->
<script>
// initialize tooltips
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
// global simulation parameters
var maxSteps = 50000;
// Time interval
var Tfinal = 15.0;
var t1 = parseFloat($("#newt1").val());
var t2 = parseFloat($("#newt2").val());
var F0 = parseInt($("#newF0").val());
var A0 = parseFloat($("#newA0").val());
var Kin = F0*parseFloat($("#newKin").val());
var KinMod = F0*parseFloat($("#newKinMod").val());
var Kout = parseFloat($("#newKout").val());
var KoutMod = parseFloat($("#newKoutMod").val());
function sum(array)
{
var total = 0.0;
for (var i = 0, n = array.length; i < n; i++)
{
total += array[i];
}
return total;
}
function mean(array)
{
if ( array.length > 0 )
{
return ( sum(array)/array.length )
}
else
{
return 0.0;
}
}
function exprand(mu)
{
return Math.log(1/(1-Math.random()))/mu;
}
function randn(mu, sigma)
{
var u, v, x, y, q;
do {
u = Math.random();
v = 1.7156*( Math.random()-0.5 );
x = u - 0.449871;
y = Math.abs(v) + 0.386595;
q = x*x + y*(0.19600*y-0.25472*x);
} while ( q > 0.27597 && (q > 0.27846 || v*v > -4.0*Math.log(u)*u*u) );
return (mu + sigma*v/u);
}
function hist(array,x0,x1,nbrBins)
{
var bar = [];
bar.length = nbrBins;
bar.fill(0); // fill bar with zeroes
var bins = [];
bins.length = nbrBins;
var h = (x1-x0)/(nbrBins+1.0);
for (var i = 0; i < nbrBins; i++)
{
bins[i] = i*h;
}
for (var i = 0; i < array.length; i++)
{
var ind = bins.findIndex( function(el) { return el > array[i] } )
if (ind < 0)
{
ind = bins.length;
}
bar[ind-1]++;
}
var myhist = { bins: bins, bar: bar};
return myhist;
}
// Initialise ODE and solve it with JXG.Math.Numerics.rungeKutta()
function ode() {
// evaluation interval
var tspan = [0, Tfinal];
// Number of steps. 1000 should be enough
var Nsteps = 1000;
// Right hand side of the ODE dx/dt = f(t, x)
var f = function(t, xx) {
var removal_rate = xx[0] * ( Kout*(t<t1 | t>=t2) + KoutMod*(t>=t1 & t<t2) );
var uptake_rate = Kin*(t<t1 | t>=t2) + KinMod*(t>=t1 & t<t2);
var dxdt = [];
// expected number of lipid droplets
dxdt[0] = uptake_rate - removal_rate;
dxdt[1] = 1 - ( Kout*(t<t1 | t>=t2) + KoutMod*(t>=t1 & t<t2) ) * xx[1] - dxdt[0]/xx[0] * xx[1];
return dxdt;
}
// Initial value
var x0 = [F0, A0];
// Solve ode
var ode_sol = JXG.Math.Numerics.rungeKutta('rk4', x0, tspan, Nsteps, f);
// to plot the data against time we need the times where the equations were solved
var t = [];
var q = tspan[0];
var h = (tspan[1]-tspan[0])/Nsteps;
for(var i=0; i<ode_sol.length; i++) {
ode_sol[i].push(q);
q += h;
}
return ode_sol;
}
// Initialise the process and solve it
function solveBD() {
var data = {age:[], avgAge:[], F:[], tj:[], t:[], px:[], py:[]};
var u; // unif random
var r; // exp random
var removal_rate;
var uptake_rate;
var dt; // time step
var remove; // index to remove
var j = 0;
// droplet number
data.F[0] = F0;
var N = F0;
// average Age
var age = [];
for(var i=0;i<N;i++)
{
age[i] = A0;
}
data.avgAge[0] = A0;
data.age[0] = age.slice();
// time
data.t[0] = 0.0;
data.tj[0] = j;
// position
var px = [];
var py = [];
for(i=0;i<N;i++)
{
px[i] = Math.random();
py[i] = Math.random();
}
data.px[0] = px.slice();
data.py[0] = py.slice();
// Solve
while(data.t[j] < Tfinal & j < maxSteps)
{
// get dt
removal_rate = N * ( Kout*(data.t[j]<t1 | data.t[j]>t2) + KoutMod*(data.t[j]>=t1 & data.t[j]<t2) );
uptake_rate = Kin*(data.t[j]<t1 | data.t[j]>t2) + KinMod*(data.t[j]>=t1 & data.t[j]<t2);
r = removal_rate + uptake_rate;
dt = exprand( r );
//console.log("r = " + r.toString() + ", dt = " + dt.toString());
// choose event
var u = Math.random();
if ( u < uptake_rate/r)
{
// new lipid droplet
px.splice(0,0, Math.random());
py.splice(0,0, Math.random());
age.splice(0,0,0.0);
N++;
}
else
{
// remove a random lipid droplet
remove = Math.floor((Math.random() * N));
//update the system
age.splice(remove,1);
px.splice(remove,1);
py.splice(remove,1);
N--;
}
for (var i = 0, n = age.length; i < n; i++)
{
age[i] += dt;
}
// update data
data.tj[j+1] = j+1;
data.px[j+1] = px.slice();
data.py[j+1] = py.slice();
data.age[j+1] = age.slice();
data.avgAge[j+1] = mean(data.age[j+1])
data.F[j+1] = N;
data.t[j+1] = data.t[j] + dt;
j++;
}
return data;
}
var normalizedata = function(datan,nbr) {
var d = [];
var maxAge = 5.0;
for(var i=0; i<nbr; i++) {
d[i] = Math.min( datan[i], maxAge )/maxAge;
}
return d; // d normalized to 0 <= d <= 1
};
function resetBoard() {
var newF0 = parseInt($("#newF0").val());
if (newF0 > 0) {
F0 = newF0;
}
var newA0 = parseFloat($("#newA0").val());
if (newA0 >= 0.0) {
A0 = newA0;
}
var newKin = parseFloat($("#newKin").val());
if (newKin >= 0.0) {
Kin = F0*newKin;
}
var newKinMod = parseFloat($("#newKinMod").val());
if (newKinMod >= 0.0) {
KinMod = F0*newKinMod;
}
var newKout = parseFloat($("#newKout").val());
if (newKout >= 0.0) {
Kout = newKout;
}
var newKoutMod = parseFloat($("#newKoutMod").val());
if (newKoutMod >= 0.0) {
KoutMod = newKoutMod;
}
var newt1 = parseFloat($("#newt1").val());
if (newt1 >= 0.0) {
t1 = newt1;
}
var newt2 = parseFloat($("#newt2").val());
if (newt2 >= 0.0) {
t2 = newt2;
}
JXG.JSXGraph.freeBoard(brdDroplets);
JXG.JSXGraph.freeBoard(brdLipidAge);
//brdDroplets = JXG.JSXGraph.initBoard('lipidDistributionBox', {boundingbox:[-0.1,1.1, 1.1, -0.1],
//keepaspectratio:false, showNavigation:false});
//brdLipidAge = JXG.JSXGraph.initBoard('lipidAgeBox', {boundingbox:[-0.5, 5.0, Tfinal, -0.5],
//keepaspectratio:false, showNavigation:false, axis: true,});
//brdLipidNumber = JXG.JSXGraph.initBoard('numberBox', {boundingbox:[-0.5, 2*F0, Tfinal, -1],
//keepaspectratio:false, showNavigation:false, axis: true,});
}
function runLipidTurnover() {
plot_time = 0;
$( "#time_info" ).html(plot_time.toString());
data = [];
data = solveBD();
ode_sol = ode();
// creating the heat map.
brdDroplets = JXG.JSXGraph.initBoard('lipidDistributionBox', {boundingbox:[-0.1,1.1, 1.1, -0.1],
keepaspectratio:false, showNavigation:false, showCopyright: false});
brdHistAge = JXG.JSXGraph.initBoard('lipidHistBox', {boundingbox:[-1,F0, 12, -0.05*F0],
keepaspectratio:false, showNavigation:false, axis: true, showCopyright: false});
var maxAge = 1.2*Math.max(...data.avgAge);
brdLipidAge = JXG.JSXGraph.initBoard('lipidAgeBox', {boundingbox:[-0.5,maxAge, Tfinal, -0.05*maxAge],
keepaspectratio:false, showNavigation:false, axis: true, showCopyright: false});
var maxNbr = 1/Math.min(Kout,KoutMod)*Math.max(Kin,KinMod);
maxNbr = 1.1*maxNbr+3*Math.sqrt(maxNbr);
brdLipidNumber = JXG.JSXGraph.initBoard('numberBox', {boundingbox:[-0.5, maxNbr, Tfinal, -0.05*maxNbr],
keepaspectratio:false, showNavigation:false, axis: true, showCopyright: false});
brdLipidAge.createElement('curve', [data.t, data.avgAge], {strokeColor:'red', strokeWidth:'2px'});
brdLipidAge.create('point', [function () { return data.t[plot_time]; }, function (){ return data.avgAge[plot_time]; }],
{withLabel: false, strokeColor:'red', strokeWidth:'2px',fixed:true});
brdLipidAge.createElement('curve', [ode_sol.map(function(val,ind) {return val[2];}), ode_sol.map(function(val,ind) {return val[1];})], {strokeColor:'red', strokeWidth:'2px'});
brdLipidNumber.createElement('curve', [ode_sol.map(function(val,ind) {return val[2];}), ode_sol.map(function(val,ind) {return val[0];})], {strokeColor:'blue', strokeWidth:'2px'});
brdLipidNumber.createElement('curve', [data.t, data.F], {strokeColor:'blue', strokeWidth:'2px'});
var d = normalizedata(data.age[plot_time],data.F[plot_time]);
brdLipidNumber.create('point', [function () { return data.t[plot_time]; }, function (){ return data.F[plot_time]; }],
{withLabel: false, strokeColor:'blue', fillColor:'blue', strokeWidth:'2px',fixed:true});
createHeatMap(brdDroplets, d, data.F[plot_time], 1.0);
createHistogram(brdHistAge, data.age[plot_time]);
}
var createHeatMap = function(board, nd, nbr, maxVal) {
var i, heat = [];
board.suspendUpdate();
for (i=0; i<nbr; i++) {
heat[i] = spot(board, data.px[plot_time][i], data.py[plot_time][i] , nd[i], maxVal);
}
board.unsuspendUpdate();
return heat;
};
// spot() creates a point at (x,y).
var spot = function(board, y, x, v, maxVal)
{
var colFunc = function() {
// return JXG.hsv2rgb(0.0, v/maxVal, 1.0);
var levRG = ( Math.floor((192*(1-v/maxVal))) ).toString();
var levB = (Math.floor(192 + 0.25*levRG)).toString()
return "rgb(" + levRG + "," + levRG + "," + levB + ")";
};
var cu = board.create('point',
[x, y],
{strokeWidth:0,
fillColor:colFunc,
withLabel:false,
size:10});
// Turn off highlighting to increase efficiency.
cu.hasPoint = function() { return false;};
return cu;
};
var createHistogram = function(board, dat)
{
console.log(dat);
hist_age = hist(dat, 0, 10, 9);
console.log(hist_age);
board.suspendUpdate;
var dh = (hist_age.bins[1] - hist_age.bins[0]);
//for (var i=0; i<hist_age.bins.length; i++) {
// hist_age.bins += dh;
//}
var h = board.create('chart', [hist_age.bins, hist_age.bar], {chartStyle: 'bar', width: 0.8*dh});
board.unsuspendUpdate;
return h;
}
function update() {
if(data.t.length <= 100)
{
plot_time+=dt;
}
else
{
plot_time+=dt*Math.floor(data.t.length/100);
}
plot_time=Math.min(plot_time,data.t.length);
plot_time=Math.max(plot_time,0);
if (plot_time > data.t.length) {
$("#plus").button("max");
$("#plus").prop('disabled', true);
} else {
$("#plus").button("reset");
$("#plus").prop('disabled', false);
}
if (plot_time <= 0 ) {
$("#minus").button("min");
$("#minus").prop('disabled', true);
} else {
$("#minus").button("reset");
$("#minus").prop('disabled', false);
}
$( "#time_info" ).html(data.t[plot_time].toFixed(1).toString());
var d = normalizedata(data.age[plot_time],data.F[plot_time]);
JXG.JSXGraph.freeBoard(brdDroplets);
brdDroplets = JXG.JSXGraph.initBoard('lipidDistributionBox', {boundingbox:[-0.1,1.1, 1.1, -0.1],
keepaspectratio:false, showNavigation:false, showCopyright: false});
createHeatMap(brdDroplets, d, data.F[plot_time], 1.0);
JXG.JSXGraph.freeBoard(brdHistAge);
brdHistAge = JXG.JSXGraph.initBoard('lipidHistBox', {boundingbox:[-1,F0, 12, -0.05*F0],
keepaspectratio:false, axis: true, showNavigation:false, showCopyright: false});
createHistogram(brdHistAge, data.age[plot_time]);
brdLipidAge.update();
brdLipidNumber.update();
}
runLipidTurnover();
</script>
<hr>
<footer>
<!--<p>© Company 2014</p>-->
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>