Skip to content

Commit 7f049d8

Browse files
committed
Add symengine support
1 parent e5947f6 commit 7f049d8

File tree

4 files changed

+104
-67
lines changed

4 files changed

+104
-67
lines changed

README.rst

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,51 +99,72 @@ iJO1366 (*E. coli*) and Recon 2.2:
9999

100100
.. code:: python
101101
102-
In [1]: from cobra.test import create_test_model
102+
In [1]: from cobra.test import create_test_model
103+
Loading symengine... This feature is in beta testing. Please report any issues you encounter on http://github.com/biosustain/optlang/issues
103104

104-
In [2]: from cobra.io import read_sbml_model
105+
In [2]: from cobra.io import read_sbml_model
105106

106-
In [3]: from corda import CORDA
107+
In [3]: from corda import CORDA
107108

108-
In [4]: ecoli = create_test_model("ecoli")
109+
In [4]: ecoli = create_test_model("ecoli")
109110

110-
In [5]: conf = {}
111+
In [5]: conf = {}
111112

112-
In [6]: for r in ecoli.reactions:
113-
...: conf[r.id] = -1
114-
...:
113+
In [6]: for r in ecoli.reactions:
114+
...: conf[r.id] = -1
115+
...:
115116

116-
In [7]: conf["Ec_biomass_iJO1366_core_53p95M"] = 3
117+
In [7]: conf["Ec_biomass_iJO1366_core_53p95M"] = 3
117118

118-
In [8]: %time opt = CORDA(ecoli, conf)
119-
CPU times: user 425 ms, sys: 41.5 ms, total: 466 ms
120-
Wall time: 466 ms
119+
In [8]: %time opt = CORDA(ecoli, conf)
120+
CPU times: user 282 ms, sys: 1.81 ms, total: 284 ms
121+
Wall time: 284 ms
121122

122-
In [9]: %time opt.build()
123-
CPU times: user 13.6 s, sys: 734 µs, total: 13.6 s
124-
Wall time: 13.6 s
123+
In [9]: %time opt.build()
124+
CPU times: user 9.04 s, sys: 93 µs, total: 9.04 s
125+
Wall time: 9.05 s
125126

126-
In [10]:
127+
In [10]: print(opt)
128+
build status: reconstruction complete
129+
Inc. reactions: 456/2583
130+
- unclear: 0/0
131+
- exclude: 455/2582
132+
- low and medium: 0/0
133+
- high: 1/1
127134

128-
In [10]: recon2 = read_sbml_model("/home/cdiener/Downloads/recon2.xml")
129-
cobra/io/sbml.py:235 UserWarning: M_h_x appears as a reactant and product FAOXC220200x
130135

131-
In [11]: conf = {}
136+
In [11]:
132137

133-
In [12]: for r in recon2.reactions:
134-
...: conf[r.id] = -1
135-
...:
138+
In [12]: recon2 = read_sbml_model("/home/cdiener/Downloads/recon_2.2.xml")
139+
cobra/io/sbml.py:235 UserWarning: M_h_c appears as a reactant and product RE3453C
140+
cobra/io/sbml.py:235 UserWarning: M_h_c appears as a reactant and product RE3459C
141+
cobra/io/sbml.py:235 UserWarning: M_h_x appears as a reactant and product FAOXC24C22x
142+
cobra/io/sbml.py:235 UserWarning: M_h_c appears as a reactant and product HAS1
143+
cobra/io/sbml.py:235 UserWarning: M_h2o_x appears as a reactant and product PROFVSCOAhc
136144

137-
In [13]: conf["biomass_reaction"] = 3
145+
In [13]: conf = {}
138146

139-
In [14]: %time opt = CORDA(recon2, conf)
140-
CPU times: user 1.39 s, sys: 149 ms, total: 1.54 s
141-
Wall time: 1.55 s
147+
In [14]: for r in recon2.reactions:
148+
...: conf[r.id] = -1
149+
...:
142150

