From f26902fa538d7afa6eda0dc3d16808e9f4f5c584 Mon Sep 17 00:00:00 2001 From: Eduard Kerkhoven Date: Fri, 17 Jul 2026 21:43:19 +0200 Subject: [PATCH] fix: drop stale compMiriams in mergeCompartments mergeCompartments rebuilds comps, compNames and compOutside for the single merged 'System' compartment but left compMiriams untouched, so a model with per-compartment MIRIAM annotations came out with a compMiriams still at the original number of compartments while comps was length 1. That desync breaks downstream permuteModel/exportModel/writeYAMLmodel. The annotations no longer apply once every compartment is merged into one, so the field is now dropped. --- manipulation/mergeCompartments.m | 6 ++++++ testing/function_tests/tManipulation.m | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/manipulation/mergeCompartments.m b/manipulation/mergeCompartments.m index 5ecddfb6..89fa0301 100755 --- a/manipulation/mergeCompartments.m +++ b/manipulation/mergeCompartments.m @@ -110,6 +110,12 @@ model.comps={'s'}; model.compOutside={''}; model.metComps=ones(numel(model.mets),1); +%The per-compartment MIRIAM annotations no longer apply once every +%compartment is merged into one, and leaving them would desync compMiriams +%from the rebuilt comps. Drop them. +if isfield(model,'compMiriams') + model=rmfield(model,'compMiriams'); +end %Add exchange mets to another compartment "b" with id "2" if keepUnconstrained==true diff --git a/testing/function_tests/tManipulation.m b/testing/function_tests/tManipulation.m index fea6878a..905dacaf 100644 --- a/testing/function_tests/tManipulation.m +++ b/testing/function_tests/tManipulation.m @@ -236,6 +236,20 @@ function mergeCompartmentsSingleComp(testCase) testCase.verifyNumElements(m2.comps, 1); end + function mergeCompartmentsDropsStaleCompMiriams(testCase) + % Merging collapses every compartment into one, so any + % per-compartment MIRIAM annotation must not be left behind at the + % original length (which would desync compMiriams from comps). + m = testCase.model; + m.compMiriams = cell(numel(m.comps),1); + m.compMiriams{1}.name = {'go'}; + m.compMiriams{1}.value = {'GO:0005737'}; + evalc('m2 = mergeCompartments(m);'); + if isfield(m2,'compMiriams') + testCase.verifyNumElements(m2.compMiriams, numel(m2.comps)); + end + end + function mergeModelsReturnsStruct(testCase) modelB = removeReactions(testCase.model, testCase.model.rxns(1:5), true, true, true); evalc('merged = mergeModels({testCase.model; modelB});');