Skip to content
Snippets Groups Projects
Unverified Commit 936cb0ce authored by St. Elmo's avatar St. Elmo Committed by Miroslav Kratochvil
Browse files

improved check_duplicate_reaction

parent 56ec8b3e
No related branches found
No related tags found
No related merge requests found
"""
check_duplicate_reaction(rxn::Reaction, rxns::Dict{String, Reaction})
check_duplicate_reaction(rxn::Reaction, rxns::Dict{String, Reaction}; only_metabolites=true)
Check if `rxn` already exists in `rxns` but has another `id`.
Looks through all the reaction equations of `rxns` and compares metabolite `id`s
and their stoichiometric coefficients to those of `rxn`.
If `only_metabolites` is `true` then only the metabolite `id`s are checked.
Otherwise, compares metabolite `id`s and the absolute value of their stoichiometric coefficients to those of `rxn`.
If `rxn` has the same reaction equation as another reaction in `rxns`, the return the `id`.
Otherwise return `nothing`.
See also: [`is_mass_balanced`](@ref)
"""
function check_duplicate_reaction(crxn::Reaction, rxns::OrderedDict{String,Reaction})
function check_duplicate_reaction(crxn::Reaction, rxns::OrderedDict{String,Reaction}; only_metabolites=true)
for (k, rxn) in rxns
if rxn.id != crxn.id # skip if same ID
reaction_checker = true
for (kk, vv) in rxn.metabolites # get reaction stoich
if get(crxn.metabolites, kk, 0) != vv # if at least one stoich doesn't match
reaction_checker = false
break
if only_metabolites # only check if metabolites are the same
if issetequal(collect(keys(crxn.metabolites)), collect(keys(rxn)))
return k
end
else # also check the stoichiometric coefficients
reaction_checker = true
for (kk, vv) in rxn.metabolites # get reaction stoich
if abs(get(crxn.metabolites, kk, 0)) != abs(vv) # if at least one stoich doesn't match
reaction_checker = false
break
end
end
if reaction_checker # was a match found
return k
end
end
if reaction_checker
return k
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment