index.html 24.5 KB
Newer Older
Documenter.jl's avatar
Documenter.jl committed
1
<!DOCTYPE html>
Documenter.jl's avatar
Documenter.jl committed
2
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Loading, converting, and saving models · COBREXA.jl</title><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="../.."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../../assets/documenter.js"></script><script src="../../siteinfo.js"></script><script src="../../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../../assets/themeswap.js"></script><link href="../../assets/favicon.ico" rel="icon" type="image/x-icon"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../"><img class="docs-light-only" src="../../assets/logo.svg" alt="COBREXA.jl logo"/><img class="docs-dark-only" src="../../assets/logo-dark.svg" alt="COBREXA.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit">COBREXA.jl</span></div><form class="docs-search" action="../../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../../">Home</a></li><li><span class="tocitem">User guide</span><ul><li><input class="collapse-toggle" id="menuitem-2-1" type="checkbox"/><label class="tocitem" for="menuitem-2-1"><span class="docs-label">Quickstart tutorials</span><i class="docs-chevron"></i></label><ul class="collapsed"><li><a class="tocitem" href="../../tutorials/">All tutorials</a></li><li><a class="tocitem" href="../../tutorials/1_loading/">Loading and converting model data</a></li><li><a class="tocitem" href="../../tutorials/2_analysis/">Basic analysis of constraint-based models</a></li><li><a class="tocitem" href="../../tutorials/3_hpc/">Distributed processing and HPC environments</a></li><li><a class="tocitem" href="../../tutorials/4_modifying/">Modifying and saving the models</a></li></ul></li><li><input class="collapse-toggle" id="menuitem-2-2" type="checkbox"/><label class="tocitem" for="menuitem-2-2"><span class="docs-label">Advanced tutorials</span><i class="docs-chevron"></i></label><ul class="collapsed"><li><a class="tocitem" href="../../advanced/">All advanced tutorials</a></li><li><a class="tocitem" href="../../advanced/1_variants/">Exploring many model variants</a></li><li><a class="tocitem" href="../../advanced/2_custom_model/">Working with custom models</a></li></ul></li><li><input class="collapse-toggle" id="menuitem-2-3" type="checkbox" checked/><label class="tocitem" for="menuitem-2-3"><span class="docs-label">Examples and notebooks</span><i class="docs-chevron"></i></label><ul class="collapsed"><li><a class="tocitem" href="../">All notebooks</a></li><li class="is-active"><a class="tocitem" href>Loading, converting, and saving models</a><ul class="internal"><li><a class="tocitem" href="#Loading-models"><span>Loading models</span></a></li><li><a class="tocitem" href="#Using-the-generic-interface-to-access-model-details"><span>Using the generic interface to access model details</span></a></li><li><a class="tocitem" href="#Converting-between-model-types"><span>Converting between model types</span></a></li><li><a class="tocitem" href="#Saving-and-exporting-models"><span>Saving and exporting models</span></a></li></ul></li><li><a class="tocitem" href="../2_finding_balance/">Finding balance and variability of constraint-based models</a></li><li><a class="tocitem" href="../3_basic_stdmodel_usage/">Basic usage of <code>StandardModel</code></a></li><li><a class="tocitem" href="../4_basic_core_coupled_usage/">Basic usage of <code>CoreModel</code> and <code>CoreModelCoupled</code></a></li><li><a class="tocitem" href="../5_basic_stdmodel_construction/">Model construction and modification</a></li><li><a class="tocitem" href="../6_screening/">Exploring model variants with <code>screen</code></a></li><li><a class="tocitem" href="../7_community_model/">Building and analysing a small community model</a></li><li><a class="tocitem" href="../8_custom_model/">Using a custom model data structure</a></li><li><a class="tocitem" href="../9_max_min_driving_force_analysis/">Maximum-minimum driving force analysis</a></li></ul></li></ul></li><li><span class="tocitem">Types and functions</span><ul><li><a class="tocitem" href="../../functions/">Contents</a></li><li><a class="tocitem" href="../../functions/analysis/">Analysis functions</a></li><li><a class="tocitem" href="../../functions/base/">Base functions</a></li><li><a class="tocitem" href="../../functions/io/">Input and output</a></li><li><a class="tocitem" href="../../functions/reconstruction/">Model construction functions</a></li><li><a class="tocitem" href="../../functions/types/">Types</a></li><li><a class="tocitem" href="../../functions/utils/">Utilities</a></li></ul></li><li><a class="tocitem" href="../../howToContribute/">How to contribute</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">User guide</a></li><li><a class="is-disabled">Examples and notebooks</a></li><li class="is-active"><a href>Loading, converting, and saving models</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Loading, converting, and saving models</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/lcsb-biocore/COBREXA.jl/blob/master/docs/src/notebooks/1_loading_converting_saving.jl" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Loading,-converting,-and-saving-models"><a class="docs-heading-anchor" href="#Loading,-converting,-and-saving-models">Loading, converting, and saving models</a><a id="Loading,-converting,-and-saving-models-1"></a><a class="docs-heading-anchor-permalink" href="#Loading,-converting,-and-saving-models" title="Permalink"></a></h1><p><a href="https://mybinder.org/v2/gh/lcsb-biocore/COBREXA.jl/gh-pages?filepath=dev/notebooks/1_loading_converting_saving.ipynb"><img src="https://mybinder.org/badge_logo.svg" alt/></a> <a href="https://nbviewer.jupyter.org/github/lcsb-biocore/COBREXA.jl/blob/gh-pages/dev/notebooks/1_loading_converting_saving.ipynb"><img src="https://img.shields.io/badge/show-nbviewer-579ACA.svg" alt/></a></p><p><code>COBREXA</code> can load models stored in <code>.mat</code>, <code>.json</code>, and <code>.xml</code> formats (with the latter denoting SBML formatted models).</p><p>We will primarily use the <em>E. Coli</em> &quot;core&quot; model to demonstrate the utilities found in <code>COBREXA</code>. First, let&#39;s download the model in several formats.</p><pre><code class="language-julia"># Downloads the model files if they don&#39;t already exist
Documenter.jl's avatar
Documenter.jl committed
3
4
5
6
7
!isfile(&quot;e_coli_core.mat&quot;) &amp;&amp;
    download(&quot;http://bigg.ucsd.edu/static/models/e_coli_core.mat&quot;, &quot;e_coli_core.mat&quot;);
!isfile(&quot;e_coli_core.json&quot;) &amp;&amp;
    download(&quot;http://bigg.ucsd.edu/static/models/e_coli_core.json&quot;, &quot;e_coli_core.json&quot;);
!isfile(&quot;e_coli_core.xml&quot;) &amp;&amp;
Documenter.jl's avatar
Documenter.jl committed
8
    download(&quot;http://bigg.ucsd.edu/static/models/e_coli_core.xml&quot;, &quot;e_coli_core.xml&quot;);</code></pre><p>Now, load the package:</p><pre><code class="language-julia">using COBREXA</code></pre><div class="admonition is-success"><header class="admonition-header">Save bandwidth!</header><div class="admonition-body"><p>The published models usually do not change very often. It is therefore pretty useful to save them to a central location and load them from there. That saves your time, and does not unnecessarily consume the connectivity resources of the model repository.</p></div></div><h2 id="Loading-models"><a class="docs-heading-anchor" href="#Loading-models">Loading models</a><a id="Loading-models-1"></a><a class="docs-heading-anchor-permalink" href="#Loading-models" title="Permalink"></a></h2><p>Load the models using the <a href="../../functions/io/#COBREXA.load_model-Tuple{String}"><code>load_model</code></a> function. Each model is able to &quot;pretty-print&quot; itself, hiding the inner complexity.</p><pre><code class="language-julia">mat_model = load_model(&quot;e_coli_core.mat&quot;)</code></pre><pre class="documenter-example-output">Metabolic model of type MATModel
Documenter.jl's avatar
Documenter.jl committed
9
sparse([9, 51, 55, 64, 65, 34, 44, 59, 66, 64  …  20, 22, 23, 25, 16, 17, 34, 44, 57, 59], [1, 1, 1, 1, 1, 2, 2, 2, 2, 3  …  93, 93, 94, 94, 95, 95, 95, 95, 95, 95], [1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0  …  1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0], 72, 95)
Documenter.jl's avatar
Documenter.jl committed
10
11
12
Number of reactions: 95
Number of metabolites: 72
</pre><pre><code class="language-julia">json_model = load_model(&quot;e_coli_core.json&quot;)</code></pre><pre class="documenter-example-output">Metabolic model of type JSONModel
Documenter.jl's avatar
Documenter.jl committed
13
sparse([9, 51, 55, 64, 65, 34, 44, 59, 66, 64  …  20, 22, 23, 25, 16, 17, 34, 44, 57, 59], [1, 1, 1, 1, 1, 2, 2, 2, 2, 3  …  93, 93, 94, 94, 95, 95, 95, 95, 95, 95], [1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0  …  1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0], 72, 95)
Documenter.jl's avatar
Documenter.jl committed
14
15
16
Number of reactions: 95
Number of metabolites: 72
</pre><pre><code class="language-julia">sbml_model = load_model(&quot;e_coli_core.xml&quot;)</code></pre><pre class="documenter-example-output">Metabolic model of type SBMLModel
Documenter.jl's avatar
Documenter.jl committed
17
sparse([41, 23, 51, 67, 61, 65, 1, 7, 19, 28  …  72, 3, 8, 33, 57, 66, 31, 45, 46, 57], [1, 2, 2, 2, 3, 3, 4, 4, 4, 4  …  93, 94, 94, 94, 94, 94, 95, 95, 95, 95], [-1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0  …  1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0], 72, 95)
Documenter.jl's avatar
Documenter.jl committed
18
19
Number of reactions: 95
Number of metabolites: 72
Documenter.jl's avatar
Documenter.jl committed
20
</pre><div class="admonition is-info"><header class="admonition-header">Note: `load_model` infers the output type from the file extension</header><div class="admonition-body"><p>Notice how each model was read into memory as a model type corresponding   to its file type, i.e. the file ending with <code>.json</code> loaded as a   <a href="../../functions/types/#COBREXA.JSONModel"><code>JSONModel</code></a>, the file ending with <code>.mat</code> loaded as <a href="../../functions/types/#COBREXA.MATModel"><code>MATModel</code></a>, and the   file ending with <code>.xml</code> loaded as an <a href="../../functions/types/#COBREXA.SBMLModel"><code>SBMLModel</code></a>.</p></div></div><p>You can directly inspect the model objects, although only with a specific way for each specific type.</p><p>JSON models contain their corresponding JSON:</p><pre><code class="language-julia">json_model.json</code></pre><pre class="documenter-example-output">Dict{String, Any} with 6 entries:
Documenter.jl's avatar
Documenter.jl committed
21
22
23
24
25
26
27
  &quot;metabolites&quot;  =&gt; Any[Dict{String, Any}(&quot;compartment&quot;=&gt;&quot;e&quot;, &quot;name&quot;=&gt;&quot;D-Glucos…
  &quot;id&quot;           =&gt; &quot;e_coli_core&quot;
  &quot;compartments&quot; =&gt; Dict{String, Any}(&quot;c&quot;=&gt;&quot;cytosol&quot;, &quot;e&quot;=&gt;&quot;extracellular space…
  &quot;reactions&quot;    =&gt; Any[Dict{String, Any}(&quot;name&quot;=&gt;&quot;Phosphofructokinase&quot;, &quot;metab…
  &quot;version&quot;      =&gt; &quot;1&quot;
  &quot;genes&quot;        =&gt; Any[Dict{String, Any}(&quot;name&quot;=&gt;&quot;adhE&quot;, &quot;id&quot;=&gt;&quot;b1241&quot;, &quot;notes…</pre><p>SBML models contain a complicated structure from <a href="https://github.com/LCSB-BioCore/SBML.jl"><code>SBML.jl</code> package</a>:</p><pre><code class="language-julia">typeof(sbml_model.sbml)</code></pre><pre class="documenter-example-output">SBML.Model</pre><p>MAT models contain MATLAB data:</p><pre><code class="language-julia">mat_model.mat</code></pre><pre class="documenter-example-output">Dict{String, Any} with 17 entries:
  &quot;description&quot; =&gt; &quot;e_coli_core&quot;
Documenter.jl's avatar
Documenter.jl committed
28
29
30
  &quot;c&quot;           =&gt; [0.0; 0.0; … ; 0.0; 0.0;;]
  &quot;rev&quot;         =&gt; [0; 0; … ; 1; 0;;]
  &quot;mets&quot;        =&gt; Any[&quot;glc__D_e&quot;; &quot;gln__L_c&quot;; … ; &quot;g3p_c&quot;; &quot;g6p_c&quot;;;]
Documenter.jl's avatar
Documenter.jl committed
31
32
  &quot;grRules&quot;     =&gt; Any[&quot;b3916 or b1723&quot;; &quot;((b0902 and b0903) and b2579) or (b09…
  &quot;subSystems&quot;  =&gt; Any[&quot;Glycolysis/Gluconeogenesis&quot;; &quot;Pyruvate Metabolism&quot;; … ;…
Documenter.jl's avatar
Documenter.jl committed
33
34
35
  &quot;b&quot;           =&gt; [0.0; 0.0; … ; 0.0; 0.0;;]
  &quot;metFormulas&quot; =&gt; Any[&quot;C6H12O6&quot;; &quot;C5H10N2O3&quot;; … ; &quot;C3H5O6P&quot;; &quot;C6H11O9P&quot;;;]
  &quot;rxnGeneMat&quot;  =&gt; sparse([6, 10, 6, 11, 27, 82, 93, 94, 12, 12  …  37, 38, 38,…
Documenter.jl's avatar
Documenter.jl committed
36
37
  &quot;S&quot;           =&gt; [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0…
  &quot;metNames&quot;    =&gt; Any[&quot;D-Glucose&quot;; &quot;L-Glutamine&quot;; … ; &quot;Glyceraldehyde 3-phosph…
Documenter.jl's avatar
Documenter.jl committed
38
39
40
  &quot;lb&quot;          =&gt; [0.0; 0.0; … ; -1000.0; 0.0;;]
  &quot;metCharge&quot;   =&gt; [0.0; 0.0; … ; -2.0; -2.0;;]
  &quot;ub&quot;          =&gt; [1000.0; 1000.0; … ; 1000.0; 1000.0;;]
Documenter.jl's avatar
Documenter.jl committed
41
  &quot;rxnNames&quot;    =&gt; Any[&quot;Phosphofructokinase&quot;; &quot;Pyruvate formate lyase&quot;; … ; &quot;O2…
Documenter.jl's avatar
Documenter.jl committed
42
43
  &quot;rxns&quot;        =&gt; Any[&quot;PFK&quot;; &quot;PFL&quot;; … ; &quot;O2t&quot;; &quot;PDH&quot;;;]
  &quot;genes&quot;       =&gt; Any[&quot;b1241&quot;; &quot;b0351&quot;; … ; &quot;b2935&quot;; &quot;b3919&quot;;;]</pre><h2 id="Using-the-generic-interface-to-access-model-details"><a class="docs-heading-anchor" href="#Using-the-generic-interface-to-access-model-details">Using the generic interface to access model details</a><a id="Using-the-generic-interface-to-access-model-details-1"></a><a class="docs-heading-anchor-permalink" href="#Using-the-generic-interface-to-access-model-details" title="Permalink"></a></h2><p>To prevent the complexities of object representation, <code>COBREXA.jl</code> uses a set of generic interface functions that extract various important information from all supported model types. This approach ensures that the analysis functions can work on any data.</p><p>For example, you can check the reactions and metabolites contained in SBML and JSON models using the same accessor:</p><pre><code class="language-julia">reactions(json_model)</code></pre><pre class="documenter-example-output">95-element Vector{String}:
Documenter.jl's avatar
Documenter.jl committed
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
 &quot;PFK&quot;
 &quot;PFL&quot;
 &quot;PGI&quot;
 &quot;PGK&quot;
 &quot;PGL&quot;
 &quot;ACALD&quot;
 &quot;AKGt2r&quot;
 &quot;PGM&quot;
 &quot;PIt2r&quot;
 &quot;ALCD2x&quot;

 &quot;MALt2_2&quot;
 &quot;MDH&quot;
 &quot;ME1&quot;
 &quot;ME2&quot;
 &quot;NADH16&quot;
 &quot;NADTRHD&quot;
 &quot;NH4t&quot;
 &quot;O2t&quot;
 &quot;PDH&quot;</pre><pre><code class="language-julia">reactions(sbml_model)</code></pre><pre class="documenter-example-output">95-element Vector{String}:
 &quot;R_EX_fum_e&quot;
 &quot;R_ACONTb&quot;
 &quot;R_TPI&quot;
 &quot;R_SUCOAS&quot;
 &quot;R_GLNS&quot;
 &quot;R_EX_pi_e&quot;
 &quot;R_PPC&quot;
 &quot;R_O2t&quot;
 &quot;R_G6PDH2r&quot;
 &quot;R_TALA&quot;

 &quot;R_THD2&quot;
 &quot;R_EX_h2o_e&quot;
 &quot;R_GLUSy&quot;
 &quot;R_ME1&quot;
 &quot;R_GLUN&quot;
 &quot;R_EX_o2_e&quot;
 &quot;R_FRUpts2&quot;
 &quot;R_ALCD2x&quot;
 &quot;R_PIt2r&quot;</pre><pre><code class="language-julia">issetequal(reactions(json_model), reactions(mat_model)) # do models contain the same reactions?</code></pre><pre class="documenter-example-output">true</pre><p>All accessors are defined in a single file in COBREXA source code; you may therefore get a list of all accessors as follows:</p><pre><code class="language-julia">using InteractiveUtils

for method in filter(
    x -&gt; endswith(string(x.file), &quot;MetabolicModel.jl&quot;),
    InteractiveUtils.methodswith(MetabolicModel, COBREXA),
)
    println(method.name)
end</code></pre><pre class="documenter-example-output">balance
bounds
coupling
coupling_bounds
Documenter.jl's avatar
Documenter.jl committed
94
fluxes
Documenter.jl's avatar
Documenter.jl committed
95
gene_annotations
Documenter.jl's avatar
Documenter.jl committed
96
gene_name
Documenter.jl's avatar
Documenter.jl committed
97
98
99
100
101
102
gene_notes
genes
metabolite_annotations
metabolite_charge
metabolite_compartment
metabolite_formula
Documenter.jl's avatar
Documenter.jl committed
103
metabolite_name
Documenter.jl's avatar
Documenter.jl committed
104
105
106
metabolite_notes
metabolites
n_coupling_constraints
Documenter.jl's avatar
Documenter.jl committed
107
n_fluxes
Documenter.jl's avatar
Documenter.jl committed
108
109
110
111
n_genes
n_metabolites
n_reactions
objective
Documenter.jl's avatar
Documenter.jl committed
112
precache!
Documenter.jl's avatar
Documenter.jl committed
113
reaction_annotations
Documenter.jl's avatar
Documenter.jl committed
114
reaction_flux
Documenter.jl's avatar
Documenter.jl committed
115
reaction_gene_association
Documenter.jl's avatar
Documenter.jl committed
116
reaction_name
Documenter.jl's avatar
Documenter.jl committed
117
reaction_notes
Documenter.jl's avatar
Documenter.jl committed
118
reaction_stoichiometry
Documenter.jl's avatar
Documenter.jl committed
119
120
reaction_subsystem
reactions
Documenter.jl's avatar
Documenter.jl committed
121
stoichiometry</pre><h2 id="Converting-between-model-types"><a class="docs-heading-anchor" href="#Converting-between-model-types">Converting between model types</a><a id="Converting-between-model-types-1"></a><a class="docs-heading-anchor-permalink" href="#Converting-between-model-types" title="Permalink"></a></h2><p>It is possible to convert model types to-and-fro. To do this, use the <code>convert</code> function, which is overloaded from Julia&#39;s <code>Base</code>.</p><div class="admonition is-danger"><header class="admonition-header">Data loss may occur when converting between models</header><div class="admonition-body"><p>The conversion of models only uses the data accessible through the generic accessors. Other data may get lost.</p></div></div><pre><code class="language-julia">m = convert(MATModel, json_model)</code></pre><pre class="documenter-example-output">Metabolic model of type MATModel
Documenter.jl's avatar
Documenter.jl committed
122
sparse([9, 51, 55, 64, 65, 34, 44, 59, 66, 64  …  20, 22, 23, 25, 16, 17, 34, 44, 57, 59], [1, 1, 1, 1, 1, 2, 2, 2, 2, 3  …  93, 93, 94, 94, 95, 95, 95, 95, 95, 95], [1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0  …  1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0], 72, 95)
Documenter.jl's avatar
Documenter.jl committed
123
124
Number of reactions: 95
Number of metabolites: 72
Documenter.jl's avatar
Documenter.jl committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
</pre><p><code>m</code> will now contain the MATLAB-style matrix representation of the model:</p><pre><code class="language-julia">Matrix(m.mat[&quot;S&quot;])</code></pre><pre class="documenter-example-output">72×95 Matrix{Float64}:
  0.0  0.0   0.0  0.0   0.0  0.0   0.0  …  0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0  …  0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0  -1.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  1.0  0.0   0.0  0.0   1.0  1.0   1.0     0.0  0.0  -4.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0  -1.0     0.0  0.0   3.0  0.0  0.0  0.0  0.0
  ⋮                          ⋮          ⋱             ⋮                   
 -1.0  0.0   1.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  1.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  1.0   0.0  0.0   0.0  0.0   0.0  …  0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0
  0.0  0.0   0.0  0.0   0.0  0.0   0.0  …  0.0  0.0   0.0  0.0  0.0  0.0  0.0
Documenter.jl's avatar
Documenter.jl committed
145
  0.0  0.0  -1.0  0.0   0.0  0.0   0.0     0.0  0.0   0.0  0.0  0.0  0.0  0.0</pre><p>The loading and conversion can be combined using a shortcut:</p><pre><code class="language-julia">m = load_model(MATModel, &quot;e_coli_core.json&quot;)</code></pre><pre class="documenter-example-output">Metabolic model of type MATModel
Documenter.jl's avatar
Documenter.jl committed
146
sparse([9, 51, 55, 64, 65, 34, 44, 59, 66, 64  …  20, 22, 23, 25, 16, 17, 34, 44, 57, 59], [1, 1, 1, 1, 1, 2, 2, 2, 2, 3  …  93, 93, 94, 94, 95, 95, 95, 95, 95, 95], [1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0  …  1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0], 72, 95)
Documenter.jl's avatar
Documenter.jl committed
147
148
Number of reactions: 95
Number of metabolites: 72
Documenter.jl's avatar
Documenter.jl committed
149
</pre><h2 id="Saving-and-exporting-models"><a class="docs-heading-anchor" href="#Saving-and-exporting-models">Saving and exporting models</a><a id="Saving-and-exporting-models-1"></a><a class="docs-heading-anchor-permalink" href="#Saving-and-exporting-models" title="Permalink"></a></h2><p><code>COBREXA.jl</code> supports exporting the models in JSON and MAT format, using <a href="../../functions/io/#COBREXA.save_model-Tuple{MetabolicModel, String}"><code>save_model</code></a>.</p><pre><code class="language-julia">save_model(m, &quot;converted_model.json&quot;)
Documenter.jl's avatar
Documenter.jl committed
150
save_model(m, &quot;converted_model.mat&quot;)</code></pre><p>If you need a non-standard suffix, use the type-specific saving functions:</p><pre><code class="language-julia">save_json_model(m, &quot;file.without.a.good.suffix&quot;)
Documenter.jl's avatar
Documenter.jl committed
151
save_mat_model(m, &quot;another.file.matlab&quot;)</code></pre><p>If you are saving the models only for future processing in Julia environment, it is often wasteful to encode the models to external formats and decode them back. Instead, you can use the &quot;native&quot; Julia data format, accessible with package <code>Serialization</code>.</p><p>This way, you can use <code>serialize</code> to save even the <a href="../../functions/types/#COBREXA.StandardModel"><code>StandardModel</code></a> that has no file format associated:</p><pre><code class="language-julia">using Serialization
Documenter.jl's avatar
Documenter.jl committed
152
153
154
155
156

sm = convert(StandardModel, m)

open(f -&gt; serialize(f, sm), &quot;myModel.stdmodel&quot;, &quot;w&quot;)</code></pre><p>The models can then be loaded back using <code>deserialize</code>:</p><pre><code class="language-julia">sm2 = deserialize(&quot;myModel.stdmodel&quot;)
issetequal(metabolites(sm), metabolites(sm2))</code></pre><pre class="documenter-example-output">true</pre><p>This form of loading operation is usually pretty quick:</p><pre><code class="language-julia">t = @elapsed deserialize(&quot;myModel.stdmodel&quot;)
Documenter.jl's avatar
Documenter.jl committed
157
@info &quot;Deserialization took $t seconds&quot;</code></pre><pre class="documenter-example-output">[ Info: Deserialization took 0.002105981 seconds</pre><p>Notably, large and complicated models with thousands of reactions and annotations can take seconds to decode properly. Serialization allows you to almost completely remove this overhead, and scales well to tens of millions of reactions.</p><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« All notebooks</a><a class="docs-footer-nextpage" href="../2_finding_balance/">Finding balance and variability of constraint-based models »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> on <span class="colophon-date" title="Monday 16 May 2022 19:38">Monday 16 May 2022</span>. Using Julia version 1.7.0.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>