opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
467 stars 218 forks source link

model.reactions.get_by_id error #1325

Closed dtusso2020 closed 1 year ago

dtusso2020 commented 1 year ago

Hello I have a key error when I run the following code

import cobra
from cobra.io import read_sbml_model
from os.path import join
if __name__ == '__main__':
    data_dir=('/Users/diana/OneDrive/Escritorio')
    cobra.io.read_sbml_model(join(data_dir,"final12041.xml"))
    model = cobra.io.read_sbml_model(join(data_dir,"final12041.xml"))
    model.solver = ('glpk')

    R1 = model.reactions.get_by_id('R_EX_C00031__extr')

    growthRates = []

    for i in range(20):

     R1.lower_bound=-i

     growthRates.append(model.objective.value)

     print(growthRates)

This the key error

`Traceback (most recent call last):

  File ~\OneDrive\Escritorio\untitled0.py:17 in <module>
    print(model.reactions.get_by_id('R_EX_C00031__extr'))

  File ~\anaconda3\lib\site-packages\cobra\core\dictlist.py:74 in get_by_id
    return list.__getitem__(self, self._dict[id])

KeyError: 'R_EX_C00031__extr'`

Does everyone know how I can solve this issue?

Thanks.

dtusso2020 commented 1 year ago

Hello I solved it. I had put the name of the reaction wrong because in the SBML format it appears R_EX_C00031__extr but in cobrapy it appears EX_C00031__extr.

Thank you.