Commit 662e4387 authored by St. Elmo's avatar St. Elmo
Browse files

added gibbs import

parent 1735e27c
......@@ -7,12 +7,12 @@ version = "0.1.0"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
JLD = "4138dd39-2aa7-5051-a626-17a0bb65d9c8"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MATLAB = "10e44e05-a98a-55b3-a45b-ba969058deb6"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
......
using JLD
using Measurements
include("buildfuncs.jl")
@info "Building ΔG files"
for f in readdir(joinpath("..", "data"))
if contains(f, "kegg_reactions_CC_")
ph = split(f, "_")[end][1:5]
mkGibbsDB(joinpath("..", "data", f), joinpath("..", "data", "gibbs_$ph.jld"))
end
end
\ No newline at end of file
[ Info: Building ΔG files
"""
mkGibbsDB(equilibrator_file_loc::String)
Read and parse equilibrator ΔG data. Save to Julia file.
"""
function mkGibbsDB(in_file_loc::String, out_file_loc::String)
gibbs = Dict{String, Measurement{Float64}}()
open(in_file_loc) do io
for ln in eachline(io)
startswith(ln, "!") && continue
prts = split(ln, "\t")
if prts[2] != "nan"
gibbs[prts[1]] = parse(Float64, prts[2]) ± parse(Float64, prts[3])
end
end
end
JLD.save(out_file_loc, "gibbs", gibbs)
end
using CobraTools
# E. coli model
# modelpath = joinpath("models", "iJO1366.json")
# model = CobraTools.readmodel(modelpath)
modelpath = joinpath("models", "iJO1366.json")
model = CobraTools.readmodel(modelpath)
# biomass_rxn = findfirst(model.rxns, "BIOMASS_Ec_iJO1366_WT_53p95M")
# solobj = CobraTools.fba(model, biomass_rxn)
biomass_rxn = findfirst(model.rxns, "BIOMASS_Ec_iJO1366_WT_53p95M")
solobj = CobraTools.fba(model, biomass_rxn)
# ad = CobraTools.atom_exchange(model, biomass_rxn)
......
......@@ -3,7 +3,6 @@
This is package aims to provide basic constraint based reconstruction analysis (COBRA) tools in the Julia environment.
## Installation
To import SBML formatted models you will need both `PyCall` and `python-libsbml` installed. See [here](https://stochasticreveller.wordpress.com/2016/08/02/sbml-and-the-julia-programming-language/) for some installation hints.
To import Matlab formatted models you will need `MATLAB.jl` installed and a working Matlab. Refer to the documentation of MATLAB.jl for installation instructions.
......@@ -53,7 +52,7 @@ The standard (temperature 25 °C, pressue 1 bar, concentration 1M) Gibbs energie
### Citations
Cobrapy
Ebrahim, A., Lerman, J.A., Palsson, B.O. & Hyduke, D. R. (2013) COBRApy: COnstraints-Based Reconstruction and Analysis for Python. BMC Syst Biol 7, 74. https://doi.org/10.1186/1752-0509-7-74
Ebrahim, A., Lerman, J.A., Palsson, B.O. & Hyduke, D. R. (2013). COBRApy: COnstraints-Based Reconstruction and Analysis for Python. BMC Systems Biology, 7(74). https://doi.org/10.1186/1752-0509-7-74
ACHR
......@@ -61,4 +60,7 @@ CHRR
Equilibrator
Noor, E., Bar-Even, A., Flamholz, A., Lubling, Y., Davidi, D., & Milo, R. (2012). An integrated open framework for thermodynamics of reactions that combines accuracy and coverage. Bioinformatics (Oxford, England), 28(15), 2037–2044. https://doi.org/10.1093/bioinformatics/bts317
\ No newline at end of file
Noor, E., Bar-Even, A., Flamholz, A., Lubling, Y., Davidi, D., & Milo, R. (2012). An integrated open framework for thermodynamics of reactions that combines accuracy and coverage. Bioinformatics, 28(15), 2037–2044. https://doi.org/10.1093/bioinformatics/bts317
MetaNetX
Bernard, T., Bridge A., Morgat A., Moretti, S., Xenarios, I., Pagni, M., (2014) Reconciliation of metabolites and biochemical reactions for metabolic networks, Briefings in Bioinformatics, 15(1), 123–135, https://doi.org/10.1093/bib/bbs058
\ No newline at end of file
......@@ -11,6 +11,7 @@ mutable struct Metabolite
compartment :: String
notes :: Dict{String, Array{String, 1}}
annotation :: Dict{String, Union{Array{String, 1}, String}}
concentration :: Union{Float64, Measurement{Float64}}
end
function Metabolite()
......@@ -21,7 +22,8 @@ function Metabolite()
compartment = ""
notes = Dict{String, Array{String, 1}}()
annotation = Dict{String, Union{Array{String, 1}, String}}()
Metabolite(id, name, formula, charge, compartment, notes, annotation)
concentration = 1e-3 # 1mM
Metabolite(id, name, formula, charge, compartment, notes, annotation, concentration)
end
function Metabolite(id::String)
......@@ -31,7 +33,8 @@ function Metabolite(id::String)
compartment = ""
notes = Dict{String, Array{String, 1}}()
annotation = Dict{String, Union{Array{String, 1}, String}}()
Metabolite(id, name, formula, charge, compartment, notes, annotation)
concentration = 1e-3 # 1mM
Metabolite(id, name, formula, charge, compartment, notes, annotation, concentration)
end
function Metabolite(d::Dict{String, Any})
......@@ -68,8 +71,8 @@ function Metabolite(d::Dict{String, Any})
cto.verbose && @warn "Unrecognized reaction field: $k"
end
end
Metabolite(id, name, formula, charge, compartment, notes, annotation)
concentration = 1e-3 # 1mM
Metabolite(id, name, formula, charge, compartment, notes, annotation, concentration)
end
"""
......
module CobraTools
# model reading and writing
# IO of models and data
using JSON
using MATLAB
using PyCall # NB: need to install libsbml
using JLD
# Model analysis
using SparseArrays
......@@ -18,24 +18,7 @@ using Ipopt
# Gibbs
using Measurements
# Global options for package
mutable struct CobraToolsOptions
verbose :: Bool
end
cto = CobraToolsOptions(true)
"""
Reduce verbosity (@info and @warn are suppressed)
This is mostly useful for unit testing to suppress all the model reading and writing that occurs therein.
"""
function setverbose(verbose)
if verbose
cto.verbose = true
else
cto.verbose = false
end
end
include("global_cobratools.jl")
include("cobra.jl")
export Reaction, Metabolite, Gene
......@@ -51,4 +34,6 @@ include("met_tools.jl")
include("basic_analysis.jl")
# export Solution
include("gibbs_tools.jl")
end # module
"""
Gibbs
Standard Gibbs free energy of reaction
"""
struct ΔᵣG
ph :: Float64
rxn :: Union{Reaction, Nothing} # get stoichiometry and concentrations from here
ΔG :: Union{Float64, Measurement{Float64}}
end
"""
Adjusted Gibbs free energy of reaction.
ΔᵣG = ΔᵣG⁰ + RTln(Q)
"""
mutable struct ΔᵣG
R :: Float64
T :: Float64
Q :: Float64 # this gets calculated.
ΔG⁰ :: Union{Float64, Measurement{Float64}}
ΔG :: Union{Float64, Measurement{Float64}}
end
function update!(ΔG::ΔᵣG)
if !isnothing(ΔG.ΔG⁰.rxn)
for (met, stoich) in ΔG.ΔG⁰.rxn
if met.concentration 0.0 # no zero concentrations
ΔG.Q = 1.0
break
else
ΔG.Q = stoich > 0 ? (ΔG.Q = ΔG.Q*met.concentration^stoich) : (ΔG.Q = ΔG.Q/met.concentration^stoich)
end
end
else
ΔG.Q = 1.0
end
ΔG.ΔG = ΔG.ΔG⁰ + ΔG.R * ΔG.T * log(ΔG.Q)
end
"""
Display standard ΔG.
"""
function Base.show(io::IO, ΔG::ΔᵣG⁰)
println(io, "ΔᵣG⁰ (pH = $(ΔG.pH))= ", dg.ΔG ," kJ/mol")
end
"""
Display modified ΔG.
"""
function Base.show(io::IO, ΔG::ΔᵣG)
println(io, "ΔᵣG⁰ (pH = $(ΔG.pH))= ", dg.ΔG ," kJ/mol")
println(io, "At T = $(ΔG.T) and Q = $(ΔG.Q)")
if !isnothing(ΔG.ΔG.rxn)
for (met, stoich) in ΔG.ΔG.rxn
println(io, met.name, " = ", met.concentration)
end
end
end
\ No newline at end of file
# Global options for package
mutable struct CobraToolsOptions
verbose :: Bool
end
cto = CobraToolsOptions(true)
"""
setverbose(verbose::Bool)
Reduce verbosity (@info and @warn are suppressed) of some functions.
This is mostly useful for unit testing to suppress output (lots of model reading and writing that occurs therein).
"""
function setverbose(verbose)
if verbose
cto.verbose = true
else
cto.verbose = false
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment