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

Fix FastCC #1428

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open

Fix FastCC #1428

wants to merge 2 commits into from

Conversation

cdiener
Copy link
Member

@cdiener cdiener commented Feb 26, 2025

This brings the method in line with the paper. Still not super fast but it works. Still missing some more tests.

Copy link
Member

@Midnighter Midnighter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly checked for style etc. Perhaps @dagl1 could look at the functional side, I'm not into the matter at the moment.


for rxn in rxns:
var = prob.Variable(
"auxiliary_{}".format(rxn.id), lb=0.0, ub=flux_threshold
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"auxiliary_{}".format(rxn.id), lb=0.0, ub=flux_threshold
f"auxiliary_{rxn.id}", lb=0.0, ub=flux_threshold


# Enable constraints for the reactions
for rid in rxn_ids:
model.constraints.get("aux_constraint_{}".format(rid)).lb = 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
model.constraints.get("aux_constraint_{}".format(rid)).lb = 0.0
model.constraints.get(f"aux_constraint_{rid}").lb = 0.0

for rid in rxn_ids:
model.constraints.get("aux_constraint_{}".format(rid)).lb = 0.0

obj_vars = [model.variables.get("auxiliary_{}".format(rid)) for rid in rxn_ids]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
obj_vars = [model.variables.get("auxiliary_{}".format(rid)) for rid in rxn_ids]
obj_vars = [model.variables.get(f"auxiliary_{rid}") for rid in rxn_ids]

const = model.constraints.get("constraint_{}".format(rxn.id))
var = model.variables.get("auxiliary_{}".format(rxn.id))
for rxn in rxn_ids:
const = model.constraints.get("aux_constraint_{}".format(rxn))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const = model.constraints.get("aux_constraint_{}".format(rxn))
const = model.constraints.get(f"aux_constraint_{rxn}")

var = model.variables.get("auxiliary_{}".format(rxn.id))
for rxn in rxn_ids:
const = model.constraints.get("aux_constraint_{}".format(rxn))
var = model.variables.get("auxiliary_{}".format(rxn))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var = model.variables.get("auxiliary_{}".format(rxn))
var = model.variables.get(f"auxiliary_{rxn}")

@dagl1
Copy link

dagl1 commented Mar 16, 2025

@Midnighter Ah sorry I didn't realise things required checking.
So output-wise this fastCC version corresponds to the cobra toolbox (matlab) implementation, and both are congruent with checking for blocked reactions (as in, after removing any things that could not carry flux, no more blocked reactions are detected with other methods (one is MACAW from https://www.biorxiv.org/lookup/doi/10.1101/2024.06.24.600481 )
Code wise it looks correct, however I did not do a line by line comparison. Additionally this is all going by the idea that the Matlab implementation is indeed correct. I will run FVA to make sure that the results corroborate (although I am expecting some reactions with very "bad" stoichiometries to show some deviance).

Some small things in regards to the code (but both of you are my seniors so take them as questions)
Edit: I will see if I have time for a full FVA run tomorrow or Tuesday, if that corroborates I think we are good

result = []
# Disable constraints for the reactions
for rid in rxn_ids:
model.constraints.get("aux_constraint_{}".format(rid)).lb = -LARGE_VALUE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optlang includes removal of constraints, as far as I can see, keeping these for later use isn't necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add and remove them in every iteration but this is much slower. Adding constraints means extending the constraint matrix and removing contracting it. Changing a bound however is a constant time operation and very quick.

@@ -10,9 +11,44 @@
if TYPE_CHECKING:
from cobra.core import Model, Reaction

logger = getLogger(__name__)
LARGE_VALUE = 1.0e6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floating constant; in the matlab implementation this is derived from the solver tolerance (which I don't like that much either), would there be anything against directly adding this as optional argument for the functions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is not the tolerance (it's 1e6 not 1e-6). Do deactivate the constraints I just want to open its bound, but optlang does not allow unbounded constraints so I just set a very large (in absolute value) lower bound here to turn off the constraint.

@Midnighter
Copy link
Member

Thank you for your evaluation @dagl1.

Ah sorry I didn't realise things required checking.

It's not so much that it's strictly required but since most of us work alone rather than pair program, it's always better to have a second pair of eyes.

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

Successfully merging this pull request may close these issues.

3 participants