Unverified Commit e0ef1855 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #413 from LCSB-BioCore/mo-reaction-name

Added `reaction_equation` function and tests
parents 8705af8d 7759085b
Pipeline #44965 passed with stages
in 32 minutes and 16 seconds
......@@ -70,3 +70,23 @@ function is_mass_balanced(model::StandardModel, rxn::Reaction)
return all(sum(values(atom_balances)) == 0), atom_balances
end
"""
stoichiometry_string(rxn_dict)
Return the reaction equation as a string.
# Example
```
julia> req = Dict("coa_c" => -1, "for_c" => 1, "accoa_c" => 1, "pyr_c" => -1);
julia> stoichiometry_string(req)
"coa_c + pyr_c = for_c + accoa_c"
```
"""
function stoichiometry_string(req)
replace_one(n) = abs(n) == 1 ? "" : string(abs(n))
substrates =
join(strip.(["$(replace_one(n)) $met" for (met, n) in req if n < 0]), " + ")
products = join(strip.(["$(replace_one(n)) $met" for (met, n) in req if n >= 0]), " + ")
return substrates * " = " * products
end
@testset "Reaction utilities" begin
# test if reaction equation can be built back into a sensible reaction string
req = Dict("coa_c" => -1, "for_c" => 1, "accoa_c" => 1, "pyr_c" => -1)
rstr_out = stoichiometry_string(req)
@test occursin("coa_c", split(rstr_out, " = ")[1])
@test occursin("for", split(rstr_out, " = ")[2])
end
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