Skip to content

fix: outputs and metabolite merging in replaceMets - #755

Merged
edkerk merged 2 commits into
mainfrom
fix/replaceMets-outputs
Sep 30, 2026
Merged

edkerk merged 2 commits into
mainfrom
fix/replaceMets-outputs

Conversation

@edkerk

@edkerk edkerk commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Fixes the bugs in replaceMets reported in discussion #754 and found while reviewing the function.

  • replaceMets outputs: removedRxns and idxDuplRxns were never assigned, and idxDuplRxns was the per-reaction cell array of contractModel instead of the indices of removedRxns in the input model.
  • replaceMets metabolite merging: stoichiometries were overwritten instead of summed when a reaction contained both metabolites, the replacement metabolite could be deleted or counted twice when merging by name, and replacement indices were not updated after metabolite rows were deleted.
  • replaceMets model consistency: metNotes was not removed together with the deleted metabolites, and the compartment lookup failed for a row-oriented comps.
  • replaceMets edge cases: replacing a metabolite by itself deleted it, the verbose listing treated reaction identifiers as format strings, and duplicate reactions that already existed were removed even when no metabolite was deleted.

The output, index, stoichiometry-summing and name-merging fixes have regression tests, and the HTML documentation is regenerated.

replaceMets declared removedRxns and idxDuplRxns as outputs but never
assigned them, so requesting them raised an error. They are now taken from
contractModel. Adds a regression test.
@edkerk

edkerk commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Ran the unit tests locally (MATLAB R2024b, Windows): 64 passed. The two failures are solverTests/testSCIP (message mismatch in the SCIP solver check) and solverTests/testCobra (COBRA Toolbox is not installed on this machine). Both are in solverTests, unrelated to this change; the new replaceMetsOutputsTest passes.

idxDuplRxns now holds the indices of removedRxns in the input model.
Stoichiometries are summed when a reaction contains both the replaced and
the replacement metabolite, replacement indices are remapped after metabolite
deletion, and the replacement metabolite is never deleted when merging by name.
Adds regression tests.
@edkerk edkerk changed the title Fix undefined outputs of replaceMets Fix ten bugs in replaceMets Sep 30, 2026
@edkerk edkerk changed the title Fix ten bugs in replaceMets Fix outputs and metabolite merging in replaceMets Sep 30, 2026
@edkerk edkerk changed the title Fix outputs and metabolite merging in replaceMets fix: outputs and metabolite merging in replaceMets Sep 30, 2026
@edkerk
edkerk merged commit cca78c4 into main Sep 30, 2026
1 check failed
@edkerk
edkerk deleted the fix/replaceMets-outputs branch September 30, 2026 17:14
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.

1 participant