klamt-lab / straindesign

StrainDesign is a python package for the computational design of metabolic networks and based on COBRApy
Apache License 2.0
33 stars 6 forks source link

An error when invoke compute_strain_designs #9

Closed Ma-Yier closed 1 year ago

Ma-Yier commented 1 year ago

Invoke compute_strain_designs for optcouple method and set gene_kos=True. In the function extend_model_gpr of networktools.py, some bugs may occur when processing some special data. For example, the iMM904 model in BiGG database has a reaction named ADK1 and also has a gene YDR226W also named ADK1. The w._model is NoneType assigned by line 185:

w = Reaction(gene.id) 

In this case, the w.id will be assigned to ADK1 in line 187:

w.id = gene.name

But because there is a reaction named ADK1 that is already existed, it will fail to add reaction w to model in line 188 :

model.add_reactions([w])

Then because w._model is still NoneType, this will cause AttributeError in line 189:

w.reaction = '--> ' + gene_met_id

This is because in cobra.core.reaction, line 1564 to 1566:

if self._model is None:
            warn("no model found")
            model = None

The model will be None, and finally in line 1612:

met = model.metabolites.get_by_id(met_id)

Here the model is invoked but it is still NoneType.

VonAlphaBisZulu commented 1 year ago

Thank you very much, I will work on it as soon as possible. That might be in a couple of days

VonAlphaBisZulu commented 1 year ago

Thank you once again for your assistance. Your explanation was very helpful in resolving the issue. Ideally, the user should ensure that there are no naming conflicts between genes and reactions. I would not automate the renaming in straindesign because it might be unintended by the user. Hence, the error is now detected, and an exception is raised, providing the user with guidance on which gene names/IDs are affected and how to rename them.

Straindesign permits the formulation of constraints based on gene names, gene IDs, and reaction IDs. To ensure this works, a constraint like "ADK1 = 0" must refer specifically to either a gene or a reaction with no room for ambiguity.

I have implemented the fix, and it will be included in the upcoming release. If you like to receive the update earlier, feel free to check out the master branch.

Ma-Yier commented 1 year ago

Thanks for your help.