-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_LoopDetect_Matlab.html
More file actions
719 lines (576 loc) · 39.7 KB
/
workflow_LoopDetect_Matlab.html
File metadata and controls
719 lines (576 loc) · 39.7 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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--
This HTML was auto-generated from MATLAB code.
To make changes, update the MATLAB code and republish this document.
--><title>LoopDetect: Feedback Loop Detection in ODE models in MATLAB</title><meta name="generator" content="MATLAB 9.7"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2020-06-24"><meta name="DC.source" content="workflow_FBLDetect_Matlab.m"><style type="text/css">
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
html { min-height:100%; margin-bottom:1px; }
html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; }
html body td { vertical-align:top; text-align:left; }
h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; }
h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }
h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }
a { color:#005fce; text-decoration:none; }
a:hover { color:#005fce; text-decoration:underline; }
a:visited { color:#004aa0; text-decoration:none; }
p { padding:0px; margin:0px 0px 20px; }
img { padding:0px; margin:0px 0px 20px; border:none; }
p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; }
ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }
ul li { padding:0px; margin:0px 0px 7px 0px; }
ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }
ul li ol li { list-style:decimal; }
ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }
ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }
ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }
ol li ol li { list-style-type:lower-alpha; }
ol li ul { padding-top:7px; }
ol li ul li { list-style:square; }
.content { font-size:1.2em; line-height:140%; padding: 20px; }
pre, code { font-size:12px; }
tt { font-size: 1.2em; }
pre { margin:0px 0px 20px; }
pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }
pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }
pre.error { color:red; }
@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }
span.keyword { color:#0000FF }
span.comment { color:#228B22 }
span.string { color:#A020F0 }
span.untermstring { color:#B20000 }
span.syscmd { color:#B28C00 }
.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }
.footer p { margin:0px; }
.footer a { color:#878787; }
.footer a:hover { color:#878787; text-decoration:underline; }
.footer a:visited { color:#878787; }
table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; }
table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }
</style></head><body><div class="content"><h1>LoopDetect: Feedback Loop Detection in ODE models in MATLAB</h1><!--introduction--><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#2">Installation</a></li><li><a href="#4">In brief and quick start</a></li><li><a href="#6">Introduction</a></li><li><a href="#7">Solving the ODE model to generate variable values of interest</a></li><li><a href="#9">Calculating the Jacobian matrix</a></li><li><a href="#11">Computing all feedback loops and useful functions for loop search</a></li><li><a href="#18">Computing feedback loops over multiple sets of variable values of interest</a></li><li><a href="#22">Comparing two loop lists</a></li><li><a href="#27">List of functions in LoopDetect - Alphabetical overview</a></li><li><a href="#28">References</a></li></ul></div><p>Copyright Katharina Baum, 2020. Developed for MATLAB 2019b and higher.</p><h2 id="2">Installation</h2><p>Download and unzip the content of the folder 'LoopDetect_for_Matlab'. Within the MATLAB session, navigate to this folder and work there or add the path of the folder to MATLAB's search path for the current MATLAB session by MATLAB's <tt>addpath()</tt> function. Deending on where you stored the folder, its name could be something like '/Users/Desktop/LoopDetect' on Mac or 'C:\matlab\LoopDetect' on Windows.</p><pre class="codeinput"><span class="comment">% Retrieve the LoopDetect folder location when having navigated to the folder</span>
<span class="comment">% within the MATLAB session.</span>
LoopDetect_Folder_Name = pwd;
<span class="comment">% Add this location to MATLAB's searchpath.</span>
addpath(LoopDetect_Folder_Name)
</pre><p>Attention: The LoopDetect content will be added only for the current session. If restarting MATLAB, you will have to perform this procedure again unless the LoopDetect folder is stored in a location that already belongs to MATLAB's searchpath (view it with MATLAB's <tt>path()</tt> function), or you navigate to the folder and work within the folder itself.</p><h2 id="4">In brief and quick start</h2><p>The function suite LoopDetect enables determining all feedback loops of an ordinary differential equation (ODE) system at user-defined values of the model parameters and of the modelled variables.</p><p>The following call reports (up to 10) feedback loops for an ODE system determined by a function, here <tt>func_POSm4()</tt>, at variable values <tt>s_star</tt> (here these are all equal to 1, column vector). The function values are only allowed to depend on the variable values, other parameters and time have to be fixed.</p><pre class="codeinput">s_star=[1,1,1,1]';
klin=ones(1,8); knonlin=[2.5,3];
loop_list=find_loops_vset(@(x)func_POSm4(1,x,klin,knonlin),s_star,10);
disp(loop_list{1})
first_loop=loop_list{1}.loop{1}
</pre><pre class="codeoutput"> loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
first_loop =
4 1 2 3 4
</pre><p>Here, the first loop in <tt>loop_list</tt>, <tt>first_loop</tt>, is a negative feedback loop (<tt>sign</tt> in the table: <tt>-1</tt>) of length 4 in that variable 4 regulates variable 1, variable 1 regulates variable 2, variable 2 regulates variable 3, and variable 3 regulates variable 4.</p><h2 id="6">Introduction</h2><p>Ordinary differential equation (ODE) models are used frequently to mathematically represent biological systems. Feedback loops are important regulatory features of biological systems and can give rise to different dynamic behavior such as multistability for positive feedback loops or oscillations for negative feedback loops.</p><p>The feedback loops in an ODE system can be detected with the help of its Jacobian matrix, the matrix of partial derivatives of the variables. It captures all interactions between the variables and gives rise to the interaction graph of the ODE model. In this graph, each modelled variable is a node and non-zero entries in the Jacobian matrix are (weighted) edges of the graph. Interactions can be positive or negative, according to the sign of the Jacobian matrix entry.</p><p>Directed path detection in this graph is used to determine all feedback loops (in graphs also called cycles or circuits) of the system. They are marked by a set of directed interactions forming a chain in which only the first and the last node (variable) is the same. Thereby, self-loops (loops of length one) can also occur.</p><p>LoopDetect allows for detection of all loops of the graph and also reports the sign of each loop, i.e. whether it is a positive feedback loop (the number of negative interactions is even) or a negative feedback loop (the number of negative interactions is uneven). The output is a table that captures the order of the variables forming the loop, their length and the sign of each loop.</p><p>Except for solving the ODE system to generate variable values of interest which requires the optimization toolbox, only MATLAB base functions are employed and no further toolboxes are required. The algorithms rely on Christopher Maes' implementation of Johnson's algorithm for path detection (find_elem_circuits.m on github) and on Brandon Kuczenski's implementation of Tarjan's algorithm for detecting strongly connected components (tarjan.m, obtained from MATLAB File Exchange).</p><p>Note that this tool was developed under MATLAB 2019b and that for earlier MATLAB versions, it cannot be guaranteed that LoopDetect functions or parts of this workflow run without errors.</p><h2 id="7">Solving the ODE model to generate variable values of interest</h2><pre class="codeinput">klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
[t,sol]=ode15s(@(t,x)func_POSm4(t,x,klin,knonlin),[0,50],ones(1,4));
s_star=sol(end,:); <span class="comment">%the last point of the simulation is chosen</span>
</pre><p>First, the ODE model is solved for a certain set of parameters, <tt>klin</tt>, <tt>knonlin</tt>, with a numerical solver in order to determine values of interest <tt>s_star</tt> for the modelled variables of the ODE system. These could be steady state values, values at a specific point in time (e.g. after a stimulus) or even a set of parameter values (see section Determining loops over a set of variable values). Thus, you can skip this step if you already have a point of interest in state space, or if you want to use dummy values such as <tt>s_star=1:4</tt>.</p><h2 id="9">Calculating the Jacobian matrix</h2><p>The supplied functions <tt>numerical_jacobian()</tt> and <tt>numerical_jacobian_complex()</tt> can be used to determine numerically the Jacobian matrix of an ODE system at a certain set of values for the variables, <tt>s_star</tt>. The approach is that of finite differences (with real step) or complex step approach, the latter of which is supposed to deliver more exact results [Martins et al., 2003] and relies on the native implementation of complex numbers in MATLAB. The input function handle <tt>f</tt> (in the example derived from <tt>func_POSm4()</tt>, positive feedback chain model from [Baum et al., 2016]) points to a function that defines the time derivatives of the modelled variables as a vector: <tt>f_i(s)=dS_i/dt</tt>. When supplied to <tt>numerical_jacobian_complex()</tt>, it is allowed to depend only on the values of the variables; other dependencies, e.g. on parameter values, should be removed by chosing fixed values.</p><pre class="codeinput">klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
j_matrix=numerical_jacobian_complex(@(s)func_POSm4(1,s,klin,knonlin),<span class="keyword">...</span>
s_star);
signed_jacobian=sign(j_matrix)
</pre><pre class="codeoutput">
signed_jacobian =
-1 0 0 -1
1 -1 0 1
0 1 -1 0
0 0 1 -1
</pre><p>The (i,j)th entry of the Jacobian matrix denotes the partial derivative of variable <tt>S_i</tt> with respect to variable <tt>S_j</tt>, <tt>J_ij=delta S_i/delta S_j</tt>, which is positive if <tt>S_j</tt> has a direct positive effect on <tt>S_i</tt>, negative if <tt>S_j</tt> has a direct negative effect on <tt>S_i</tt> and zero if <tt>S_j</tt> does not have a direct effect on <tt>S_i</tt>. For example, the entry in row 1, column 4, <tt>J_14</tt>, of the matrix above is <tt>-1</tt>, meaning that in the underlying ODE model, variable 4 negatively regulates variable 1.</p><h2 id="11">Computing all feedback loops and useful functions for loop search</h2><p>The Jacobian matrix is used to compute feedback loops in the generated interaction graph. For this, the default function is <tt>find_loops()</tt>, in that strongly connected components are determined to reduce runtime. For smaller systems, the function <tt>find_loops_noscc()</tt> skips this step and thus can be faster. The optional second input argument sets an upper limit to the number of detected and reported loops and thus can prevent overly long runtime (but also potentially not all loops are returned).</p><pre class="codeinput">loop_list=find_loops(j_matrix)
</pre><pre class="codeoutput">
loop_list =
6×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
</pre><p>Single loops can be examined by entering the corresponding entry.</p><pre class="codeinput"><span class="keyword">for</span> i=1:6
disp(loop_list.loop{i})
<span class="keyword">end</span>
</pre><pre class="codeoutput"> 4 1 2 3 4
4 2 3 4
1 1
2 2
3 3
4 4
</pre><p>The function <tt>loop_summary()</tt> provides a convenient report on total number of loops, subdivided by their lengths and signs.</p><pre class="codeinput">disp(loop_summary(loop_list))
</pre><pre class="codeoutput"> length_1 length_2 length_3 length_4
________ ________ ________ ________
total 4 0 1 1
negative 4 0 0 1
positive 0 0 1 0
</pre><p>One can filter the loop list for loops containing specific variables, for example the one with index 2:</p><pre class="codeinput">noi = 2;
loops_with_node2=loop_list(<span class="keyword">...</span>
cellfun(@(z) ismember(noi,z),loop_list.loop),:)
</pre><pre class="codeoutput">
loops_with_node2 =
3×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
{1×2 double} 1 -1
</pre><p>Search a loop list for loops containing specific edges defined by the indices of the ingoing and outgoing nodes. This example returns the indices of all loops with a regulation of node 3 by node 2. These are only two here.</p><pre class="codeinput">loop_edge_ind=find_edge(loop_list,2,3);
loops_with_edge_2_to_3=loop_list(loop_edge_ind,:)
<span class="keyword">for</span> i=1:2
disp(loops_with_edge_2_to_3.loop{i})
<span class="keyword">end</span>
</pre><pre class="codeoutput">
loops_with_edge_2_to_3 =
2×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
4 1 2 3 4
4 2 3 4
</pre><p>Saving and reading loop lists from files can be done using MATLAB's <tt>save()</tt> and <tt>load()</tt> functions. They keep the correct data format, but objects have to be retrieved from a struct.</p><pre class="codeinput">save(<span class="string">'loop_list_example.mat'</span>, <span class="string">'loops_with_node2'</span>)
loaded_loops_with_node2=load(<span class="string">'loop_list_example.mat'</span>)
<span class="comment">% access the loaded data table from the struct (might not be required</span>
<span class="comment">% in earlier MATLAB versions)</span>
loaded_loops_with_node2.loops_with_node2
</pre><pre class="codeoutput">
loaded_loops_with_node2 =
struct with fields:
loops_with_node2: [3×3 table]
ans =
3×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
{1×2 double} 1 -1
</pre><p>Reading and writing loop lists to tabular format can be performed via MATLAB's <tt>writetable()</tt> and <tt>readtable()</tt> functions. Here, we choose tabs as delimiters. Note that the formatting is lost.</p><pre class="codeinput">writetable(loops_with_node2,<span class="string">'loop_list_example.txt'</span>,<span class="string">'Delimiter'</span>,<span class="string">'\t'</span>)
loops_with_node2_readin = readtable(<span class="string">'loop_list_example.txt'</span>)
</pre><pre class="codeoutput">
loops_with_node2_readin =
3×7 table
loop_1 loop_2 loop_3 loop_4 loop_5 length sign
______ ______ ______ ______ ______ ______ ____
4 1 2 3 4 4 -1
4 2 3 4 NaN 3 1
2 2 NaN NaN NaN 1 -1
</pre><h2 id="18">Computing feedback loops over multiple sets of variable values of interest</h2><p>In this example of a model of the bacterial cell cycle [Li et al., 2008], we demonstrate how feedback loops can be determined over multiple sets of variable values. Here, we focus on the solution of the ODE systems along the time axis (provided in 'li08_solution.txt').</p><pre class="codeinput"><span class="comment">% load sets of variable values (solution to the ODE over time)</span>
sol = readmatrix(<span class="string">'li08_solution.txt'</span>);
<span class="comment">% possible alternative: sol = dlmread('li08_solution.txt');</span>
[loop_rep,loop_rep_index,jac_rep,jac_rep_index]=find_loops_vset(<span class="keyword">...</span>
@(x)func_li08(0,x), sol(:,2:end)', 1e5, false);
</pre><p>The solutions give rise to seven different loop lists.</p><pre class="codeinput">disp(length(loop_rep))
</pre><pre class="codeoutput"> 7
</pre><p>Here, two examples of resulting loop lists are given (without self-loops).</p><pre class="codeinput">loop_list_2=loop_rep{2}(loop_rep{2}.length>1,:)
loop_list_7=loop_rep{7}(loop_rep{7}.length>1,:)
</pre><pre class="codeoutput">
loop_list_2 =
3×3 table
loop length sign
____________ ______ ____
{1×4 double} 3 -1
{1×3 double} 2 1
{1×3 double} 2 -1
loop_list_7 =
12×3 table
loop length sign
____________ ______ ____
{1×3 double} 2 -1
{1×4 double} 3 1
{1×3 double} 2 -1
{1×6 double} 5 1
{1×5 double} 4 -1
{1×4 double} 3 -1
{1×3 double} 2 1
{1×7 double} 6 1
{1×4 double} 3 -1
{1×5 double} 4 -1
{1×9 double} 8 -1
{1×8 double} 7 1
</pre><p>These results could be plotted along the solution, e.g. by indicating a certain background color for certain specific loop lists, and analyzed further to discover reasons of changing loops. Please note that in order to obtain the sample solution in <tt>li08_solution.txt</tt> also event functions are required; the solution cannot be retrieved from integrating <tt>func_li08()</tt> alone. Please refer to the model's publication [Li et al., 2008] for details.</p><h2 id="22">Comparing two loop lists</h2><p>We might want to compare loops of two systems, e.g. as obtained in the example above. For this, we provide the function <tt>compare_loop_list()</tt>. Thereby, loop indices in the compared systems should point to the same variables, otherwise a meaningful comparison is not possible. This could be the case for example if we examine a system in which only one regulation has changed (for example the positive feedback chain model vs. the negative feedback chain model, [Baum et al. 2016]), or if regulations changed within one system when determining loops for multiple sets of variables of interest (along a dynamic trajectory, at different steady states of the system).</p><pre class="codeinput"><span class="comment">% Function with positive regulation</span>
klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
j_matrix=numerical_jacobian_complex(@(s)func_POSm4(1,s,klin,knonlin),<span class="keyword">...</span>
s_star);
loop_list_pos=find_loops(j_matrix);
<span class="comment">% Function with negative regulation. The altered regulation affects</span>
<span class="comment">% two entries of the Jacobian matrix. Parameter values and the set of</span>
<span class="comment">% variable values remain identical.</span>
j_matrix_neg=j_matrix;
j_matrix_neg(1:2,4)=-j_matrix(1:2,4);
loop_list_neg=find_loops(j_matrix_neg);
<span class="comment">% compute comparison</span>
[ind_a_id,ind_a_switch,ind_a_notin,ind_b_id,ind_b_switch]=<span class="keyword">...</span>
compare_loop_list(loop_list_pos,loop_list_neg);
</pre><p>Only the four self-loops remain identical in both systems.</p><pre class="codeinput">disp(loop_list_pos(ind_a_id,:))
<span class="keyword">for</span> i=1:4
disp(loop_list_pos.loop{ind_a_id(i)})
<span class="keyword">end</span>
</pre><pre class="codeoutput"> loop length sign
____________ ______ ____
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
1 1
2 2
3 3
4 4
</pre><p>These are the corresponding loops in the negatively regulated system.</p><pre class="codeinput">disp(loop_list_neg(ind_b_id,:))
<span class="keyword">for</span> i=1:4
disp(loop_list_neg.loop{ind_b_id(i)})
<span class="keyword">end</span>
</pre><pre class="codeoutput"> loop length sign
____________ ______ ____
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
{1×2 double} 1 -1
1 1
2 2
3 3
4 4
</pre><p>Two loops are the same in both systems but they have switched their signs.</p><pre class="codeinput">loops_switch_pos=loop_list_pos(ind_a_switch,:)
<span class="keyword">for</span> i=1:2
disp(loops_switch_pos.loop{i})
<span class="keyword">end</span>
loops_switch_neg=loop_list_neg(ind_b_switch,:)
<span class="keyword">for</span> i=1:2
disp(loops_switch_neg.loop{i})
<span class="keyword">end</span>
</pre><pre class="codeoutput">
loops_switch_pos =
2×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 -1
{1×4 double} 3 1
4 1 2 3 4
4 2 3 4
loops_switch_neg =
2×3 table
loop length sign
____________ ______ ____
{1×5 double} 4 1
{1×4 double} 3 -1
4 1 2 3 4
4 2 3 4
</pre><p>All loops in the positively regulated system do also occur in the negatively regulated system, i.e. <tt>ind_a_notin</tt> is empty.</p><pre class="codeinput">ind_a_notin
</pre><pre class="codeoutput">
ind_a_notin =
0×1 empty double column vector
</pre><h2 id="27">List of functions in LoopDetect - Alphabetical overview</h2><div><ul><li><tt>compare_loop_list</tt> - compare two loop lists</li><li><tt>find_edge</tt> - find loops with a certain edge in a loop list</li><li><tt>find_loops_noscc</tt> - detect feedback loops from a Jacobian or adjacency matrix without determining strongly connected components, suitable for smaller or densely connected systems</li><li><tt>find_loops_vset</tt> - detect feedback loops from a function and sets of values for the modelled variables</li><li><tt>find_loops</tt> - detect feedback loops from a Jacobian or adjacency matrix</li><li><tt>loop_summary</tt> - summarize loops list contents by lengths and signs</li><li><tt>numerical_jacobian_complex</tt> - finite difference numerical determination of the Jacobian matrix with a complex step, provides higher accuracy than <tt>numerical_jacobian</tt></li><li><tt>numerical_jacobian</tt> - finite difference numerical determination of the Jacobian matrix</li><li><tt>sort_loop_index</tt> - sort the reported loops to always start with the lowest node index</li></ul></div><h2 id="28">References</h2><p>Baum K, Politi AZ, Kofahl B, Steuer R, Wolf J. Feedback, Mass Conservation and Reaction Kinetics Impact the Robustness of Cellular Oscillations. PLoS Comput Biol. 2016;12(12):e1005298.</p><p>Brandon Kuczenski (2018). tarjan(e) (<a href="https://www.mathworks.com/matlabcentral/fileexchange/50707-tarjan-e">https://www.mathworks.com/matlabcentral/fileexchange/50707-tarjan-e</a>), MATLAB Central File Exchange. Retrieved August 14, 2018.</p><p>Li S, Brazhnik P, Sobral B, Tyson JJ. A Quantitative Study of the Division Cycle of Caulobacter crescentus Stalked Cells. Plos Comput Biol. 2008;4(1):e9.</p><p>Christopher Maes (2011). find_elem_circuits.m <a href="https://gist.github.com/cmaes/1260153">https://gist.github.com/cmaes/1260153</a></p><p>Martins JRRA, Sturdza P, Alonso JJ. The complex-step derivative approximation. ACM Trans Math Softw. 2003;29(3):245–62.</p><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB® R2019b</a><br></p></div><!--
##### SOURCE BEGIN #####
%% LoopDetect: Feedback Loop Detection in ODE models in MATLAB
%%
%
% Copyright Katharina Baum, 2020.
% Developed for MATLAB 2019b and higher.
%% Installation
%
% Download and unzip the content of the folder 'LoopDetect_for_Matlab'.
% Within the MATLAB session, navigate to this folder and work there or add the path of the
% folder to MATLAB's search path for the current MATLAB session
% by MATLAB's |addpath()| function. Deending on where you stored the folder,
% its name could be something like '/Users/Desktop/LoopDetect' on Mac or
% 'C:\matlab\LoopDetect' on Windows.
% Retrieve the LoopDetect folder location when having navigated to the folder
% within the MATLAB session.
LoopDetect_Folder_Name = pwd;
% Add this location to MATLAB's searchpath.
addpath(LoopDetect_Folder_Name)
%%
% Attention: The LoopDetect content
% will be added only for the current session. If restarting MATLAB, you
% will have to perform this procedure again unless the LoopDetect folder
% is stored in a location that already belongs to MATLAB's searchpath
% (view it with MATLAB's |path()|
% function), or you navigate to the folder and work within the folder itself.
%% In brief and quick start
%
% The function suite LoopDetect enables determining all feedback loops of
% an ordinary differential equation (ODE) system at user-defined values of
% the model parameters and of the modelled variables.
%
% The following call reports (up to 10) feedback loops for an ODE system
% determined by a function, here |func_POSm4()|, at variable values |s_star|
% (here these are all equal to 1, column vector). The function values are
% only allowed to depend on the variable values, other parameters and time
% have to be fixed.
%
s_star=[1,1,1,1]';
klin=ones(1,8); knonlin=[2.5,3];
loop_list=find_loops_vset(@(x)func_POSm4(1,x,klin,knonlin),s_star,10);
disp(loop_list{1})
first_loop=loop_list{1}.loop{1}
%%
% Here, the first loop in |loop_list|, |first_loop|, is a negative feedback
% loop (|sign| in the table: |-1|) of length 4
% in that variable 4 regulates variable 1,
% variable 1 regulates variable 2, variable 2 regulates variable 3, and
% variable 3 regulates variable 4.
%% Introduction
%
% Ordinary differential equation (ODE) models are used frequently to
% mathematically represent biological systems. Feedback loops are important
% regulatory features of biological systems and can give rise to different
% dynamic behavior such as multistability for positive feedback loops or
% oscillations for negative feedback loops.
%
% The feedback loops in an ODE system can be detected with the help of its
% Jacobian matrix, the matrix of partial derivatives of the variables.
% It captures all interactions between the variables and gives rise to the
% interaction graph of the ODE model. In this graph, each modelled variable
% is a node and non-zero entries in the Jacobian matrix are (weighted)
% edges of the graph. Interactions can be positive or negative, according
% to the sign of the Jacobian matrix entry.
%
% Directed path detection in this graph is used to determine all feedback
% loops (in graphs also called cycles or circuits) of the system. They are
% marked by a set of directed interactions forming a chain in which only
% the first and the last node (variable) is the same. Thereby, self-loops
% (loops of length one) can also occur.
%
% LoopDetect allows for detection of all loops of the graph and also reports
% the sign of each loop, i.e. whether it is a positive feedback loop
% (the number of negative interactions is even) or a negative feedback loop
% (the number of negative interactions is uneven).
% The output is a table that captures the order of the variables forming
% the loop, their length and the sign of each loop.
%
% Except for solving the ODE system to generate variable values of interest
% which requires the optimization toolbox, only MATLAB base functions are
% employed and no further toolboxes are required. The algorithms rely on
% Christopher Maes' implementation of
% Johnson's algorithm for path detection (find_elem_circuits.m on github) and
% on Brandon Kuczenski's implementation of Tarjan's algorithm for detecting
% strongly connected components (tarjan.m, obtained from MATLAB File Exchange).
%
% Note that this tool was developed under MATLAB 2019b and that for earlier
% MATLAB versions, it cannot be guaranteed that LoopDetect functions or parts
% of this workflow run without errors.
%% Solving the ODE model to generate variable values of interest
klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
[t,sol]=ode15s(@(t,x)func_POSm4(t,x,klin,knonlin),[0,50],ones(1,4));
s_star=sol(end,:); %the last point of the simulation is chosen
%%
% First, the ODE model is solved for a certain set of parameters, |klin|,
% |knonlin|, with a
% numerical solver in order to determine values of interest |s_star| for the
% modelled variables of the ODE system. These could be steady state values,
% values at a specific point in time (e.g. after a stimulus) or even a set
% of parameter values (see section
% Determining loops over a set of variable values). Thus, you can skip this step if
% you already have a point of interest in state space, or if you want to
% use dummy values such as |s_star=1:4|.
%% Calculating the Jacobian matrix
%
% The supplied functions |numerical_jacobian()| and
% |numerical_jacobian_complex()| can be used to determine numerically the Jacobian matrix
% of an ODE system at a certain set of values for the variables, |s_star|.
% The approach is that of finite differences (with real step) or
% complex step approach, the latter of which is supposed to deliver more exact results [Martins et al., 2003] and
% relies on the native implementation of complex numbers in MATLAB. The
% input function handle |f| (in the example derived from |func_POSm4()|,
% positive feedback chain model from [Baum et al., 2016]) points to a function that defines the time
% derivatives of the modelled variables as a vector:
% |f_i(s)=dS_i/dt|.
% When supplied to |numerical_jacobian_complex()|, it is allowed to depend only on the values of
% the variables; other dependencies, e.g. on parameter values, should be
% removed by chosing fixed values.
klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
j_matrix=numerical_jacobian_complex(@(s)func_POSm4(1,s,klin,knonlin),...
s_star);
signed_jacobian=sign(j_matrix)
%%
% The (i,j)th entry of the Jacobian matrix denotes the partial derivative
% of variable |S_i| with respect to variable |S_j|,
% |J_ij=delta S_i/delta S_j|,
% which is positive if |S_j| has a direct positive effect on |S_i|, negative
% if |S_j| has a direct negative effect on |S_i| and zero if |S_j| does not
% have a direct effect on |S_i|. For example, the entry in row 1,
% column 4, |J_14|, of the matrix above is |-1|, meaning that in the
% underlying ODE model, variable 4 negatively regulates variable 1.
%% Computing all feedback loops and useful functions for loop search
%
% The Jacobian matrix is used to compute feedback loops in the generated interaction graph.
% For this, the default function is |find_loops()|, in that strongly
% connected components are determined to reduce runtime. For smaller
% systems, the function |find_loops_noscc()| skips this step and thus can be
% faster. The optional second input argument sets an upper limit to the number of detected
% and reported loops and thus can prevent overly long runtime (but also
% potentially not all loops are returned).
%
loop_list=find_loops(j_matrix)
%%
% Single loops can be examined by entering the corresponding entry.
for i=1:6
disp(loop_list.loop{i})
end
%%
% The function |loop_summary()| provides a convenient report on total number of
% loops, subdivided by their lengths and signs.
disp(loop_summary(loop_list))
%%
% One can filter the loop list for loops containing specific variables,
% for example the one with index 2:
noi = 2;
loops_with_node2=loop_list(...
cellfun(@(z) ismember(noi,z),loop_list.loop),:)
%%
% Search a loop list for loops containing specific edges defined by the
% indices of the ingoing and outgoing nodes. This example returns the
% indices of all loops with a regulation of node 3 by node 2. These are
% only two here.
%
loop_edge_ind=find_edge(loop_list,2,3);
loops_with_edge_2_to_3=loop_list(loop_edge_ind,:)
for i=1:2
disp(loops_with_edge_2_to_3.loop{i})
end
%%
% Saving and reading loop lists from files can be done using MATLAB's
% |save()| and |load()| functions. They keep the correct data format, but
% objects have to be retrieved from a struct.
save('loop_list_example.mat', 'loops_with_node2')
loaded_loops_with_node2=load('loop_list_example.mat')
% access the loaded data table from the struct (might not be required
% in earlier MATLAB versions)
loaded_loops_with_node2.loops_with_node2
%%
% Reading and writing loop lists to tabular format can be performed via
% MATLAB's |writetable()| and |readtable()| functions. Here, we choose tabs as
% delimiters. Note that the formatting is lost.
writetable(loops_with_node2,'loop_list_example.txt','Delimiter','\t')
loops_with_node2_readin = readtable('loop_list_example.txt')
%% Computing feedback loops over multiple sets of variable values of interest
%
% In this example of a model of the bacterial cell cycle [Li et al., 2008],
% we demonstrate how feedback loops can be determined over multiple sets of
% variable values. Here, we focus on the solution of the ODE
% systems along the time axis (provided in 'li08_solution.txt').
% load sets of variable values (solution to the ODE over time)
sol = readmatrix('li08_solution.txt');
% possible alternative: sol = dlmread('li08_solution.txt');
[loop_rep,loop_rep_index,jac_rep,jac_rep_index]=find_loops_vset(...
@(x)func_li08(0,x), sol(:,2:end)', 1e5, false);
%%
% The solutions give rise to seven different loop lists.
disp(length(loop_rep))
%%
% Here, two examples of resulting loop lists are given (without
% self-loops).
loop_list_2=loop_rep{2}(loop_rep{2}.length>1,:)
loop_list_7=loop_rep{7}(loop_rep{7}.length>1,:)
%%
% These results could be plotted along the solution, e.g. by indicating a
% certain background color for certain specific loop lists, and analyzed
% further to discover reasons of changing loops. Please note that in order
% to obtain the sample solution in |li08_solution.txt| also event functions
% are required; the solution cannot be retrieved from integrating
% |func_li08()| alone. Please refer to the model's publication [Li et al.,
% 2008] for details.
%% Comparing two loop lists
%
% We might want to compare loops of two systems, e.g. as obtained in the
% example above. For this, we provide the function |compare_loop_list()|.
% Thereby, loop indices in
% the compared systems should point to the same variables, otherwise a meaningful
% comparison is not possible. This could be the case for example if we
% examine a system in which only one regulation has changed (for example
% the positive feedback chain model vs. the negative feedback chain model, [Baum et al. 2016]),
% or if regulations changed within one system when determining loops for
% multiple sets of variables of interest (along a dynamic trajectory, at
% different steady states of the system).
% Function with positive regulation
klin=[165,0.044,0.27,550,5000,78,4.4,5.1];
knonlin=[0.3,2];
j_matrix=numerical_jacobian_complex(@(s)func_POSm4(1,s,klin,knonlin),...
s_star);
loop_list_pos=find_loops(j_matrix);
% Function with negative regulation. The altered regulation affects
% two entries of the Jacobian matrix. Parameter values and the set of
% variable values remain identical.
j_matrix_neg=j_matrix;
j_matrix_neg(1:2,4)=-j_matrix(1:2,4);
loop_list_neg=find_loops(j_matrix_neg);
% compute comparison
[ind_a_id,ind_a_switch,ind_a_notin,ind_b_id,ind_b_switch]=...
compare_loop_list(loop_list_pos,loop_list_neg);
%%
% Only the four self-loops remain identical in both systems.
disp(loop_list_pos(ind_a_id,:))
for i=1:4
disp(loop_list_pos.loop{ind_a_id(i)})
end
%%
% These are the corresponding loops in the negatively regulated system.
disp(loop_list_neg(ind_b_id,:))
for i=1:4
disp(loop_list_neg.loop{ind_b_id(i)})
end
%%
% Two loops are the same in both systems but they have switched their signs.
loops_switch_pos=loop_list_pos(ind_a_switch,:)
for i=1:2
disp(loops_switch_pos.loop{i})
end
loops_switch_neg=loop_list_neg(ind_b_switch,:)
for i=1:2
disp(loops_switch_neg.loop{i})
end
%%
% All loops in the positively regulated system do also occur in the negatively regulated
% system, i.e. |ind_a_notin| is empty.
ind_a_notin
%% List of functions in LoopDetect - Alphabetical overview
%
% * |compare_loop_list| - compare two loop lists
% * |find_edge| - find loops with a certain edge in a loop list
% * |find_loops_noscc| - detect feedback loops from a Jacobian or adjacency
% matrix without determining strongly connected components, suitable for
% smaller or densely connected systems
% * |find_loops_vset| - detect feedback loops from a function and sets of
% values for the modelled variables
% * |find_loops| - detect feedback loops from a Jacobian or adjacency matrix
% * |loop_summary| - summarize loops list contents by lengths and signs
% * |numerical_jacobian_complex| - finite difference numerical determination of the Jacobian
% matrix with a complex step, provides higher accuracy than
% |numerical_jacobian|
% * |numerical_jacobian| - finite difference numerical determination of the Jacobian
% matrix
% * |sort_loop_index| - sort the reported loops to always start with the
% lowest node index
%
%% References
%
% Baum K, Politi AZ, Kofahl B, Steuer R, Wolf J. Feedback, Mass
% Conservation and Reaction Kinetics Impact the Robustness of Cellular
% Oscillations. PLoS Comput Biol. 2016;12(12):e1005298.
%
% Brandon Kuczenski (2018). tarjan(e)
% (https://www.mathworks.com/matlabcentral/fileexchange/50707-tarjan-e),
% MATLAB Central File Exchange. Retrieved August 14, 2018.
%
% Li S, Brazhnik P, Sobral B, Tyson JJ. A Quantitative Study of the
% Division Cycle of Caulobacter crescentus Stalked Cells. Plos Comput Biol.
% 2008;4(1):e9.
%
% Christopher Maes (2011). find_elem_circuits.m
% https://gist.github.com/cmaes/1260153
%
% Martins JRRA, Sturdza P, Alonso JJ. The complex-step derivative
% approximation. ACM Trans Math Softw. 2003;29(3):245–62.
%
##### SOURCE END #####
--></body></html>