Skip to content

Commit

Permalink
Fixing summary calls in simulating.ipynb
Browse files Browse the repository at this point in the history
Previously, the summary calls were made on a solution object that was
optimized for ATP maintenance, while the current objective was for
biomass optimization
  • Loading branch information
pstjohn committed Mar 16, 2016
1 parent 1c13b4b commit aa7d9db
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
18 changes: 7 additions & 11 deletions cobra/flux_analysis/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def rxn_summary(r):
"} {0.id:>8} {0.reaction:>54}").format(row[1]))


def model_summary(model, threshold=1E-8, fva=None, digits=2):
def model_summary(model, threshold=1E-8, fva=None, decimals=2):
"""Print a summary of the input and output fluxes of the model.
threshold: float
tolerance for determining if a flux is zero (not printed)
fva: int or None
Whether or not to calculate and report flux variability in the
output summary
digits: int
decimals: int
number of digits after the decimal place to print
"""
Expand All @@ -129,11 +129,8 @@ def model_summary(model, threshold=1E-8, fva=None, digits=2):
out_fluxes = pd.Series({r.reactants[0]: r.x for r in out_rxns})
in_fluxes = pd.Series({r.reactants[0]: r.x for r in in_rxns})

# sort and round
out_fluxes.sort_values(ascending=False, inplace=True)
out_fluxes = out_fluxes.round(digits)
in_fluxes.sort_values(inplace=True)
in_fluxes = in_fluxes.round(digits)
out_fluxes = out_fluxes.sort_values(ascending=False).round(decimals)
in_fluxes = in_fluxes.sort_values().round(decimals)

table = pd.np.array(
[((a if a else ''), (b if b else ''), (c if c else ''))
Expand Down Expand Up @@ -167,10 +164,9 @@ def model_summary(model, threshold=1E-8, fva=None, digits=2):
'err': half_span.loc[r.id]}
for r in in_rxns}).T

out_fluxes.sort_values(by='x', ascending=False, inplace=True)
out_fluxes = out_fluxes.round(digits)
in_fluxes.sort_values(by='x', inplace=True)
in_fluxes = in_fluxes.round(digits)
out_fluxes = out_fluxes.sort_values(
by='x', ascending=False).round(decimals)
in_fluxes = in_fluxes.sort_values(by='x').round(decimals)

