{ "cells": [ { "cell_type": "markdown", "id": "c44a1f04-a698-4656-81c1-318fecdef9fe", "metadata": {}, "source": [ "# PyCoMo CycleBreaker #\n", "This tutorial show-cases the use of CycleBreaker. Here, efmtool is used to enumerate all WONCY cycles (witout net conversion cycles), and then binary variables are used to forbid all reactions of a cycle being active at the same time - in turn breaking the cycle.\n", "\n", "The expected runtime for this notebook is less than 10 minutes." ] }, { "cell_type": "code", "execution_count": 1, "id": "4f268ff5-696e-4ce9-8ddc-5ba0feb4d39b", "metadata": {}, "outputs": [], "source": [ "import cobra" ] }, { "cell_type": "code", "execution_count": 2, "id": "84fa22a6-a759-4cd0-a27a-113c439a2506", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:31:31,852 - PyCoMo - INFO - Logger initialized.\n" ] } ], "source": [ "import pycomo\n", "pycomo.configure_logger(level=\"info\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "43a784e5-f89a-49fc-be5f-4060b678f311", "metadata": {}, "outputs": [], "source": [ "conf = cobra.Configuration()\n", "conf.solver = \"gurobi\"\n", "conf.processes = 8" ] }, { "cell_type": "markdown", "id": "4715de63-bee8-475e-a5c3-db5df3dac769", "metadata": {}, "source": [ "## Model import ##\n", "We are using two genome-scale models of the AGORA2 collection:\n", " - Bacteroides stercoris ERR2230062\n", " - Blautia torques ERR1022325" ] }, { "cell_type": "code", "execution_count": 4, "id": "09986d36-d2c2-4994-87dc-26080afa6304", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "No defined compartments in model model. Compartments will be deduced heuristically using regular expressions.\n", "Using regular expression found the following compartments:c, e, p\n", "No defined compartments in model model. Compartments will be deduced heuristically using regular expressions.\n", "Using regular expression found the following compartments:c, e\n" ] } ], "source": [ "test_model_dir = \"../data/use_case/cyclebreaker\"\n", "named_models = pycomo.load_named_models_from_dir(test_model_dir, file_format=\"mat\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "e62c9975-8ac8-479f-a2c5-dc842549c602", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Bacteroides_stercoris_ERR2230062': ,\n", " 'Blautia_torques_ERR1022325': }" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "named_models" ] }, { "cell_type": "code", "execution_count": 6, "id": "ac6b689d-e9c7-4b64-b660-cf50c8be0461", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bacteroides_stercoris_ERR2230062\n", "Read LP format model from file /tmp/tmp2p6n4a2_.lp\n", "Reading time = 0.01 seconds\n", ": 1174 rows, 2510 columns, 10030 nonzeros\n", "Blautia_torques_ERR1022325\n", "Read LP format model from file /tmp/tmp9f2lyns4.lp\n", "Reading time = 0.01 seconds\n", ": 1034 rows, 2358 columns, 10044 nonzeros\n" ] } ], "source": [ "single_org_models = []\n", "for name, model in named_models.items():\n", " print(name)\n", " single_org_model = pycomo.SingleOrganismModel(model, name)\n", " single_org_models.append(single_org_model)" ] }, { "cell_type": "code", "execution_count": 7, "id": "d7f78cab-cd42-4dff-b022-d04bb6471d3a", "metadata": {}, "outputs": [], "source": [ "community_name = \"cyclebreaker_test\"\n", "com_model_obj = pycomo.CommunityModel(single_org_models, community_name)" ] }, { "cell_type": "code", "execution_count": 8, "id": "12d17b62-d146-4888-bf32-ed973f428cdf", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:31:39,148 - PyCoMo - INFO - No community model generated yet. Generating now:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Read LP format model from file /tmp/tmpm8nnnw4k.lp\n", "Reading time = 0.01 seconds\n", ": 1174 rows, 2510 columns, 10030 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:31:41,165 - PyCoMo - INFO - Identified biomass reaction from objective: bio1\n", "2026-03-15 13:31:41,166 - PyCoMo - INFO - Note: no products in the objective function, adding biomass to it.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Read LP format model from file /tmp/tmp0w0qe80u.lp\n", "Reading time = 0.01 seconds\n", ": 1034 rows, 2358 columns, 10044 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:31:59,241 - PyCoMo - INFO - Identified biomass reaction from objective: bio1\n", "2026-03-15 13:31:59,242 - PyCoMo - INFO - Note: no products in the objective function, adding biomass to it.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Read LP format model from file /tmp/tmpwwgf8mec.lp\n", "Reading time = 0.03 seconds\n", ": 2829 rows, 5946 columns, 20512 nonzeros\n", "Read LP format model from file /tmp/tmps2dub8ux.lp\n", "Reading time = 0.06 seconds\n", ": 5927 rows, 12308 columns, 42154 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:32:27,862 - PyCoMo - WARNING - Not all reactions in the model are mass and charge balanced. To check which reactions are imbalanced, please run the get_unbalanced_reactions method of this CommunityModel object\n", "2026-03-15 13:32:27,863 - PyCoMo - INFO - Generated community model.\n" ] }, { "data": { "text/html": [ "

Objective

1.0 community_biomass = 1.0

Uptake

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MetaboliteReactionFluxC-NumberC-Flux
_26dap_M_mediumEX__26dap_M_medium0.0250170.16%
ade_mediumEX_ade_medium0.147650.69%
ala_D_mediumEX_ala_D_medium0.131330.37%
ala_L_mediumEX_ala_L_medium0.32230.91%
arg_L_mediumEX_arg_L_medium0.246761.39%
asn_L_mediumEX_asn_L_medium0.200840.75%
asp_L_mediumEX_asp_L_medium0.360841.36%
ca2_mediumEX_ca2_medium0.00309600.00%
cgly_mediumEX_cgly_medium0.00309650.01%
cl_mediumEX_cl_medium0.00309600.00%
cobalt2_mediumEX_cobalt2_medium0.00309600.00%
csn_mediumEX_csn_medium0.20740.78%
cu2_mediumEX_cu2_medium0.00309600.00%
cys_L_mediumEX_cys_L_medium0.0823430.23%
fe2_mediumEX_fe2_medium0.00619300.00%
fe3_mediumEX_fe3_medium0.00309600.00%
fol_mediumEX_fol_medium0.00929190.17%
gln_L_mediumEX_gln_L_medium0.222251.04%
glu_L_mediumEX_glu_L_medium0.268951.26%
glyleu_mediumEX_glyleu_medium0.460683.46%
gncore2_mediumEX_gncore2_medium0.0587301.65%
gua_mediumEX_gua_medium0.148650.70%
his_L_mediumEX_his_L_medium0.0792660.45%
ile_L_mediumEX_ile_L_medium0.32761.84%
k_mediumEX_k_medium0.00309600.00%
lys_L_mediumEX_lys_L_medium0.285461.61%
metala_mediumEX_metala_medium0.130980.98%
mg2_mediumEX_mg2_medium0.00309600.00%
mn2_mediumEX_mn2_medium0.00309600.00%
mqn7_mediumEX_mqn7_medium0.003096460.13%
mqn8_mediumEX_mqn8_medium0.003096510.15%
nac_mediumEX_nac_medium0.00619360.03%
o2_mediumEX_o2_medium10.0900.00%
ocdca_mediumEX_ocdca_medium0.08518181.44%
phe_L_mediumEX_phe_L_medium0.154591.31%
pheme_mediumEX_pheme_medium0.003096340.10%
pi_mediumEX_pi_medium1.01800.00%
pnto_R_mediumEX_pnto_R_medium0.00619390.05%
pro_L_mediumEX_pro_L_medium0.184450.87%
ptrc_mediumEX_ptrc_medium0.00309640.01%
ribflv_mediumEX_ribflv_medium0.006193170.10%
ser_L_mediumEX_ser_L_medium0.260730.73%
so4_mediumEX_so4_medium0.00309600.00%
spmd_mediumEX_spmd_medium0.00309670.02%
stys_mediumEX_stys_medium0.04594241.04%
sucr_mediumEX_sucr_medium6.3751271.86%
thm_mediumEX_thm_medium0.003097120.03%
thr_L_mediumEX_thr_L_medium0.211140.79%
trp_L_mediumEX_trp_L_medium0.0472110.49%
tyr_L_mediumEX_tyr_L_medium0.120791.02%
zn2_mediumEX_zn2_medium0.00309600.00%

Secretion

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MetaboliteReactionFluxC-NumberC-Flux
Blautia_torques_ERR1022325_biomass_Blautia_torques_ERR1022325_cBlautia_torques_ERR1022325_EX_biomass_e_Blautia_torques_ERR1022325_c-100.00%
T_antigen_mediumEX_T_antigen_medium-0.0587141.19%
ac_mediumEX_ac_medium-22.08263.90%
co2_mediumEX_co2_medium-1.02411.48%
for_mediumEX_for_medium-23.11133.43%
h2o_mediumEX_h2o_medium-1.08900.00%
h_mediumEX_h_medium-43.6100.00%
nh4_mediumEX_nh4_medium-0.0940200.00%
cpd11416_mediumcommunity_biomass-100.00%
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "com_model_obj.summary()" ] }, { "cell_type": "markdown", "id": "f56a447f-fc4a-4dbd-959f-65593fdd9a7a", "metadata": {}, "source": [ "## Cycle enumeration ##" ] }, { "cell_type": "code", "execution_count": 9, "id": "950b2311-ce78-48f1-961b-ff775abd3245", "metadata": {}, "outputs": [], "source": [ "cycles = pycomo.helper.cyclebreaker.enumerate_cycles_in_com_model(com_model_obj)" ] }, { "cell_type": "markdown", "id": "b6a0b1f8-a005-4bd6-a5d1-ea1b134a1157", "metadata": {}, "source": [ "## CycleBreaker ##" ] }, { "cell_type": "markdown", "id": "6809eba7-f95a-495d-8642-97ba8fa48d17", "metadata": {}, "source": [ "### Test flux without medium ###\n", "Check how many external reactions can carry flux without a medium present. These reactionse are part of a cycle." ] }, { "cell_type": "code", "execution_count": 10, "id": "7baed45f-67df-4ac0-8d26-c99bf2859aad", "metadata": {}, "outputs": [], "source": [ "com_model_obj.medium = {}" ] }, { "cell_type": "code", "execution_count": 11, "id": "5733b414-2b03-419b-a9d3-919bf751742f", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:36,635 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpiy9cqh6s.lp\n", "Reading time = 0.06 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:39,428 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpg6fq4jdx.lp\n", "Reading time = 0.07 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:42,196 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp9wj5v4ut.lp\n", "Reading time = 0.06 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:44,613 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp0q0k7log.lp\n", "Reading time = 0.06 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:47,450 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmplyu86s_s.lp\n", "Reading time = 0.07 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:50,041 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpenjlf0do.lp\n", "Reading time = 0.06 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:52,938 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp3sz51bpl.lp\n", "Reading time = 0.06 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:33:56,294 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpdyqilvrf.lp\n", "Reading time = 0.07 seconds\n", ": 5928 rows, 12309 columns, 42153 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:02,169 - PyCoMo - INFO - Processed 20.75% of fva steps\n", "2026-03-15 13:34:05,838 - PyCoMo - INFO - Processed 41.49% of fva steps\n", "2026-03-15 13:34:09,342 - PyCoMo - INFO - Processed 62.24% of fva steps\n", "2026-03-15 13:34:12,723 - PyCoMo - INFO - Processed 82.99% of fva steps\n", "2026-03-15 13:34:15,344 - PyCoMo - INFO - Processed 100.0% of fva steps\n" ] } ], "source": [ "fva_no_medium = com_model_obj.run_fva(fva_mu_c=0) # FVA on all external reactions" ] }, { "cell_type": "markdown", "id": "c7a420bb-d383-4dd0-ae22-08d5b14fcce6", "metadata": {}, "source": [ "Check how many reactions can carry flux (i.e. are not 0)" ] }, { "cell_type": "code", "execution_count": 12, "id": "d16befdd-38ed-47f2-a4e9-3a5d5ad8884b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
reaction_idmin_fluxmax_flux
Bacteroides_stercoris_ERR2230062_TF_gln_L_Bacteroides_stercoris_ERR2230062_eBacteroides_stercoris_ERR2230062_TF_gln_L_Bact...-500.0500.0
Bacteroides_stercoris_ERR2230062_TF_glu_L_Bacteroides_stercoris_ERR2230062_eBacteroides_stercoris_ERR2230062_TF_glu_L_Bact...-500.0500.0
Bacteroides_stercoris_ERR2230062_TF_h2o_Bacteroides_stercoris_ERR2230062_eBacteroides_stercoris_ERR2230062_TF_h2o_Bacter...-500.0500.0
Bacteroides_stercoris_ERR2230062_TF_nh4_Bacteroides_stercoris_ERR2230062_eBacteroides_stercoris_ERR2230062_TF_nh4_Bacter...-500.0500.0
Blautia_torques_ERR1022325_TF_gln_L_Blautia_torques_ERR1022325_eBlautia_torques_ERR1022325_TF_gln_L_Blautia_to...-500.0500.0
Blautia_torques_ERR1022325_TF_glu_L_Blautia_torques_ERR1022325_eBlautia_torques_ERR1022325_TF_glu_L_Blautia_to...-500.0500.0
Blautia_torques_ERR1022325_TF_h2o_Blautia_torques_ERR1022325_eBlautia_torques_ERR1022325_TF_h2o_Blautia_torq...-500.0500.0
Blautia_torques_ERR1022325_TF_nh4_Blautia_torques_ERR1022325_eBlautia_torques_ERR1022325_TF_nh4_Blautia_torq...-500.0500.0
\n", "
" ], "text/plain": [ " reaction_id \\\n", "Bacteroides_stercoris_ERR2230062_TF_gln_L_Bacte... Bacteroides_stercoris_ERR2230062_TF_gln_L_Bact... \n", "Bacteroides_stercoris_ERR2230062_TF_glu_L_Bacte... Bacteroides_stercoris_ERR2230062_TF_glu_L_Bact... \n", "Bacteroides_stercoris_ERR2230062_TF_h2o_Bactero... Bacteroides_stercoris_ERR2230062_TF_h2o_Bacter... \n", "Bacteroides_stercoris_ERR2230062_TF_nh4_Bactero... Bacteroides_stercoris_ERR2230062_TF_nh4_Bacter... \n", "Blautia_torques_ERR1022325_TF_gln_L_Blautia_tor... Blautia_torques_ERR1022325_TF_gln_L_Blautia_to... \n", "Blautia_torques_ERR1022325_TF_glu_L_Blautia_tor... Blautia_torques_ERR1022325_TF_glu_L_Blautia_to... \n", "Blautia_torques_ERR1022325_TF_h2o_Blautia_torqu... Blautia_torques_ERR1022325_TF_h2o_Blautia_torq... \n", "Blautia_torques_ERR1022325_TF_nh4_Blautia_torqu... Blautia_torques_ERR1022325_TF_nh4_Blautia_torq... \n", "\n", " min_flux max_flux \n", "Bacteroides_stercoris_ERR2230062_TF_gln_L_Bacte... -500.0 500.0 \n", "Bacteroides_stercoris_ERR2230062_TF_glu_L_Bacte... -500.0 500.0 \n", "Bacteroides_stercoris_ERR2230062_TF_h2o_Bactero... -500.0 500.0 \n", "Bacteroides_stercoris_ERR2230062_TF_nh4_Bactero... -500.0 500.0 \n", "Blautia_torques_ERR1022325_TF_gln_L_Blautia_tor... -500.0 500.0 \n", "Blautia_torques_ERR1022325_TF_glu_L_Blautia_tor... -500.0 500.0 \n", "Blautia_torques_ERR1022325_TF_h2o_Blautia_torqu... -500.0 500.0 \n", "Blautia_torques_ERR1022325_TF_nh4_Blautia_torqu... -500.0 500.0 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fva_no_medium[(\n", " ~fva_no_medium[\"min_flux\"].apply(pycomo.helper.utils.close_to_zero, t=10**-5)\n", ") | (\n", " ~fva_no_medium[\"max_flux\"].apply(pycomo.helper.utils.close_to_zero, t=10**-5)\n", ")]" ] }, { "cell_type": "markdown", "id": "f851327b-f8b9-435a-a1f8-6526f56b0900", "metadata": {}, "source": [ "### Add CycleBreaker constraints ###" ] }, { "cell_type": "code", "execution_count": 13, "id": "1ff78294-202d-4372-923a-046d47597dc8", "metadata": {}, "outputs": [], "source": [ "pycomo.helper.cyclebreaker.add_cycle_breaker_constraints_for_all_cycles(com_model_obj, cycles)" ] }, { "cell_type": "code", "execution_count": 14, "id": "79c70ae7-a329-4930-ba49-ba5a10155ea0", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:20,846 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpwq8e71ns.lp\n", "Reading time = 0.07 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:23,254 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpneaszex6.lp\n", "Reading time = 0.06 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:26,081 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp_dpf9zf4.lp\n", "Reading time = 0.06 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:28,830 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpq5ytleyx.lp\n", "Reading time = 0.06 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:31,703 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmpb97o7bim.lp\n", "Reading time = 0.07 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:34,635 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp3qgzdj9k.lp\n", "Reading time = 0.06 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:38,118 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp6v3uryre.lp\n", "Reading time = 0.07 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:34:41,010 - PyCoMo - INFO - Logger initialized.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Set parameter LicenseID to value 2696585\n", "Academic license - for non-commercial use only - expires 2026-08-19\n", "Read LP format model from file /tmp/tmp_j33m9f_.lp\n", "Reading time = 0.06 seconds\n", ": 6195 rows, 12464 columns, 43877 nonzeros\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-03-15 13:37:35,349 - PyCoMo - INFO - Processed 20.75% of fva steps\n", "2026-03-15 13:37:35,379 - PyCoMo - INFO - Processed 41.49% of fva steps\n", "2026-03-15 13:37:35,409 - PyCoMo - INFO - Processed 62.24% of fva steps\n", "2026-03-15 13:37:46,608 - PyCoMo - INFO - Processed 82.99% of fva steps\n", "2026-03-15 13:37:46,621 - PyCoMo - INFO - Processed 100.0% of fva steps\n" ] } ], "source": [ "fva_cyclebreaker = com_model_obj.run_fva(fva_mu_c=0) # FVA on all external reactions" ] }, { "cell_type": "code", "execution_count": 15, "id": "24df3e85-c18c-460a-ba6b-923cdc102693", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
reaction_idmin_fluxmax_flux
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [reaction_id, min_flux, max_flux]\n", "Index: []" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fva_cyclebreaker[(\n", " ~fva_cyclebreaker[\"min_flux\"].apply(pycomo.helper.utils.close_to_zero, t=10**-5)\n", ") | (\n", " ~fva_cyclebreaker[\"max_flux\"].apply(pycomo.helper.utils.close_to_zero, t=10**-5)\n", ")]" ] }, { "cell_type": "markdown", "id": "53e40db4-28a0-420d-8a62-7d1287e21c76", "metadata": {}, "source": [ "Now all cycles are broken and none of the cycle reactions can carry flux!" ] }, { "cell_type": "code", "execution_count": null, "id": "655c428c-5f66-4838-9d0f-1b3109a16a7c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "pycomo_efmtool_dev_cplex_3.10", "language": "python", "name": "pycomo_efmtool_dev_cplex_3.10" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.19" } }, "nbformat": 4, "nbformat_minor": 5 }