Skip to content

Adding a reaction that is already part of a model to another model creates an alias (not a copy) #1456

@oxinabox

Description

@oxinabox

Consider:

model1 = cobra.Model("M1")
model1.add_reactions([cobra.Reaction("R1")])
model2 = cobra.Model("M2")
model2.add_reactions(model1.reactions)

print(model1.reactions.R1.bounds)
model2.reactions.R1.bounds = (500,600)
print(model1.reactions.R1.bounds)

which prints:

(0.0, 1000.0)
(500, 600)

We would have expected that changing a reaction on model2 would have no effect on model1.
But actually those reactions are the same.
In fact:

print(model1.reactions.R1.model is model2)

prints True.

Probably add_reactions should always create a copy if reaction.model is set?

Related: #673

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions