segrelab / cometspy

Python interface for running COMETS simulations and analyzing the results
GNU General Public License v3.0
11 stars 9 forks source link

Potential bug in signalling #13

Closed behzadk closed 2 years ago

behzadk commented 2 years ago

Hi all,

I'm having problems adding signals that induce death with cometspy. Death signals do not seem to correspond with the metabolite indexes I am giving it. I think the issue is a mix up between 1-base or 0-base indexing. As it stands, I think COMETSpy is expecting base-1 indexing when referencing signalling metabolites. I'm not sure if this intentional or not:

According to the notes, the index is subtracted by 1 because COMETS expects it

https://github.com/segrelab/cometspy/blob/609dedb911441f6f20b46e9789f82a707724a154/cometspy/model.py#L149-L153

However, this is in contrast to the line in the comets repo, Signal.java that assumes indexes given are 1-base:

    this.exch_met = exch_met - 1;  // because we let people write in terms of 1-base, but java is 0-order

Link below: https://github.com/segrelab/comets/blob/cd96c97d71bb22c77971ee83fb0cf46ffd480e37/comets_simplified/src/edu/bu/segrelab/comets/fba/Signal.java#L57

Here's some code as a minimal example where E. coli growth is negatively impacted by co2 concentration. In it's current form E. coli grows normally, increment it by 1 to get the expected death of E. coli population:

import cometspy

# Create empty 1x1 layout
test_tube = c.layout()

e_coli = build_model()

# add it to the test_tube
test_tube.add_model(e_coli)

# Set gas metabolites
test_tube.set_specific_metabolite("glc__D_e", 1000000)
test_tube.set_specific_metabolite("o2_e", 100000.0)
test_tube.set_specific_metabolite("co2_e", 100000)

# Add the rest of nutrients unlimited (ammonia, phosphate, water and protons)
test_tube.set_specific_metabolite("nh4_e", 1000)
test_tube.set_specific_metabolite("pi_e", 1000)
test_tube.set_specific_metabolite("h2o_e", 1000)
test_tube.set_specific_metabolite("h_e", 1000)

sim_params = c.params()
sim_params.set_param("timeStep", 0.01)
sim_params.set_param("spaceWidth", 1)
sim_params.set_param("maxSpaceBiomass", 10)
sim_params.set_param("minSpaceBiomass", 1e-11)
sim_params.set_param("writeMediaLog", True)

co2_e_index = list(e_coli.get_exchange_metabolites()).index('co2_e')

e_coli.add_signal(rxn_num='death', exch_ind=co2_e_index, 
bound='met_unchanged', function='linear', parms=[0.001, 0.0])

experiment_open = cometspy.comets(test_tube, sim_params)
experiment_open.run(delete_files=False)

experiment_open.total_biomass.plot(
    x="cycle"
)
plt.show()
dukovski commented 2 years ago

Thanks, let us take a look. Yes, comets has this problem of indexing 1-base, against Java native 0-base.

jeremymchacon commented 2 years ago

Hello,

Thanks for the post. You are correct. Right now, the signaling, while present, is not fully developed or 'released,' and so there are likely to be bugs in it. We appreciate the interest!