Skip to content

Commit

Permalink
feat: test sortIdentifiers and permuteModel
Browse files Browse the repository at this point in the history
  • Loading branch information
edkerk committed Oct 25, 2021
1 parent 4a250ac commit 8dd899d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions testing/unit_tests/sortIdentifiers_and_permuteModelTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
%run this test case with the command
%results = runtests('sortIdentifiers_and_permuteModelTests.m')
function tests = sortIdentifiers_and_permuteModelTests
tests = functiontests(localfunctions);
end

function sortRandomizedModelTest(testCase)

% Load sorted toy model
sourceDir = fileparts(which(mfilename));
load([sourceDir,'/test_data/ecoli_textbook.mat']);
taskStruct = parseTaskList(strcat(sourceDir, '/test_data/test_tasks.txt'));
rndModel = model;

% Randomly permutate model, do not use RAVEN functions
rndIdx = randperm(numel(rndModel.rxns));
fieldsToChange = {'rxns','lb','ub','rev','c','rxnNames','grRules','eccodes'};
for i=1:numel(fieldsToChange)
rndModel.(fieldsToChange{i}) = rndModel.(fieldsToChange{i})(rndIdx);
end
rndModel.S = rndModel.S(:,rndIdx);
rndModel.rxnGeneMat = rndModel.rxnGeneMat(rndIdx,:);

rndIdx = randperm(numel(rndModel.mets));
fieldsToChange = {'mets','metNames','metComps','metFormulas'};
for i=1:numel(fieldsToChange)
rndModel.(fieldsToChange{i}) = rndModel.(fieldsToChange{i})(rndIdx);
end
rndModel.S = rndModel.S(rndIdx,:);

rndIdx = randperm(numel(rndModel.genes));
fieldsToChange = {'genes','geneShortNames'};
for i=1:numel(fieldsToChange)
rndModel.(fieldsToChange{i}) = rndModel.(fieldsToChange{i})(rndIdx);
end
rndModel.rxnGeneMat = rndModel.rxnGeneMat(:,rndIdx);

rndIdx = randperm(numel(rndModel.comps));
fieldsToChange = {'comps','compNames'};
for i=1:numel(fieldsToChange)
rndModel.(fieldsToChange{i}) = rndModel.(fieldsToChange{i})(rndIdx);
end
[~,J]=sort(rndIdx);
[toreplace, bywhat] = ismember(rndModel.metComps,1:length(J));
rndModel.metComps(toreplace) = J(bywhat(toreplace));

%Sort random model
rndModel = sortIdentifiers(rndModel);

%Check that results is same as original model
verifyEqual(testCase,rndModel,model)
end
Binary file added testing/unit_tests/test_data/ecoli_textbook.mat
Binary file not shown.

0 comments on commit 8dd899d

Please sign in to comment.