EPFL-LCSB / pytfa

A Python 3 implementation of Thermodynamics-based Flux Analysis
https://lcsb.epfl.ch/
Apache License 2.0
38 stars 26 forks source link

KeyError on .convert() #51

Open mdziurzynski opened 3 years ago

mdziurzynski commented 3 years ago

Hello,

I'm trying to convert my model to TFA, and I'm getting an unmanaged KeyError for some of my metabolites. It usually looks like that:

mytfa.prepare()
mytfa.convert()

2021-04-23 14:02:02,924 - thermomodel_ - INFO - # Model preparation starting...
2021-04-23 14:02:04,180 - thermomodel_ - WARNING - Warning : Pb/Pb
2021-04-23 14:02:04,181 - thermomodel_ - WARNING - Warning : Pb/Pb
2021-04-23 14:02:04,296 - thermomodel_ - INFO - # Model preparation done.
2021-04-23 14:02:04,297 - thermomodel_ - INFO - # Model conversion starting...
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-ebc2fae6d451> in <module>
      1 ## TFA conversion
      2 mytfa.prepare()
----> 3 mytfa.convert()#add_displacement = True)
      4 
      5 ## Info on the cobra_model

/media/data/mdz/bio_projects/tac125_metabolic_modelling/analysis/14_tfa_model_construction/pytfa/pytfa/thermo/tmodel.py in convert(self, add_potentials, add_displacement, verbose)
    658         for rxn in self.reactions:
    659             self._convert_reaction(
--> 660                 rxn, add_potentials, add_displacement, verbose
    661             )
    662 

/media/data/mdz/bio_projects/tac125_metabolic_modelling/analysis/14_tfa_model_construction/pytfa/pytfa/thermo/tmodel.py in _convert_reaction(self, rxn, add_potentials, add_displacement, verbose)
    519                             # changes in deltaGFs in the RHS term
    520                             LC_ChemMet += (
--> 521                                 self.LC_vars[met] * RT * rxn.metabolites[met]
    522                             )
    523 

KeyError: <Metabolite cpd15684_c at 0x7f3762226518>

I tried to understand what is going on, but without any success. I just know that self.LC_vars[met] is raising the error. Does it have something to do with how my metabolites/reactions are defined?

psalvy commented 3 years ago

Good day mdziurzynski

Thanks for using pyTFA! From what I see here, it looks like you do not have a concentration variable for this metabolite cpd15684_c. Right after the prepare statement, can you check that this is the case ?

Cheers, Pierre

mdziurzynski commented 3 years ago

Hello Pierre,

thank you for such a quick answer. Quite frankly, I wasn't able to look up the concentration variables after prepare(). What is the proper way to do that? It appears that log concentration data is not created during _convert_metabolites method, but later on in _convert_reactions those missing LC's are required and hence the error.

I'm trying to replicate the tutorial_basics.py code on non reduced model. I prepared the lexicon, adjusted compartment data but I get this error. I uploaded the code along with a the data to this repo: https://github.com/mdziurzynski/tac125_to_pytfa

Update: I managed to overcome this error through removal of 57 reactions from my model. All of them had their dGibbs in Seed Database set to 10000000. If I understand this correctly, that means that there are no reliable data for dGibbs for these reactions, so a placeholder values have been put, right? If yes, if there maybe any way to deal with that kind of unknowns? I read that there are ways to computationally predict dGibbs, so should this kind of approach be applied in such situations?