143-
In [15]: %time opt.build()
144-
CPU times: user 54.2 s, sys: 0 ns, total: 54.2 s
145-
Wall time: 54.3 s
151+
In [15]: conf["biomass_reaction"] = 3
146152

153+
In [16]: %time opt = CORDA(recon2, conf)
154+
CPU times: user 1 s, sys: 8.95 ms, total: 1.01 s
155+
Wall time: 1.01 s
156+
157+
In [17]: %time opt.build()
158+
CPU times: user 24.7 s, sys: 240 µs, total: 24.7 s
159+
Wall time: 24.8 s
160+
161+
In [28]: print(opt)
162+
build status: reconstruction complete
163+
Inc. reactions: 395/7864
164+
- unclear: 0/0
165+
- exclude: 394/7863
166+
- low and medium: 0/0
167+
- high: 1/1
147168

148169
.. |travis| image:: https://travis-ci.org/resendislab/corda.svg?branch=master
149170
:target: https://travis-ci.org/resendislab/corda

corda/corda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616
from collections import Counter
1717
import re
18-
from sympy.core.singleton import S
18+
from optlang.symbolics import Zero
1919

2020
UPPER = 1e6 # default upper bound
2121
CI = 1.01 # cost increase for redundancy detection
@@ -109,7 +109,7 @@ def __init__(self, model, confidence, met_prod=None, n=np.inf,
109109
confidence[r.id] = 3
110110

111111
# Map confidences from forward to backward reactions
112-
self.model.objective = S.Zero
112+
self.model.objective = Zero
113113
self.model.objective.direction = "min"
114114
self.conf = {}
115115
self.redundancies = {}

docs/index.html

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11726,9 +11726,7 @@
1172611726
div#notebook {
1172711727
overflow: visible;
1172811728
border-top: none;
11729-
}
11730-
11731-
@media print {
11729+
}@media print {
1173211730
div.cell {
1173311731
display: block;
1173411732
page-break-inside: avoid;
@@ -11749,7 +11747,7 @@
1174911747

1175011748
<!-- Loading mathjax macro -->
1175111749
<!-- Load mathjax -->
11752-
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
11750+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
1175311751
<!-- MathJax configuration -->
1175411752
<script type="text/x-mathjax-config">
1175511753
MathJax.Hub.Config({
@@ -11773,26 +11771,23 @@
1177311771
<div tabindex="-1" id="notebook" class="border-box-sizing">
1177411772
<div class="container" id="notebook-container">
1177511773

11776-
<div class="cell border-box-sizing text_cell rendered">
11777-
<div class="prompt input_prompt">
11774+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1177811775
</div>
1177911776
<div class="inner_cell">
1178011777
<div class="text_cell_render border-box-sizing rendered_html">
1178111778
<h1 id="CORDA-tutorial">CORDA tutorial<a class="anchor-link" href="#CORDA-tutorial">&#182;</a></h1>
1178211779
</div>
1178311780
</div>
1178411781
</div>
11785-
<div class="cell border-box-sizing text_cell rendered">
11786-
<div class="prompt input_prompt">
11782+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1178711783
</div>
1178811784
<div class="inner_cell">
1178911785
<div class="text_cell_render border-box-sizing rendered_html">
1179011786
<h2 id="Reactions,-Genes-and-confidences">Reactions, Genes and confidences<a class="anchor-link" href="#Reactions,-Genes-and-confidences">&#182;</a></h2>
1179111787
</div>
1179211788
</div>
1179311789
</div>
11794-
<div class="cell border-box-sizing text_cell rendered">
11795-
<div class="prompt input_prompt">
11790+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1179611791
</div>
1179711792
<div class="inner_cell">
1179811793
<div class="text_cell_render border-box-sizing rendered_html">
@@ -11834,10 +11829,23 @@ <h2 id="Reactions,-Genes-and-confidences">Reactions, Genes and confidences<a cla
1183411829

1183511830

1183611831
<div class="output_area">
11832+
11833+
<div class="prompt"></div>
11834+
11835+
11836+
<div class="output_subarea output_stream output_stderr output_text">
11837+
<pre>Loading symengine... This feature is in beta testing. Please report any issues you encounter on http://github.com/biosustain/optlang/issues
11838+
</pre>
11839+
</div>
11840+
</div>
11841+
11842+
<div class="output_area">
11843+
1183711844
<div class="prompt output_prompt">Out[1]:</div>
1183811845

1183911846

1184011847

11848+
1184111849
<div class="output_text output_subarea output_execute_result">
1184211850
<pre>1</pre>
1184311851
</div>
@@ -11848,17 +11856,15 @@ <h2 id="Reactions,-Genes-and-confidences">Reactions, Genes and confidences<a cla
1184811856
</div>
1184911857

1185011858
</div>
11851-
<div class="cell border-box-sizing text_cell rendered">
11852-
<div class="prompt input_prompt">
11859+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1185311860
</div>
1185411861
<div class="inner_cell">
1185511862
<div class="text_cell_render border-box-sizing rendered_html">
1185611863
<h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-example">&#182;</a></h2>
1185711864
</div>
1185811865
</div>
1185911866
</div>
11860-
<div class="cell border-box-sizing text_cell rendered">
11861-
<div class="prompt input_prompt">
11867+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1186211868
</div>
1186311869
<div class="inner_cell">
1186411870
<div class="text_cell_render border-box-sizing rendered_html">
@@ -11887,10 +11893,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1188711893

1188811894

1188911895
<div class="output_area">
11896+
1189011897
<div class="prompt output_prompt">Out[2]:</div>
1189111898

1189211899

1189311900

11901+
1189411902
<div class="output_text output_subarea output_execute_result">
1189511903
<pre>60</pre>
1189611904
</div>
@@ -11901,8 +11909,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1190111909
</div>
1190211910

1190311911
</div>
11904-
<div class="cell border-box-sizing text_cell rendered">
11905-
<div class="prompt input_prompt">
11912+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1190611913
</div>
1190711914
<div class="inner_cell">
1190811915
<div class="text_cell_render border-box-sizing rendered_html">
@@ -11928,10 +11935,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1192811935

1192911936

1193011937
<div class="output_area">
11938+
1193111939
<div class="prompt output_prompt">Out[3]:</div>
1193211940

1193311941

1193411942

11943+
1193511944
<div class="output_text output_subarea output_execute_result">
1193611945
<pre>&#39;0.39253 3pg + 20.7045 atp + 0.15446 cit + 0.38587 glu + 0.35261 oaa + 0.053446 prpp + 0.50563 pyr --&gt; 20.6508 adp + 20.6508 pi&#39;</pre>
1193711946
</div>
@@ -11942,8 +11951,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1194211951
</div>
1194311952

1194411953
</div>
11945-
<div class="cell border-box-sizing text_cell rendered">
11946-
<div class="prompt input_prompt">
11954+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1194711955
</div>
1194811956
<div class="inner_cell">
1194911957
<div class="text_cell_render border-box-sizing rendered_html">
@@ -11967,8 +11975,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1196711975
</div>
1196811976

1196911977
</div>
11970-
<div class="cell border-box-sizing text_cell rendered">
11971-
<div class="prompt input_prompt">
11978+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1197211979
</div>
1197311980
<div class="inner_cell">
1197411981
<div class="text_cell_render border-box-sizing rendered_html">
@@ -11998,8 +12005,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1199812005

1199912006

1200012007
<div class="output_area">
12008+
1200112009
<div class="prompt"></div>
1200212010

12011+
1200312012
<div class="output_subarea output_stream output_stdout output_text">
1200412013
<pre>build status: reconstruction complete
1200512014
Inc. reactions: 33/60
@@ -12016,8 +12025,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1201612025
</div>
1201712026

1201812027
</div>
12019-
<div class="cell border-box-sizing text_cell rendered">
12020-
<div class="prompt input_prompt">
12028+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1202112029
</div>
1202212030
<div class="inner_cell">
1202312031
<div class="text_cell_render border-box-sizing rendered_html">
@@ -12043,10 +12051,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1204312051

1204412052

1204512053
<div class="output_area">
12054+
1204612055
<div class="prompt"></div>
1204712056

12057+
1204812058
<div class="output_subarea output_stream output_stdout output_text">
12049-
<pre>[&#39;cit &lt;=&gt; icit&#39;, &#39;icit + nad &lt;=&gt; akg + nadh&#39;, &#39;fdp &lt;=&gt; dhap + g3p&#39;, &#39; --&gt; adp&#39;, &#39;g6p &lt;=&gt; f6p&#39;, &#39; &lt;=&gt; gln&#39;, &#39;r5p &lt;=&gt; ru5p_D&#39;, &#39; &lt;=&gt; pi&#39;, &#39;mal_L + nad &lt;=&gt; nadh + oaa&#39;, &#39;atp + r5p &lt;=&gt; amp + prpp&#39;, &#39;0.39253 3pg + 20.7045 atp + 0.15446 cit + 0.38587 glu + 0.35261 oaa + 0.053446 prpp + 0.50563 pyr --&gt; 20.6508 adp + 20.6508 pi&#39;, &#39; --&gt; g1p&#39;, &#39;3pg + atp &lt;=&gt; 13dpg + adp&#39;, &#39; &lt;=&gt; amp&#39;, &#39;nadh --&gt; nad&#39;, &#39;atp + f6p --&gt; adp + fdp&#39;, &#39;e4p + xu5p_D &lt;=&gt; f6p + g3p&#39;, &#39;icit + nadp &lt;=&gt; akg + nadph&#39;, &#39;dhap &lt;=&gt; g3p&#39;, &#39;gln &lt;=&gt; glu&#39;, &#39;g1p &lt;=&gt; g6p&#39;, &#39;mal_L + nadp &lt;=&gt; nadph + pyr&#39;, &#39;atp + pyr --&gt; adp + oaa + pi&#39;, &#39;glu + nadp &lt;=&gt; akg + nadph&#39;, &#39;glu + nad &lt;=&gt; akg + nadh&#39;, &#39;ru5p_D &lt;=&gt; xu5p_D&#39;, &#39;adp + pi --&gt; atp&#39;, &#39;lac_L &lt;=&gt; &#39;, &#39;g3p + s7p &lt;=&gt; e4p + f6p&#39;, &#39;lac_L + nad &lt;=&gt; nadh + pyr&#39;, &#39;g3p + nad + pi &lt;=&gt; 13dpg + nadh&#39;, &#39;r5p + xu5p_D &lt;=&gt; g3p + s7p&#39;, &#39;mal_L + nad &lt;=&gt; nadh + pyr&#39;]
12059+
<pre>[&#39;fdp &lt;=&gt; dhap + g3p&#39;, &#39;g3p + nad + pi &lt;=&gt; 13dpg + nadh&#39;, &#39;atp + f6p --&gt; adp + fdp&#39;, &#39;g6p &lt;=&gt; f6p&#39;, &#39;3pg + atp &lt;=&gt; 13dpg + adp&#39;, &#39;g1p &lt;=&gt; g6p&#39;, &#39;dhap &lt;=&gt; g3p&#39;, &#39;lac_L + nad &lt;=&gt; nadh + pyr&#39;, &#39;atp + r5p &lt;=&gt; amp + prpp&#39;, &#39;ru5p_D &lt;=&gt; xu5p_D&#39;, &#39;r5p &lt;=&gt; ru5p_D&#39;, &#39;g3p + s7p &lt;=&gt; e4p + f6p&#39;, &#39;r5p + xu5p_D &lt;=&gt; g3p + s7p&#39;, &#39;e4p + xu5p_D &lt;=&gt; f6p + g3p&#39;, &#39;cit &lt;=&gt; icit&#39;, &#39;icit + nad &lt;=&gt; akg + nadh&#39;, &#39;icit + nadp &lt;=&gt; akg + nadph&#39;, &#39;mal_L + nad &lt;=&gt; nadh + oaa&#39;, &#39;mal_L + nad &lt;=&gt; nadh + pyr&#39;, &#39;mal_L + nadp &lt;=&gt; nadph + pyr&#39;, &#39;atp + pyr --&gt; adp + oaa + pi&#39;, &#39;gln &lt;=&gt; glu&#39;, &#39;glu + nad &lt;=&gt; akg + nadh&#39;, &#39;glu + nadp &lt;=&gt; akg + nadph&#39;, &#39;adp + pi --&gt; atp&#39;, &#39;nadh --&gt; nad&#39;, &#39; --&gt; g1p&#39;, &#39; &lt;=&gt; gln&#39;, &#39; --&gt; adp&#39;, &#39; &lt;=&gt; amp&#39;, &#39; &lt;=&gt; pi&#39;, &#39;lac_L &lt;=&gt; &#39;, &#39;0.39253 3pg + 20.7045 atp + 0.15446 cit + 0.38587 glu + 0.35261 oaa + 0.053446 prpp + 0.50563 pyr --&gt; 20.6508 adp + 20.6508 pi&#39;]
1205012060
</pre>
1205112061
</div>
1205212062
</div>
@@ -12055,8 +12065,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1205512065
</div>
1205612066

1205712067
</div>
12058-
<div class="cell border-box-sizing text_cell rendered">
12059-
<div class="prompt input_prompt">
12068+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1206012069
</div>
1206112070
<div class="inner_cell">
1206212071
<div class="text_cell_render border-box-sizing rendered_html">
@@ -12066,8 +12075,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1206612075
</div>
1206712076
</div>
1206812077
</div>
12069-
<div class="cell border-box-sizing text_cell rendered">
12070-
<div class="prompt input_prompt">
12078+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1207112079
</div>
1207212080
<div class="inner_cell">
1207312081
<div class="text_cell_render border-box-sizing rendered_html">
@@ -12095,8 +12103,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1209512103

1209612104

1209712105
<div class="output_area">
12106+
1209812107
<div class="prompt"></div>
1209912108

12109+
1210012110
<div class="output_subarea output_stream output_stdout output_text">
1210112111
<pre>build status: reconstruction complete
1210212112
Inc. reactions: 39/61
@@ -12113,8 +12123,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1211312123
</div>
1211412124

1211512125
</div>
12116-
<div class="cell border-box-sizing text_cell rendered">
12117-
<div class="prompt input_prompt">
12126+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1211812127
</div>
1211912128
<div class="inner_cell">
1212012129
<div class="text_cell_render border-box-sizing rendered_html">
@@ -12143,8 +12152,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1214312152

1214412153

1214512154
<div class="output_area">
12155+
1214612156
<div class="prompt"></div>
1214712157

12158+
1214812159
<div class="output_subarea output_stream output_stdout output_text">
1214912160
<pre># of redundant pathway for pep = 2
1215012161
gtp + oaa &lt;=&gt; gdp + pep
@@ -12157,8 +12168,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1215712168
</div>
1215812169

1215912170
</div>
12160-
<div class="cell border-box-sizing text_cell rendered">
12161-
<div class="prompt input_prompt">
12171+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1216212172
</div>
1216312173
<div class="inner_cell">
1216412174
<div class="text_cell_render border-box-sizing rendered_html">
@@ -12191,8 +12201,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1219112201

1219212202

1219312203
<div class="output_area">
12204+
1219412205
<div class="prompt"></div>
1219512206

12207+
1219612208
<div class="output_subarea output_stream output_stdout output_text">
1219712209
<pre>used 33 reactions
1219812210
# of redundant pathway for pep = 1
@@ -12205,8 +12217,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
1220512217
</div>
1220612218

1220712219
</div>
12208-
<div class="cell border-box-sizing text_cell rendered">
12209-
<div class="prompt input_prompt">
12220+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
1221012221
</div>
1221112222
<div class="inner_cell">
1221212223
<div class="text_cell_render border-box-sizing rendered_html">

0 commit comments

Comments
 (0)