Skip to content

Commit

Permalink
Add symengine support
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener committed Oct 26, 2017
1 parent e5947f6 commit 7f049d8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 67 deletions.
79 changes: 50 additions & 29 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,51 +99,72 @@ iJO1366 (*E. coli*) and Recon 2.2:

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

In [2]: from cobra.io import read_sbml_model
In [2]: from cobra.io import read_sbml_model

In [3]: from corda import CORDA
In [3]: from corda import CORDA

In [4]: ecoli = create_test_model("ecoli")
In [4]: ecoli = create_test_model("ecoli")

In [5]: conf = {}
In [5]: conf = {}

In [6]: for r in ecoli.reactions:
...: conf[r.id] = -1
...:
In [6]: for r in ecoli.reactions:
...: conf[r.id] = -1
...:

In [7]: conf["Ec_biomass_iJO1366_core_53p95M"] = 3
In [7]: conf["Ec_biomass_iJO1366_core_53p95M"] = 3

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

In [9]: %time opt.build()
CPU times: user 13.6 s, sys: 734 µs, total: 13.6 s
Wall time: 13.6 s
In [9]: %time opt.build()
CPU times: user 9.04 s, sys: 93 µs, total: 9.04 s
Wall time: 9.05 s

In [10]:
In [10]: print(opt)
build status: reconstruction complete
Inc. reactions: 456/2583
- unclear: 0/0
- exclude: 455/2582
- low and medium: 0/0
- high: 1/1

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

In [11]: conf = {}
In [11]:

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

In [13]: conf["biomass_reaction"] = 3
In [13]: conf = {}

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

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

In [16]: %time opt = CORDA(recon2, conf)
CPU times: user 1 s, sys: 8.95 ms, total: 1.01 s
Wall time: 1.01 s

In [17]: %time opt.build()
CPU times: user 24.7 s, sys: 240 µs, total: 24.7 s
Wall time: 24.8 s

In [28]: print(opt)
build status: reconstruction complete
Inc. reactions: 395/7864
- unclear: 0/0
- exclude: 394/7863
- low and medium: 0/0
- high: 1/1

.. |travis| image:: https://travis-ci.org/resendislab/corda.svg?branch=master
:target: https://travis-ci.org/resendislab/corda
Expand Down
4 changes: 2 additions & 2 deletions corda/corda.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
from collections import Counter
import re
from sympy.core.singleton import S
from optlang.symbolics import Zero

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

# Map confidences from forward to backward reactions
self.model.objective = S.Zero
self.model.objective = Zero
self.model.objective.direction = "min"
self.conf = {}
self.redundancies = {}
Expand Down
77 changes: 44 additions & 33 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11726,9 +11726,7 @@
div#notebook {
overflow: visible;
border-top: none;
}

@media print {
}@media print {
div.cell {
display: block;
page-break-inside: avoid;
Expand All @@ -11749,7 +11747,7 @@

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

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="CORDA-tutorial">CORDA tutorial<a class="anchor-link" href="#CORDA-tutorial">&#182;</a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Reactions,-Genes-and-confidences">Reactions, Genes and confidences<a class="anchor-link" href="#Reactions,-Genes-and-confidences">&#182;</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -11834,10 +11829,23 @@ <h2 id="Reactions,-Genes-and-confidences">Reactions, Genes and confidences<a cla


<div class="output_area">

<div class="prompt"></div>


<div class="output_subarea output_stream output_stderr output_text">
<pre>Loading symengine... This feature is in beta testing. Please report any issues you encounter on http://github.com/biosustain/optlang/issues
</pre>
</div>
</div>

<div class="output_area">

<div class="prompt output_prompt">Out[1]:</div>




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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-example">&#182;</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -11887,10 +11893,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt output_prompt">Out[2]:</div>




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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand All @@ -11928,10 +11935,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt output_prompt">Out[3]:</div>




<div class="output_text output_subarea output_execute_result">
<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>
</div>
Expand All @@ -11942,8 +11951,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand All @@ -11967,8 +11975,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -11998,8 +12005,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt"></div>


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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand All @@ -12043,10 +12051,12 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<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;]
<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;]
</pre>
</div>
</div>
Expand All @@ -12055,8 +12065,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand All @@ -12066,8 +12075,7 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -12095,8 +12103,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt"></div>


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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -12143,8 +12152,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt"></div>


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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down Expand Up @@ -12191,8 +12201,10 @@ <h2 id="A-small-example">A small example<a class="anchor-link" href="#A-small-ex


<div class="output_area">

<div class="prompt"></div>


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

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
Expand Down
Loading

0 comments on commit 7f049d8

Please sign in to comment.