Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Equality of metabolites and reactions #1414

Open
1 task done
oxinabox opened this issue Nov 26, 2024 · 4 comments
Open
1 task done

[Feature] Equality of metabolites and reactions #1414

oxinabox opened this issue Nov 26, 2024 · 4 comments

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Nov 26, 2024

Checklist

Problem

I want to be able to detect if metabolites or reactions are equal so i can avoid adding duplicates to my model.

Consider:

In [1]: from cobra import Model, Reaction, Metabolite

In [2]: m_o2 = Metabolite("o2", "O2", "oxygen")

In [3]: m_o2 == m_o2.copy()
Out[3]: False

In [4]:     ex_o2 = Reaction("EX_o2", lower_bound=-100, upper_bound=100)
    ...:     ex_o2.add_metabolites({m_o2: -1})
    ...: 

In [5]: ex_o2 == ex_o2.copy()
Out[5]: False

Solution

The exact details of how this would work is unclear to me.
In terms of should it require that the metabolites have same id, or should it require a deeper check that they are equal in all fields.
Should it allow different id if name is the same?

In general though we should be be able to detect if reactions are the same.

Alternatives

In general it seems like sometimes reactions are considered equal if they have the same identifier.
Except the equality operator is not implemented.
E.g. model.add_reactions will ignore requests to add things with same id

In [29]: model.add_reactions([ex_o2])

In [30]: model.add_reactions([ex_o2])
Ignoring reaction 'EX_o2' since it already exists.

Anything else?

No response

@Midnighter
Copy link
Member

I don't disagree that better comparison methods would be useful, but can I anyway ask about your use-case?

For the last part, Model.metabolites, Model.genes, and Model.reactions are all containers that track not only the order of elements about also their identifiers. Hence, it is not possible to have two elements with the same identifier in a model.

@oxinabox
Copy link
Contributor Author

oxinabox commented Dec 10, 2024

I am knocking-in ractions from one "universal" model into another model that I want to simulate.
So I want to make sure I am not knocking in a reaction that is already present.
Because

  1. that is not nesc biologically sound
  2. because it will error if I try (actually it is a bit inconsistent, sometimes adding things that already have there id there is a no-op, sometimes it is an error, sometimes it is a warning)

@cdiener
Copy link
Member

cdiener commented Dec 11, 2024

Apart from the difficulties in checking that the stoichiometry, genes and GPRs are the same, the annotations would be really hard I feel. What if the reactions agree in their KEGG ID but not in the ModelSEED one? Or if one misses an annotation.

@oxinabox
Copy link
Contributor Author

oxinabox commented Dec 12, 2024

Or if one uses a deprecated id and the other the current one.

I think sensibly the annotations can only be considered metadata and that stoichiometry and GPR is all that should be checked.
Checking GPR is annoying but possible (at least with sympy).

But also even checking stoichiometry is nontrivial.
For example reactions can be the same if you negate their stoichimetry matrix and flip their bounds.
Or in general scale their stoichiometry matrix and bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants