Home > testing > unit_tests > mergeModelsTests.m

mergeModelsTests

PURPOSE ^

run this test case with the command

SYNOPSIS ^

function tests = mergeModelsTests

DESCRIPTION ^

run this test case with the command
results = runtests('mergeModelsTests.m')

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %run this test case with the command
0002 %results = runtests('mergeModelsTests.m')
0003 function tests = mergeModelsTests
0004 tests = functiontests(localfunctions);
0005 end
0006 
0007 function mergeModelsBasicTest(testCase)
0008 %Merging plain models (without rxnFrom/metFrom/geneFrom) should create these
0009 %fields and trace each reaction/metabolite/gene back to the model it came from
0010 sourceDir = fileparts(which(mfilename));
0011 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0012 
0013 modelA    = model;
0014 modelA.id = 'modelA';
0015 
0016 %Make all reactions and metabolites in modelB unique so that they are all
0017 %added as new entities when merging (metabolites are matched by name)
0018 modelB          = model;
0019 modelB.id       = 'modelB';
0020 modelB.rxns     = strcat(modelB.rxns,'_B');
0021 modelB.mets     = strcat(modelB.mets,'_B');
0022 modelB.metNames = strcat(modelB.metNames,'_B');
0023 
0024 evalc('modelMerged=mergeModels({modelA;modelB})');
0025 
0026 %The From fields should exist and have the same size as their entities. Before
0027 %the fix, metFrom was not extended and ended up shorter than mets
0028 verifyTrue(testCase,isfield(modelMerged,'rxnFrom'));
0029 verifyTrue(testCase,isfield(modelMerged,'metFrom'));
0030 verifyTrue(testCase,isfield(modelMerged,'geneFrom'));
0031 verifyEqual(testCase,numel(modelMerged.rxnFrom),numel(modelMerged.rxns));
0032 verifyEqual(testCase,numel(modelMerged.metFrom),numel(modelMerged.mets));
0033 verifyEqual(testCase,numel(modelMerged.geneFrom),numel(modelMerged.genes));
0034 
0035 %Each reaction and metabolite should be traced back to its source model
0036 verifyEqual(testCase,modelMerged.rxnFrom,[repmat({'modelA'},numel(modelA.rxns),1);repmat({'modelB'},numel(modelB.rxns),1)]);
0037 verifyEqual(testCase,modelMerged.metFrom,[repmat({'modelA'},numel(modelA.mets),1);repmat({'modelB'},numel(modelB.mets),1)]);
0038 %Genes are shared between the models, so all are traced to the first model
0039 verifyTrue(testCase,all(ismember(modelMerged.geneFrom,{'modelA','modelB'})));
0040 end
0041 
0042 function mergeModelsKeepExistingFromTest(testCase)
0043 %If the input models already have rxnFrom/metFrom/geneFrom fields, mergeModels
0044 %should keep those values instead of overwriting them with the model ids
0045 sourceDir = fileparts(which(mfilename));
0046 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0047 
0048 modelA          = model;
0049 modelA.id       = 'modelA';
0050 modelA.rxnFrom  = repmat({'origA'},numel(modelA.rxns),1);
0051 modelA.metFrom  = repmat({'origA'},numel(modelA.mets),1);
0052 
0053 modelB          = model;
0054 modelB.id       = 'modelB';
0055 modelB.rxns     = strcat(modelB.rxns,'_B');
0056 modelB.mets     = strcat(modelB.mets,'_B');
0057 modelB.metNames = strcat(modelB.metNames,'_B');
0058 modelB.rxnFrom  = repmat({'origB'},numel(modelB.rxns),1);
0059 modelB.metFrom  = repmat({'origB'},numel(modelB.mets),1);
0060 
0061 evalc('modelMerged=mergeModels({modelA;modelB})');
0062 
0063 %The pre-existing labels should be preserved, not replaced by the model ids
0064 verifyEqual(testCase,modelMerged.rxnFrom,[repmat({'origA'},numel(modelA.rxns),1);repmat({'origB'},numel(modelB.rxns),1)]);
0065 verifyEqual(testCase,modelMerged.metFrom,[repmat({'origA'},numel(modelA.mets),1);repmat({'origB'},numel(modelB.mets),1)]);
0066 end
0067 
0068 function mergeModelsViaCopyToCompsTest(testCase)
0069 %copyToComps runs mergeModels with the copyToComps flag set. When the input
0070 %model has no rxnFrom/metFrom/geneFrom fields, the output should not gain any
0071 sourceDir = fileparts(which(mfilename));
0072 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0073 
0074 evalc('modelNew=copyToComps(model,{''p''},''ACKr'')');
0075 
0076 verifyFalse(testCase,isfield(modelNew,'rxnFrom'));
0077 verifyFalse(testCase,isfield(modelNew,'metFrom'));
0078 verifyFalse(testCase,isfield(modelNew,'geneFrom'));
0079 %The reaction should still have been copied to the new compartment
0080 verifyTrue(testCase,ismember('ACKr_p',modelNew.rxns));
0081 end
0082 
0083 function mergeModelsViaCopyToCompsKeepFromTest(testCase)
0084 %When the input model already has the From fields, copyToComps should keep
0085 %them and assign empty labels ('') to the newly created reactions/metabolites
0086 sourceDir = fileparts(which(mfilename));
0087 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0088 
0089 model.rxnFrom  = repmat({'orig'},numel(model.rxns),1);
0090 model.metFrom  = repmat({'orig'},numel(model.mets),1);
0091 model.geneFrom = repmat({'orig'},numel(model.genes),1);
0092 
0093 nRxns = numel(model.rxns);
0094 nMets = numel(model.mets);
0095 
0096 evalc('modelNew=copyToComps(model,{''p''},''ACKr'')');
0097 
0098 %The fields should still be present and consistent in size
0099 verifyEqual(testCase,numel(modelNew.rxnFrom),numel(modelNew.rxns));
0100 verifyEqual(testCase,numel(modelNew.metFrom),numel(modelNew.mets));
0101 %The original labels are kept, the new reactions/metabolites are labelled ''
0102 verifyEqual(testCase,modelNew.rxnFrom(1:nRxns),model.rxnFrom);
0103 verifyEqual(testCase,modelNew.metFrom(1:nMets),model.metFrom);
0104 verifyTrue(testCase,all(strcmp(modelNew.rxnFrom(nRxns+1:end),'')));
0105 verifyTrue(testCase,all(strcmp(modelNew.metFrom(nMets+1:end),'')));
0106 %No new genes are introduced, so geneFrom is left untouched
0107 verifyEqual(testCase,modelNew.geneFrom,model.geneFrom);
0108 end
0109

Generated by m2html © 2005