in_fluxes_s = in_fluxes.apply(
lambda x: u'{0:0.2f} \u00B1 {1:0.2f}'.format(x.x, x.err),
Expand Down
82 changes: 42 additions & 40 deletions documentation_builder/simulating.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"data": {
"text/plain": [
"<Solution 0.87 at 0x7f1bb8789550>"
"<Solution 0.87 at 0x10ddd0080>"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -106,7 +106,7 @@
{
"data": {
"text/plain": [
"0.8739215069684909"
"0.8739215069684305"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -172,8 +172,8 @@
" % FLUX RXN ID REACTION \n",
" 41.6% 16 GAPD g3p_c + nad_c + pi_c <=> 13dpg_c + h_c + nadh_c\n",
" 24.1% 9.3 PDH coa_c + nad_c + pyr_c --> accoa_c + co2_c + nadh_c\n",
" 13.1% 5.1 MDH mal__L_c + nad_c <=> h_c + nadh_c + oaa_c\n",
" 13.1% 5.1 AKGDH akg_c + coa_c + nad_c --> co2_c + nadh_c + succoa_c\n",
" 13.1% 5.1 MDH mal__L_c + nad_c <=> h_c + nadh_c + oaa_c\n",
" 8.0% 3.1 Bioma... 1.496 3pg_c + 3.7478 accoa_c + 59.81 atp_c + 0.36...\n",
"\n",
"CONSUMING REACTIONS -- Nicotinamide adenine dinucleotide - reduced\n",
Expand Down Expand Up @@ -263,7 +263,7 @@
{
"data": {
"text/plain": [
"{<Reaction Biomass_Ecoli_core at 0x7f1b92f03470>: 1.0}"
"{<Reaction Biomass_Ecoli_core at 0x116510828>: 1.0}"
]
},
"execution_count": 9,
Expand Down Expand Up @@ -292,7 +292,7 @@
{
"data": {
"text/plain": [
"{<Reaction ATPM at 0x7f1b92f036d8>: 1}"
"{<Reaction ATPM at 0x1165107b8>: 1}"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -320,7 +320,7 @@
{
"data": {
"text/plain": [
"175.00000000002336"
"174.99999999999997"
]
},
"execution_count": 11,
Expand Down Expand Up @@ -349,7 +349,7 @@
{
"data": {
"text/plain": [
"{<Reaction Biomass_Ecoli_core at 0x7f1b92f03470>: 1.0}"
"{<Reaction Biomass_Ecoli_core at 0x116510828>: 1.0}"
]
},
"execution_count": 12,
Expand Down Expand Up @@ -396,17 +396,17 @@
" <tr>\n",
" <th>ACALD</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ACALDt</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ACKr</th>\n",
" <td>-0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ACONTa</th>\n",
Expand All @@ -421,11 +421,11 @@
" <tr>\n",
" <th>ACt2r</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ADK1</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
Expand All @@ -436,12 +436,12 @@
" <tr>\n",
" <th>AKGt2r</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ALCD2x</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ATPM</th>\n",
Expand Down Expand Up @@ -475,8 +475,8 @@
" </tr>\n",
" <tr>\n",
" <th>D_LACt2</th>\n",
" <td>-0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ENO</th>\n",
Expand All @@ -486,11 +486,11 @@
" <tr>\n",
" <th>ETOHt2r</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>EX_ac_e</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" </tr>\n",
" </tbody>\n",
Expand All @@ -499,26 +499,26 @@
],
"text/plain": [
" maximum minimum\n",
"ACALD 0.00000 -0.00000\n",
"ACALDt 0.00000 -0.00000\n",
"ACKr -0.00000 -0.00000\n",
"ACALD 0.00000 0.00000\n",
"ACALDt -0.00000 0.00000\n",
"ACKr -0.00000 0.00000\n",
"ACONTa 6.00725 6.00725\n",
"ACONTb 6.00725 6.00725\n",
"ACt2r 0.00000 -0.00000\n",
"ADK1 0.00000 0.00000\n",
"ACt2r 0.00000 0.00000\n",
"ADK1 -0.00000 0.00000\n",
"AKGDH 5.06438 5.06438\n",
"AKGt2r 0.00000 -0.00000\n",
"ALCD2x 0.00000 -0.00000\n",
"AKGt2r 0.00000 0.00000\n",
"ALCD2x 0.00000 0.00000\n",
"ATPM 8.39000 8.39000\n",
"ATPS4r 45.51401 45.51401\n",
"Biomass_Ecoli_core 0.87392 0.87392\n",
"CO2t -22.80983 -22.80983\n",
"CS 6.00725 6.00725\n",
"CYTBD 43.59899 43.59899\n",
"D_LACt2 -0.00000 -0.00000\n",
"D_LACt2 0.00000 0.00000\n",
"ENO 14.71614 14.71614\n",
"ETOHt2r 0.00000 -0.00000\n",
"EX_ac_e 0.00000 0.00000"
"ETOHt2r 0.00000 0.00000\n",
"EX_ac_e -0.00000 0.00000"
]
},
"execution_count": 13,
Expand Down Expand Up @@ -561,12 +561,12 @@
" <tbody>\n",
" <tr>\n",
" <th>ACALD</th>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" <td>-2.54237</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ACALDt</th>\n",
" <td>0.00000</td>\n",
" <td>-0.00000</td>\n",
" <td>-2.54237</td>\n",
" </tr>\n",
" <tr>\n",
Expand All @@ -586,7 +586,7 @@
" </tr>\n",
" <tr>\n",
" <th>ACt2r</th>\n",
" <td>-0.00000</td>\n",
" <td>0.00000</td>\n",
" <td>-3.81356</td>\n",
" </tr>\n",
" <tr>\n",
Expand Down Expand Up @@ -665,12 +665,12 @@
],
"text/plain": [
" maximum minimum\n",
"ACALD -0.00000 -2.54237\n",
"ACALDt 0.00000 -2.54237\n",
"ACALD 0.00000 -2.54237\n",
"ACALDt -0.00000 -2.54237\n",
"ACKr -0.00000 -3.81356\n",
"ACONTa 8.89452 0.84859\n",
"ACONTb 8.89452 0.84859\n",
"ACt2r -0.00000 -3.81356\n",
"ACt2r 0.00000 -3.81356\n",
"ADK1 17.16100 0.00000\n",
"AKGDH 8.04593 0.00000\n",
"AKGt2r 0.00000 -1.43008\n",
Expand Down Expand Up @@ -718,7 +718,7 @@
"output_type": "stream",
"text": [
"IN FLUXES OUT FLUXES OBJECTIVES \n",
"o2_e -21.80 ± 1.91 h2o_e 27.86 ± 2.86 Biomass_Ecoli_core 0.000\n",
"o2_e -21.80 ± 1.91 h2o_e 27.86 ± 2.86 Biomass_Ecoli_core 0.874\n",
"glc__D_e -9.76 ± 0.24 co2_e 21.81 ± 2.86 \n",
"nh4_e -4.84 ± 0.32 h_e 19.51 ± 2.86 \n",
"pi_e -3.13 ± 0.08 for_e 2.86 ± 2.86 \n",
Expand All @@ -734,6 +734,7 @@
}
],
"source": [
"model.optimize()\n",
"model.summary(fva=0.95)"
]
},
Expand All @@ -758,13 +759,14 @@
"PRODUCING REACTIONS -- Pyruvate\n",
"-------------------------------\n",
" % FLUX RXN ID REACTION \n",
" 50.0% 6.13 ± 6.13 PYK adp_c + h_c + pep_c --> atp_c + pyr_c\n",
" 50.0% 9.76 ± 0.24 GLCpts glc__D_e + pep_c --> g6p_c + pyr_c\n",
" 85.0% 9.76 ± 0.24 GLCpts glc__D_e + pep_c --> g6p_c + pyr_c\n",
" 15.0% 6.13 ± 6.13 PYK adp_c + h_c + pep_c --> atp_c + pyr_c\n",
"\n",
"CONSUMING REACTIONS -- Pyruvate\n",
"-------------------------------\n",
" % FLUX RXN ID REACTION \n",
"100.0% 11.34 ± 7.43 PDH coa_c + nad_c + pyr_c --> accoa_c + co2_c + nadh_c\n"
" 78.9% 11.34 ± 7.43 PDH coa_c + nad_c + pyr_c --> accoa_c + co2_c + nadh_c\n",
" 21.1% 0.85 ± 0.02 Bioma... 1.496 3pg_c + 3.7478 accoa_c + 59.81 atp_c + 0.36...\n"
]
}
],
Expand Down Expand Up @@ -817,7 +819,7 @@
{
"data": {
"text/plain": [
"6.072919944699606e-14"
"1.1102230246251565e-16"
]
},
"execution_count": 18,
Expand Down Expand Up @@ -846,7 +848,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.4.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit aa7d9db

Please sign in to comment.