Adding metabolites to a reaction using a dictionary

30 views
Skip to first unread message

Kristy Chang

unread,
Jun 1, 2022, 9:18:38 PM6/1/22
to cobra pie
Hi, 

I am stuck at this problem:
I have my reaction equation as a dictionary:
reaction= {'glu__L_c': -1.0, 'h2o_c': -1.0, 'nadp_c': -1.0, 'akg_c': 1.0, 'h_c': 1.0, 'nadph_c': 1.0, 'nh4_c': 1.0}
but when I do:
reaction.add_metabolite(reaction)
it gives a blank result and the following error:
TypeError: 'dict' object is not callable
or TypeError: Either add the reaction to a model or use Metabolite objects instead of strings as keys

How do I use metabolite objects as keys? (or rather, how do I convert my keys into objects?)

Dennis van den Berg

unread,
Jun 7, 2022, 7:05:38 AM6/7/22
to Kristy Chang, cobra pie
Hi Kristy,

To convert your keys to objects you can simple use {model.metabolites.glu__L_c:-1.0, model.metabolites.h2o_c:-1.0, etc, ect.}
Then you refer to the objects in your model, if you called it model at least. If you called it ecoli then use ecoli.metabolites.glu__L_c .
One warning: If your metabolite has a name which is illegal according to python use .get_by_id("string with name"), f.i. objects can not start with a number, so 4abz_c is not a valid name.
Then you do: model.metabolites.get_by_id('4abz_c'):-1.0 and it will work fine.

Good luck with your modeling,

Dennis

--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-pie+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-pie/95f22028-d28c-42fa-85d4-a887770d3a0en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages