Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
COBREXA.jl
Commits
0c72a4bf
Unverified
Commit
0c72a4bf
authored
Aug 10, 2021
by
St. Elmo
Browse files
add back stoichiometry_string
parent
60a1abab
Pipeline
#45233
passed with stages
in 12 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/base/utils/Reaction.jl
View file @
0c72a4bf
...
...
@@ -100,3 +100,36 @@ reaction_mass_balanced(model::StandardModel, rxn::Reaction) =
reaction_mass_balanced
(
model
::
StandardModel
,
reaction_dict
::
Dict
{
String
,
Float64
})
=
all
(
values
(
reaction_atom_balance
(
model
,
reaction_dict
))
.==
0
)
"""
stoichiometry_string(rxn_dict::Dict{String, Float64}; format_id = x -> x)
Return the reaction equation as a string. The metabolite strings can be manipulated by
setting `format_id`.
# 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
"
julia> stoichiometry_string(req; format_id = x -> x[1:end-2])
"
coa
+
pyr
=
for
+
accoa
"
```
"""
function
stoichiometry_string
(
req
;
format_id
=
x
->
x
)
count_prefix
(
n
)
=
abs
(
n
)
==
1
?
""
:
string
(
abs
(
n
),
" "
)
substrates
=
join
((
string
(
count_prefix
(
n
),
format_id
(
met
))
for
(
met
,
n
)
in
req
if
n
<
0
),
" + "
)
products
=
join
((
string
(
count_prefix
(
n
),
format_id
(
met
))
for
(
met
,
n
)
in
req
if
n
>=
0
),
" + "
)
return
substrates
*
" = "
*
products
end
"""
stoichiometry_string(rxn::Reaction; kwargs)
Alternative of [`stoichiometry_string`](@ref) take takes a `Reaction` as an argument.
"""
stoichiometry_string
(
rxn
::
Reaction
;
kwargs
...
)
=
stoichiometry_string
(
rxn
.
metabolites
;
kwargs
...
)
test/base/utils/reaction.jl
View file @
0c72a4bf
...
...
@@ -38,4 +38,10 @@
atol
=
TEST_TOLERANCE
,
)
@test
reaction_atom_balance
(
model
,
Dict
(
"h_c"
=>
-
1.0
,
"h2o_c"
=>
1.0
))[
"H"
]
==
1.0
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment