Developer documentation¶
CORE¶
Import core modules¶
In order to use findCPcore library you have to import the following core modules.
[2]:
import sys
from findCPcore import MetabolicModel
from findCPcore import CobraMetabolicModel
Read metabolic model¶
Read input metabolic model in Systems Biology Markup Language (SBML) format. SBML is a XML-based standard for systems biology model’s exchange.
Allowed files formats are: * xml * json * yml
[15]:
model = MetabolicModel(CobraMetabolicModel("aureus.xml"))
Get model info¶
The following methods allow to print on the command line data from the model.
Model info¶
[16]:
model.print_model_info()
MODEL INFO
-------------------------------------------------------
MODEL: MODEL1507180070
REACTIONS: 743
METABOLITES: 655
GENES: 619
COMPARTMENTS: c
e
Metabolites¶
[17]:
model.print_metabolites()
MODEL: MODEL1507180070 - NUMBER OF METABOLITES: 655
METABOLITE | COMPARTMENT | REACTION ID
-------------------------------------------------------
10fthf_c | c | AICART
| | FTHFL
| | GARFT
| | MTHFC
| | biomass_SA_7a
| | biomass_SA_8a
| | biomass_SA_7b
12dgr_EC_c | c | biomass_SA_2a
| | biomass_SA_2b
| | biomass_SA_lipids_only
| | biomass_SA_3a
|
Reactions¶
[18]:
model.print_reactions()
MODEL: MODEL1507180070 - NUMBER OF REACTIONS: 743
REACTION ID | UPPER BOUND | LOWER BOUND | REACTION
-------------------------------------------------------
3M2OBLOXRD | 999999.0 | -999999.0 | 3mob_c + h_c + lpam_c <=> 2mpdhl_c + co2_c
3M2OPLOXRD | 999999.0 | -999999.0 | 3mop_c + h_c + lpam_c <=> 2mbdhl_c + co2_c
4M2OPLOXRD | 999999.0 | -999999.0 | 4mop_c + h_c + lpam_c <=> 3mbdhl_c + co2_c
6PGALSZ | 999999.0 | 0.0 | h2o_c + lac6p_c --> dgal6p_c + glc_DASH_D_c
6PHBG | 999999.0 | 0.0 | h2o_c + salc6p_c --> 2hymeph_c + g6p_c
ABTAr | 999999.0 | 0.0 | 4abut_c + akg_c --> glu_DASH_L_c + sucsal_c
ACACT1r | 999999.0
Genes¶
[19]:
model.print_genes()
MODEL: MODEL1507180070 - NUMBER OF GENES: 619
GENE ID | GENE NAME | REACTION ID | GPR RELATION
-------------------------------------------------------
SA0008 | SA0008 | HISDr | SA0008
SA0009 | SA0009 | SERTRS | SA0009
SA0011 | SA0011 | HSERTA | SA0011
SA0016 | SA0016 | ADSS | SA0016
SA0036 | SA0036 | GPDDA5 | SA0036 or SA0820 or SA1542 or SA0969 or SA0220
| | GPDDA4 | SA0036 or SA0820 or SA1542 or SA0969 or SA0220
| | GPDDA3 | SA0036 or SA0820 or SA1542 or SA0969 or SA0220
|
Dead-end metabolites¶
Dead-end metabolites are those metabolites which are not consumed or not produced by any reaction of a given compartment of the model including exchange reactions.
Finding Dead-end metabolites¶
find_dem()
. The method dem()
returns a python dict with the following content:[20]:
model.find_dem()
model.dem()
[20]:
{'c': [<Metabolite clpn_EC_c at 0x7f9ed3818050>,
<Metabolite dgdcg_SA_c at 0x7f9ed379c0d0>,
<Metabolite drib_c at 0x7f9ed3692150>,
<Metabolite octdp_c at 0x7f9ed3a0e150>,
<Metabolite DGDG_SA_c at 0x7f9ed373a1d0>,
<Metabolite udcp_c at 0x7f9ed3888590>,
<Metabolite octp_c at 0x7f9ed3a0e650>,
<Metabolite fdxox_c at 0x7f9ed37886d0>,
<Metabolite 2a3pp_c at 0x7f9ed37c26d0>,
<Metabolite plys_SA_c at 0x7f9ed37966d0>,
<Metabolite uppg1_c at 0x7f9ed3888810>,
<Metabolite pleu_SA_c at 0x7f9ed3796850>,
<Metabolite adprib_c at 0x7f9ed382c890>,
<Metabolite Sptmyn_c at 0x7f9ed373a990>,
<Metabolite sucr_c at 0x7f9ed37909d0>,
<Metabolite Stmyn_c at 0x7f9ed373a9d0>,
<Metabolite
Dead-end metabolites can be printed on the command line with print_dem()
method.
[21]:
model.print_dem()
MODEL: MODEL1507180070 - NUMBER OF DEM: 2 - COMPARTMENT: ALL
METABOLITE | COMPARTMENT | REACTION ID
-------------------------------------------------------
clpn_EC_c | c | biomass_SA_2a
| | biomass_SA_2b
| | biomass_SA_lipids_only
| | biomass_SA_3a
| | biomass_SA_3b
dgdcg_SA_c | c | biomass_SA_3a
| | biomass_SA_3b
drib_c | c | DRBK
octdp_c | c | DHNAOT
DGDG_SA_c | c | biomass_SA_2a
| | biomass_SA_li
Dead-end metabolites printed can be limited to a specific compartment. Avaible compartments are given by model.compartments()
method.
[22]:
model.print_dem(compartment="e")
MODEL: MODEL1507180070 - NUMBER OF DEM: 2 - COMPARTMENT: e
METABOLITE | COMPARTMENT | REACTION ID
-------------------------------------------------------
acnam_e | e | ACNAMt2
| | EX_acnam_e
gua_e | e | EX_gua_e
| | GUAt2
Cit_DASH_Mg_e | e | CIT_Mgt
| | EX_Cit_DASH_Mg_e
zn2_e | e | EX_zn2_e
| | ZNabc
gly_e | e | EX_gly_e
| | GLYabc
crn_e | e | CRNabc
| | EX_crn_e
cys_
Removing dead-end metabolites¶
Method remove_dem()
removes dead-end metabolites from the model. Once dead-end metabolites are deleted, some reactions might not produce a metabolite anymore so the method deletes also these reactions and loops again until no dead-end metabolite is found:
while number of metabolites doesnt change:
delete all dead-end metabolites
for reaction that produced or consumed dead-end metabolites:
if reaction produces or consumes 0 metabolites [and is not exchange nor demand]:
delete reaction
find dead-end metabolites
The reactions that are deleted on the method can be modified by the following params:
delete_exchange :
<li> **True** : all the reactions that are produce or consume 0 metabolites are deleted whether they are exchange/demand or not. </li> <li> **False** : (default) deleted according to 'keep_all_incomplete_reactions' param. </li> </ul>
keep_all_incomplete_reactions :
<li> **False**: if a reactions is a [cobra boundary reaction](https://cobrapy.readthedocs.io/en/latest/media.html#Boundary-reactions) (calculated by heuristics) that reaction can't be deleted. </li> <li> **True**: (default) if a reaction initially doesn't produce or consume any metabolite that reaction can't be deleted. </li> </ul>
[23]:
print("Metabolites: ", len(model.metabolites()), "\nReactions: ", len(model.reactions()))
Metabolites: 655
Reactions: 743
[24]:
model.remove_dem()
[25]:
print("Metabolites: ", len(model.metabolites()), "\nReactions: ", len(model.reactions()))
Metabolites: 486
Reactions: 739
Dead reactions¶
Dead reactions are those reactions with upper and lower flux equal to zero.
Finding Dead reactions¶
Dead reactions of the model are calculated with the method dead_reactions()
, which returns a list of cobra.core.reactions with dead reactions.
[27]:
model.dead_reactions()
[27]:
[<Reaction SA_biomass_1a at 0x7f9ed2ed7d50>,
<Reaction biomass_SA_2a at 0x7f9ed2e31910>,
<Reaction biomass_SA_2b at 0x7f9ed2e31310>,
<Reaction biomass_SA_3a at 0x7f9ed2e31a90>,
<Reaction biomass_SA_3b at 0x7f9ed2e31e90>,
<Reaction biomass_SA_4a at 0x7f9ed2e3c150>,
<Reaction biomass_SA_5a at 0x7f9ed2e3c050>,
<Reaction biomass_SA_6a at 0x7f9ed2e3cfd0>,
<Reaction biomass_SA_6b at 0x7f9ed2dd3650>,
<Reaction biomass_SA_7a at 0x7f9ed2de2f90>,
<Reaction biomass_SA_7b at 0x7f9ed2dd3f90>,
<Reaction biomass_SA_lipids_only at 0x7f9ed2dd3fd0>,
<Reaction biomass_SA_nuc_only at 0x7f9ed2e31950>,
<Reaction biomass_SA_only_AA at 0x7f9ed2e31c90>]
Chokepoint reactions¶
Chokepoint reactions are those reactions that are the only consumer or producer of a given metabolite that isn’t a dead-end metabolite.
Finding chokepoint reactions¶
Chokepoint reactions are calculated with the method find_chokepoints()
. The method chokepoints()
returns a list of tuples of types (cobra.core.reactions, cobra.core.metabolites) representing a chokepoint reactions object and the metabolite it only produces/consumes.
[28]:
# Read initial model again
model = MetabolicModel(CobraMetabolicModel("aureus.xml"))
model.find_chokepoints()
model.chokepoints()
[28]:
[(<Reaction PAPA_SA at 0x7f9ed31df450>,
<Metabolite 12dgr_SA_c at 0x7f9ed38b1d50>),
(<Reaction PROD2 at 0x7f9ed32eb750>, <Metabolite 1pyr5c_c at 0x7f9ed38b1a90>),
(<Reaction DHDPRy at 0x7f9ed3a4a9d0>,
<Metabolite 23dhdp_c at 0x7f9ed312e690>),
(<Reaction DHDPS at 0x7f9ed3a44350>, <Metabolite 23dhdp_c at 0x7f9ed312e690>),
(<Reaction DHAD1 at 0x7f9ed3a54550>, <Metabolite 23dhmb_c at 0x7f9ed312e190>),
(<Reaction KARA1i at 0x7f9ed31f9310>,
<Metabolite 23dhmb_c at 0x7f9ed312e190>),
(<Reaction DHAD2 at 0x7f9ed3a4aa50>, <Metabolite 23dhmp_c at 0x7f9ed312edd0>),
(<Reaction KARA2i at 0x7f9ed31f9690>,
<Metabolite 23dhmp_c at 0x7f9ed312edd0>),
(<Reaction DHPPDA at 0x7f9ed3ab3450>,
<Met
Dead reactions can be excluded from the computation of chokepoints with the exclude_dead_reactions=True
parameter.
[31]:
model.find_chokepoints(exclude_dead_reactions=True)
model.chokepoints()
[31]:
[(<Reaction PAPA_SA at 0x7f9ed31df450>,
<Metabolite 12dgr_SA_c at 0x7f9ed38b1d50>),
(<Reaction PROD2 at 0x7f9ed32eb750>, <Metabolite 1pyr5c_c at 0x7f9ed38b1a90>),
(<Reaction DHDPRy at 0x7f9ed3a4a9d0>,
<Metabolite 23dhdp_c at 0x7f9ed312e690>),
(<Reaction DHDPS at 0x7f9ed3a44350>, <Metabolite 23dhdp_c at 0x7f9ed312e690>),
(<Reaction DHAD1 at 0x7f9ed3a54550>, <Metabolite 23dhmb_c at 0x7f9ed312e190>),
(<Reaction KARA1i at 0x7f9ed31f9310>,
<Metabolite 23dhmb_c at 0x7f9ed312e190>),
(<Reaction DHAD2 at 0x7f9ed3a4aa50>, <Metabolite 23dhmp_c at 0x7f9ed312edd0>),
(<Reaction KARA2i at 0x7f9ed31f9690>,
<Metabolite 23dhmp_c at 0x7f9ed312edd0>),
(<Reaction DHPPDA at 0x7f9ed3ab3450>,
<Met
Chokepoint reactions can also be printed on the command line with print_chokepoints
.
[14]:
model.print_chokepoints()
MODEL: MODEL1507180070 - NUMBER OF CHOKEPOINTS: 439
METABOLITE ID | METABOLITE NAME | REACTION ID | REACTION NAME
------------------------------------------------------------
12dgr_SA_c | 1,2-Daicylglycerol (Saureus) | PAPA_SA | Phosphatidate phosphatase
1pyr5c_c | 1-Pyrroline-5-carboxylate | PROD2 | Proline dehydrogenase
23dhdp_c | 2,3-Dihydrodipicolinate | DHDPRy | dihydrodipicolinate reductase (NADPH)
23dhdp_c | 2,3-Dihydrodipicolinate | DHDPS | dihydrodipicolinate synthase
23dhmb_c | (R)-2,3-Dihydroxy-3-methylbutanoate | DHAD1 |
Flux Balance Analysis¶
Flux Balance Analysis (FBA) is a mathematical procedure used to calculate the growth rate of a metabolic model considering a objective function to maximize and the reactions flux as constraints.
The method get_growth()
calculates the objective value (growth rate) that maximizes the objective function. This method uses cobra.core.model.slim_optimize and was obtained from cobra.flux_analysis.deletion.
The objective value obtained with FBA can be accesed with objective_value()
.
[15]:
model.get_growth()
model.objective_value()
[15]:
0.1580502916027849
The objective function that is maximized during FBA can be accesed by objective()
[16]:
model.objective()
[16]:
'1.0*biomass_SA_8a - 1.0*biomass_SA_8a_reverse_4ce77'
This objective function can be changed by another reaction of the model with set_objective()
. This method receives the id of the reaction that will be set as the new objective value.
[17]:
model.set_objective("DHAD1")
model.objective()
[17]:
'1.0*DHAD1 - 1.0*DHAD1_reverse_39dca'
Flux Variability Analysis¶
Flux Vatiability Analysis (FVA) is a mathematical procedure used to calculate the ‘’minimum and maximum flux for reactions in the network while maintaining some state of the network, e.g., supporting 90% of maximal possible biomass production rate’’.
fva()
runs Flux Variability Analysis on the model. This method runs cobra.flux_analysis.variability and as so it allows the same parameters (see the previous link):Method fva()
returns an error list if there was an error while running FVA or an empty list []
otherwise.
[18]:
model.fva(threshold=0.95)
[18]:
[]
[19]:
model.fva(threshold=0.95, verbose=True)
FLUX VARIABILITY ANALYSIS: MODEL1507180070
REACTION: 3-Methyl-2-oxobutanoate:lipoamide oxidoreductase(decarboxylating and acceptor-2-methylpropanoylating)
fva ranges: [ 0.0 , 0.0 ]
REACTION: 3-Methyl-2-oxopentanoate:lipoamide oxidoreductase(decarboxylating and acceptor-2-methylpropanoylating)
fva ranges: [ 0.0 , 0.0 ]
REACTION: 4-Methyl-2-oxopentanoate:lipoamide oxidoreductase(decarboxylating and acceptor-2-methylpropanoylating)
fva ranges: [ 0.0 , 0.0 ]
REACTION: 6-phospho-beta-galactosidase
fva ranges: [ 0.0 , 0.0 ]
REACTION: 6-phospho-beta-glucosidase
fva ranges: [ 0.0 , 0.0 ]
RE
The result obtained with FVA can be accesed with get_fva()
. This method returns a list of tuples: (cobra.core.reaction, [float] maximum flux, [float] minimum flux)
[20]:
model.get_fva()
[20]:
[(<Reaction 3M2OBLOXRD at 0x7f79b4e53c90>, 0.0, 0.0),
(<Reaction 3M2OPLOXRD at 0x7f79b4e53c50>, 0.0, 0.0),
(<Reaction 4M2OPLOXRD at 0x7f79b4e53b10>, 0.0, 0.0),
(<Reaction 6PGALSZ at 0x7f79b4e53ed0>, 0.0, 0.0),
(<Reaction 6PHBG at 0x7f79b4e53a90>, 0.0, 0.0),
(<Reaction ABTAr at 0x7f79b4e4bc50>, 0.0, 0.0),
(<Reaction ACACT1r at 0x7f79b4e4b110>,
0.00032511320071648854,
-2065.6249999999704),
(<Reaction ACACT2r at 0x7f79b4e43950>, 0.0, -2065.624999999973),
(<Reaction ACACT3r at 0x7f79b4e4bad0>, 0.0, -2065.624999999973),
(<Reaction ACACT4r at 0x7f79b4e53210>, 0.0, -2065.624999999973),
(<Reaction ACACT5r at 0x7f79b4e4bc90>, 0.0, -2065.624999999973),
(<Reaction ACACT6r at 0x7f79b4e439
Updating reaction’s flux with FVA¶
findCritical adds an extra parameter to this method which is update_flux
. If True
the method fva()
updates the model reaction’s flux with the maximum and minimum flux values obtained with FVA (see the example below).
[21]:
# Print initial reactions of the model with initial flux values.
model.print_reactions()
MODEL: MODEL1507180070 - NUMBER OF REACTIONS: 743
REACTION ID | UPPER BOUND | LOWER BOUND | REACTION
-------------------------------------------------------
3M2OBLOXRD | 999999.0 | -999999.0 | 3mob_c + h_c + lpam_c <=> 2mpdhl_c + co2_c
3M2OPLOXRD | 999999.0 | -999999.0 | 3mop_c + h_c + lpam_c <=> 2mbdhl_c + co2_c
4M2OPLOXRD | 999999.0 | -999999.0 | 4mop_c + h_c + lpam_c <=> 3mbdhl_c + co2_c
6PGALSZ | 999999.0 | 0.0 | h2o_c + lac6p_c --> dgal6p_c + glc_DASH_D_c
6PHBG | 999999.0 | 0.0 | h2o_c + salc6p_c --> 2hymeph_c + g6p_c
ABTAr | 999999.0 | 0.0 | 4abut_c + akg_c --> glu_DASH_L_c + sucsal_c
ACACT1r | 999999.0
[22]:
# Update reactions flux values with FVA
model.fva(update_flux=True)
[22]:
[]
[23]:
# Print reactions of the model with refined reactions flux values.
model.print_reactions()
MODEL: MODEL1507180070 - NUMBER OF REACTIONS: 743
REACTION ID | UPPER BOUND | LOWER BOUND | REACTION
-------------------------------------------------------
3M2OBLOXRD | 0.0 | 0.0 | 3mob_c + h_c + lpam_c --> 2mpdhl_c + co2_c
3M2OPLOXRD | 0.0 | 0.0 | 3mop_c + h_c + lpam_c --> 2mbdhl_c + co2_c
4M2OPLOXRD | 0.0 | 0.0 | 4mop_c + h_c + lpam_c --> 3mbdhl_c + co2_c
6PGALSZ | 0.0 | 0.0 | h2o_c + lac6p_c --> dgal6p_c + glc_DASH_D_c
6PHBG | 0.0 | 0.0 | h2o_c + salc6p_c --> 2hymeph_c + g6p_c
ABTAr | 0.0 | 0.0 | 4abut_c + akg_c --> glu_DASH_L_c + sucsal_c
ACACT1r | -3.26642
Essential genes¶
Essential genes are those genes that cause a zero growth rate when knocked out.
Finding essential genes¶
Essential genes are calculated with the method find_essential_genes_1()
. This method returns an error list if there was an error during the computing or an empty list []
otherwise.
[33]:
model.find_essential_genes_1()
[33]:
[]
If essential genes were computed with the method above, they can be accesed with essential_genes()
. This method return a list of cobra.core.gene with essential genes.
[35]:
model.essential_genes()
[35]:
{<Gene SA0016 at 0x7f9ed3143e50>,
<Gene SA0134 at 0x7f9ed3110b90>,
<Gene SA0176 at 0x7f9ed31a95d0>,
<Gene SA0177 at 0x7f9ed31a9390>,
<Gene SA0178 at 0x7f9ed31a4810>,
<Gene SA0179 at 0x7f9ed31a4f10>,
<Gene SA0244 at 0x7f9ed3198990>,
<Gene SA0344 at 0x7f9ed31901d0>,
<Gene SA0345 at 0x7f9ed3190b10>,
<Gene SA0346 at 0x7f9ed3190ad0>,
<Gene SA0347 at 0x7f9ed3190d90>,
<Gene SA0375 at 0x7f9ed3190350>,
<Gene SA0376 at 0x7f9ed318f610>,
<Gene SA0419 at 0x7f9ed3190490>,
<Gene SA0439 at 0x7f9ed3190b90>,
<Gene SA0457 at 0x7f9ed31922d0>,
<Gene SA0458 at 0x7f9ed3192490>,
<Gene SA0472 at 0x7f9ed3192910>,
<Gene SA0473 at 0x7f9ed3192ad0>,
<Gene SA0474 at 0x7f9ed3192b50>,
<Gene SA0486 at 0x7
Essential reactions¶
Essential reactions are those genes that cause a zero growth rate when knocked out.
Finding essential reactions¶
Essential reactions are calculated with the method find_essential_reactions_1()
. This method returns an error list if there was an error during the computing or an empty list []
otherwise.
[36]:
model.find_essential_reactions_1()
If essential genes were computed with the method above, they can be accesed with essential_reactions()
. This method return a dict
with keys cobra.core.reaction with all the reactions of the model, and values float
with the result of computing FBA with the reaction knocked-out.
[37]:
model.essential_reactions()
[37]:
{<Reaction SBTD_Dr at 0x7f9ed356ee50>: 0.1580502916027849,
<Reaction ARGSL at 0x7f9ed3667b10>: 0.1580502916027849,
<Reaction CIT_Mgt at 0x7f9ed38b7210>: 0.1580502916027849,
<Reaction METabc at 0x7f9ed31eea90>: 0.1580502916027849,
<Reaction GLGC at 0x7f9ed318ba50>: 0.1580502916027849,
<Reaction EX_gly_e at 0x7f9ed3af4ed0>: 0.1580502916027849,
<Reaction HISDr at 0x7f9ed31fef90>: 0.1580502916027849,
<Reaction EX_acnam_e at 0x7f9ed3a80cd0>: 0.1580502916027849,
<Reaction PTHPS at 0x7f9ed32d1990>: 0.1580502916027849,
<Reaction biomass_SA_2b at 0x7f9ed3402110>: 0.1580502916027849,
<Reaction NADH5 at 0x7f9ed31e9410>: 0.1580502916027849,
<Reaction CBPS at 0x7f9ed37f8f50>: 0.158050291602784
Essential genes reactions¶
Essential genes reactions are those reactions that are knocked-out when an essential gene is knocked-out.
Finding essential genes reactions¶
Essential genes reactions are calculated with the method find_essential_genes_reactions()
. This method returns an error list if there was an error during the computing or an empty list []
otherwise.
[38]:
model.find_essential_genes_reactions()
[38]:
[]
If essential genes reactions were computed with the method above, they can be accesed with essential_genes_reactions()
. This method returns a dict
with keys cobra.core.reaction with all the reactions of the model, and values a list
of cobra.core.genes with the essential genes that cause the knock-out of the reaction.
[39]:
model.essential_genes_reactions()
[39]:
{<Reaction ANPRT at 0x7f9ed3602f10>: [<Gene SA1201 at 0x7f9ed316c050>],
<Reaction SHK3Dr at 0x7f9ed3570f10>: [<Gene SA1424 at 0x7f9ed3a0a050>],
<Reaction SUCD4 at 0x7f9ed3313c50>: [<Gene SA0994 at 0x7f9ed3156050>,
<Gene SA0995 at 0x7f9ed3156210>,
<Gene SA0996 at 0x7f9ed3156450>],
<Reaction SUCD1 at 0x7f9ed3313fd0>: [<Gene SA0994 at 0x7f9ed3156050>,
<Gene SA0995 at 0x7f9ed3156210>,
<Gene SA0996 at 0x7f9ed3156450>],
<Reaction PPBNGS at 0x7f9ed32aadd0>: [<Gene SA1492 at 0x7f9ed3a0e050>],
<Reaction CYTBD at 0x7f9ed38c0ad0>: [<Gene SA0938 at 0x7f9ed314c090>,
<Gene SA0910 at 0x7f9ed31ba8d0>,
<Gene SA0912 at 0x7f9ed31bac10>,
<Gene SA0937 at 0x7f9ed3148e50>,
<Gene SA0911 at 0x7f