forked from SysBioChalmers/RAVEN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test sortIdentifiers and permuteModel
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
testing/unit_tests/sortIdentifiers_and_permuteModelTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.