Skip to content

Commit 5455e4c

Browse files
committed
review comments
1 parent 03849f9 commit 5455e4c

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/cobra/flux_analysis/fastcc.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
logger = getLogger(__name__)
1515
LARGE_VALUE = 1.0e6
1616

17+
1718
def _add_lp7_vars(
1819
model: "Model", rxns: List["Reaction"], flux_threshold: float
1920
) -> None:
@@ -33,9 +34,7 @@ def _add_lp7_vars(
3334
vars_and_cons = []
3435

3536
for rxn in rxns:
36-
var = prob.Variable(
37-
"auxiliary_{}".format(rxn.id), lb=0.0, ub=flux_threshold
38-
)
37+
var = prob.Variable(f"auxiliary_{rxn.id}", lb=0.0, ub=flux_threshold)
3938
const = prob.Constraint(
4039
rxn.flux_expression - var,
4140
name="aux_constraint_{}".format(rxn.id),
@@ -72,9 +71,9 @@ def _find_sparse_mode(
7271

7372
# Enable constraints for the reactions
7473
for rid in rxn_ids:
75-
model.constraints.get("aux_constraint_{}".format(rid)).lb = 0.0
74+
model.constraints.get(f"aux_constraint_{rid}").lb = 0.0
7675

77-
obj_vars = [model.variables.get("auxiliary_{}".format(rid)) for rid in rxn_ids]
76+
obj_vars = [model.variables.get(f"auxiliary_{rid}") for rid in rxn_ids]
7877
model.objective = Zero
7978
model.objective.set_linear_coefficients({v: 1.0 for v in obj_vars})
8079

@@ -102,12 +101,13 @@ def _flip_coefficients(model: "Model", rxn_ids: Set[str]) -> None:
102101
return
103102
# flip reactions
104103
for rxn in rxn_ids:
105-
const = model.constraints.get("aux_constraint_{}".format(rxn))
106-
var = model.variables.get("auxiliary_{}".format(rxn))
104+
const = model.constraints.get(f"aux_constraint_{rxn}")
105+
var = model.variables.get(f"auxiliary_{rxn}")
107106
coefs = const.get_linear_coefficients(const.variables)
108107
const.set_linear_coefficients({k: -v for k, v in coefs.items() if k is not var})
109108
model.solver.update()
110109

110+
111111
def _any_set(s):
112112
for x in s:
113113
return set([x])
@@ -169,25 +169,25 @@ def fastcc(
169169
with model:
170170
_add_lp7_vars(model, model.reactions, flux_threshold)
171171

172-
rxns_to_keep = _find_sparse_mode(
173-
model, rxns_to_check, zero_cutoff
174-
)
172+
rxns_to_keep = _find_sparse_mode(model, rxns_to_check, zero_cutoff)
175173
rxns_to_check = all_rxns.difference(rxns_to_keep)
176174
logger.info(
177175
"Initial step found %d consistent reactions. "
178176
"Starting the consistency loop for the remaining %d reactions.",
179-
len(rxns_to_keep), len(rxns_to_check)
177+
len(rxns_to_keep),
178+
len(rxns_to_check),
180179
)
181180

182181
while rxns_to_check:
183182
logger.debug(
184183
"reactions to check: %d - consistent reactions: %d - flipped: %d - singletons: %d",
185-
len(rxns_to_check), len(rxns_to_keep), flipped, singletons
184+
len(rxns_to_check),
185+
len(rxns_to_keep),
186+
flipped,
187+
singletons,
186188
)
187189
check = _any_set(rxns_to_check) if singletons else rxns_to_check
188-
new_rxns = _find_sparse_mode(
189-
model, check, zero_cutoff
190-
)
190+
new_rxns = _find_sparse_mode(model, check, zero_cutoff)
191191
rxns_to_keep.update(new_rxns)
192192

193193
if rxns_to_check.intersection(rxns_to_keep):
@@ -206,14 +206,16 @@ def fastcc(
206206
check = _any_set(rxns_to_check) if singletons else rxns_to_check
207207
_flip_coefficients(model, check_irr)
208208
logger.info(
209-
"Final - consistent reactions: %d - inconsistent reactions: %d [eps=%.2g, tol=%.2g]",
210-
len(rxns_to_keep), len(all_rxns) - len(rxns_to_keep), flux_threshold, zero_cutoff
211-
)
209+
"Final - consistent reactions: %d - inconsistent reactions: %d [eps=%.2g, tol=%.2g]",
210+
len(rxns_to_keep),
211+
len(all_rxns) - len(rxns_to_keep),
212+
flux_threshold,
213+
zero_cutoff,
214+
)
212215

213216
consistent_model = model.copy()
214217
consistent_model.remove_reactions(
215-
all_rxns.difference(rxns_to_keep),
216-
remove_orphans=True
218+
all_rxns.difference(rxns_to_keep), remove_orphans=True
217219
)
218220

219221
return consistent_model

0 commit comments

Comments
 (0)