Skip to content

Commit 08c742a

Browse files
committed
docs: improve iMAT multi-condition example
1 parent 180be84 commit 08c742a

3 files changed

Lines changed: 987 additions & 342 deletions

File tree

corneto/methods/future/imat.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def create_flow_based_problem(self, flow_problem, graph: BaseGraph, data: Data):
243243

244244
# Process weights for each sample
245245
n_samples = len(data.samples)
246-
for i, sample_data in enumerate(data.samples.values()):
246+
for i, (sample_name, sample_data) in enumerate(data.samples.items()):
247247
weights = []
248248
rxn_ids = []
249249

@@ -305,18 +305,29 @@ def create_flow_based_problem(self, flow_problem, graph: BaseGraph, data: Data):
305305
unblocked_sample = sample_active
306306

307307
# Add objectives for highly expressed reactions
308+
sample_name_str = str(sample_name).replace(" ", "_")
309+
308310
if len(idx_pos) > 0:
309311
pos_weights = scored_weights[idx_pos]
310-
flow_problem.add_objectives(pos_weights @ (1 - sample_active[idx_pos]))
312+
flow_problem.add_objective(
313+
pos_weights @ (1 - sample_active[idx_pos]),
314+
name=f"imat_fit_pos_{sample_name_str}_{i}",
315+
)
311316

312317
# Add objectives for lowly expressed reactions
313318
if len(idx_neg) > 0:
314319
neg_weights = scored_weights[idx_neg]
315320
if self.use_bigm_constraints:
316321
# 1 if the reactions is unblocked (can have positive/negative flux)
317-
flow_problem.add_objectives(np.abs(neg_weights) @ unblocked_sample[idx_neg])
322+
flow_problem.add_objective(
323+
np.abs(neg_weights) @ unblocked_sample[idx_neg],
324+
name=f"imat_fit_neg_{sample_name_str}_{i}",
325+
)
318326
else:
319-
flow_problem.add_objectives(np.abs(neg_weights) @ sample_active[idx_neg])
327+
flow_problem.add_objective(
328+
np.abs(neg_weights) @ sample_active[idx_neg],
329+
name=f"imat_fit_neg_{sample_name_str}_{i}",
330+
)
320331

321332
return flow_problem
322333

0 commit comments

Comments
 (0)