Home > testing > unit_tests > modelSortingTests.m

modelSortingTests

PURPOSE ^

run this test case with the command

SYNOPSIS ^

function tests = modelSortingTests

DESCRIPTION ^

run this test case with the command
results = runtests('modelSortingTests.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('modelSortingTests.m')
0003 function tests = modelSortingTests
0004 tests = functiontests(localfunctions);
0005 end
0006 
0007 function sortIdentifirs_and_permuteModelTest(testCase)
0008 
0009 %Load the expected (i.e. sorted) model
0010 sourceDir = fileparts(which(mfilename));
0011 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0012 expModel = model;
0013 
0014 %Create the actual model that will be permuted and sorted
0015 actModel = expModel;
0016 
0017 %Randomly permutate model, do not use RAVEN functions
0018 rndIdx = randperm(numel(actModel.rxns));
0019 fieldsToChange = {'rxns','lb','ub','rev','c','rxnNames','grRules','eccodes'};
0020 for i=1:numel(fieldsToChange)
0021     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
0022 end
0023 actModel.S          = actModel.S(:,rndIdx);
0024 actModel.rxnGeneMat = actModel.rxnGeneMat(rndIdx,:);
0025 
0026 rndIdx = randperm(numel(actModel.mets));
0027 fieldsToChange = {'mets','metNames','metComps','metFormulas','metMiriams'};
0028 for i=1:numel(fieldsToChange)
0029     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
0030 end
0031 actModel.S     = actModel.S(rndIdx,:);
0032 
0033 rndIdx = randperm(numel(actModel.genes));
0034 fieldsToChange = {'genes','geneShortNames'};
0035 for i=1:numel(fieldsToChange)
0036     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
0037 end
0038 actModel.rxnGeneMat = actModel.rxnGeneMat(:,rndIdx);
0039 
0040 rndIdx = randperm(numel(actModel.comps));
0041 fieldsToChange = {'comps','compNames'};
0042 for i=1:numel(fieldsToChange)
0043     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
0044 end
0045 [~,J]=sort(rndIdx);
0046 [toreplace, bywhat] = ismember(actModel.metComps,1:length(J));
0047 actModel.metComps(toreplace) = J(bywhat(toreplace));
0048 
0049 %Sort randomly permutated model
0050 actModel = sortIdentifiers(actModel);
0051 
0052 %Check that the actual model is the same as the expected model
0053 verifyEqual(testCase,actModel,expModel)
0054 end
0055 
0056 function expandModel_and_contractModelTest(testCase)
0057 %Load the expected model
0058 sourceDir = fileparts(which(mfilename));
0059 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0060 
0061 % Note that this does not work any model, as grRules might not be properly
0062 % sorted (but should still be valid)
0063 evalc('modelNew = expandModel(model);'); % Suppress warnings about complex grRules
0064 modelNew = contractModel(modelNew);
0065 
0066 verifyEqual(testCase,model,modelNew)
0067 end
0068

Generated by m2html © 2005