Right now removing reactions from a model will still reatin in them in the objective even when using remove_orphans=True. They are kind of handled correctly there because they appear as diconnected variables, meaning they are fixed to zero.
In [2]: from cobra.io import load_model
In [3]: mod = load_model("textbook")
In [4]: mod.objective
Out[4]: <optlang.cplex_interface.Objective at 0x7fb641a6d790>
In [5]: mod.objective.expression
Out[5]: 1.0*Biomass_Ecoli_core - 1.0*Biomass_Ecoli_core_reverse_2cdba
In [6]: mod.remove_reactions([mod.reactions.Biomass_Ecoli_core], True)
In [7]: mod.objective.expression
Out[7]: 1.0*Biomass_Ecoli_core - 1.0*Biomass_Ecoli_core_reverse_2cdba
In [8]: mod.optimize()
Out[8]: <Solution 0.000 at 0x7fb641a74590>
But it is still a bit confusing to have removed reactions appear there.
Solution
I don't have a definitive solution. It is challenging because the objective can be arbitrary non-linear functions so it is not trivial to correctly remove terms. Removing individual reactions in theory also breaks the scaling to 1gDW.
Alternatives
Other approaches:
leave it as is and document the behavior
don't touch the objective but raise a warning
remove the objective if any included variables are removed, forcing the user to set a new objective by hand
Checklist
Problem
Right now removing reactions from a model will still reatin in them in the objective even when using
remove_orphans=True
. They are kind of handled correctly there because they appear as diconnected variables, meaning they are fixed to zero.But it is still a bit confusing to have removed reactions appear there.
Solution
I don't have a definitive solution. It is challenging because the objective can be arbitrary non-linear functions so it is not trivial to correctly remove terms. Removing individual reactions in theory also breaks the scaling to 1gDW.
Alternatives
Other approaches:
Anything else?
Happy to hear the thoughts of the community!