6 releases (breaking)
0.5.0 | Mar 27, 2021 |
---|---|
0.4.0 | Mar 24, 2021 |
0.3.1 | Oct 22, 2020 |
0.2.0 | Oct 18, 2020 |
0.1.0 | Oct 16, 2020 |
#796 in Science
73KB
272 lines
KAIr (COBRA Alternative In rust)
COnstraint-Based Reconstruction and Analysis (COBRA) methods enable the use of knowledge-based reconstructions of the metabolism of a particular organism to simulate its metabolic network.
kair provides the translation from a SBML (using rust_sbml) document to the most basic
Linear Programming formulation of COBRA: Flux Balance Analysis (FBA). Being
f(z)
a function to optimize (historically, the biomass pseudoreaction or the ATPase),
S
and stoichimetry matrix; and v
the flux vector representing
the reactions in the reconstruction:
The FBA problem can then be optimized thanks to lp_modeler.
See What is flux balance analysis?, Orth et al., 2010 for a brief description of FBA.
Installation
Add kair it to your Cargo.toml:
[dependencies]
kair = "0.5.0"
In addition, add good_lp
with the solver of choice, for instance coin_cbc
(default):
[dependencies]
good_lp = { version="1.1.0", default_features=true }
Make sure you have installed the Cbc solver (other solvers do not require installation).
# Debian
sudo apt install coinor-cbc
# Arch
sudo pacman -S coin-or
# Mac OS
brew tap coin-or-tools/coinor && brew install coin-or-tools/coinor/cbc
Example
Some use
statements to get started.
use kair::{ModelLP, fba, flux_analysis::fva};
use good_lp::default_solver;
use std::str::FromStr;
First, read the SBML document, we will be using the e_coli_core model.
let file_str = std::fs::read_to_string("examples/EcoliCore.xml").unwrap();
let model = ModelLP::from_str(&file_str).unwrap();
Now, we can optimize it and print the solution, which is just a HashMap of pairs variable name -> solution value.
for (name, val) in fba(&mut model, default_solver).unwrap().iter() {
println!("{} = {}", name, val)
}
Output
R_EX_co2_e_ = 22.809834
R_ATPM_ = 8.39
R_H2Ot_ = -29.175827
R_GLNS_ = 0.22346173
...
R_BIOMASS_Ecoli_core_w_GAM_ = 0.8739215
...
R_EX_pi_e_ = -3.214895
R_SUCOAS_ = -5.064376
R_PGL_ = 4.959985
R_TKT1_ = 1.4969838
To run this example, on the root of this repository, run
cargo run --example ecoli
Flux variability analysis is also implemented:
let reactions: Vec<String> = model.reactions.iter().map(|(k, _v)| k.clone()).collect();
for (name, val) in fva(&mut model, default_solver, reactions).unwrap().iter() {
println!("{} = {:?}", name, val)
}
Output (you would need to use a bigger model to see the difference)
R_ACONTa = (6.007249575350586, 6.007249575350007)
R_ACALD = (0.0, 0.0)
R_ACKr = (-0.0, -0.0)
R_ICDHyr = (6.007249575351851, 6.007249575350007)
R_CO2t = (-22.80983331020489, -22.809833310205118)
R_RPI = (-2.2815030940668573, -2.2815030940674283)
R_ADK1 = (-0.0, -0.0000000000003395200787181807)
R_PGK = (-16.0235261431673, -16.02352614316787)
R_SUCCt3 = (0.0, -0.0000000000004168517383125921)
R_EX_pyr_e = (0.0, 0.0)
Dependencies
~2–2.7MB
~51K SLoC