I have a model and want to add an entire new pathway to it. Some of the metabolites already exist in the model, others have to be created. I also have to add GPRs to the reactions using genes not yet present in the model.
I found the function addReaction
, but always get an error when I use it:
import cbmpy
cmod = cbmpy.CBRead.readSBML3FBC('model.xml')
cmod.addReaction('R_foo')
AssertionError: ERROR: requires a Reaction object, not something of type
<type 'str'>
Any ideas how I can pass a reaction object and add metabolites and a GPR?
You are looking for
createReaction
. The following will work (I use the model from this question):This will print
So, by default, one adds reversible reactions (see below how to add an irreversible one) and it also tells you how to add reagents.
Let's first assume that you add a reactions for which all reagents are already present in the model. Then you can use
createReactionReagent
to add reagents along with their stoichiometric factor like this:We can check whether the reaction was added correctly:
will return
You can then easily add a GPR to the reaction using
createGeneProteinAssociation
:Again the check whether it worked as intended:
yields:
If the genes are not present in the model, they will be added automatically:
will return
As you want to add an entire pathway, we do the same now for a second reaction with a reagent not yet part of the model:
Let's assume, the metabolite you want to add is called
A
, thenwill fail with
That means that we first have to create it using
createSpecies
:The arguments
name
tillchemFormula
are not required. Now you can callYou can check this question on how to add additional annotation to the species or reactions.
You might then also want to add all reactions belonging to this pathway into a group which makes accessing the reactions very easy later on:
Now you can access the members of this group using
if you are interested in the reaction IDs or
if you are interested in the reaction objects themselves.