diff --git a/sorter.m b/sorter.m deleted file mode 100644 index 74b59d1..0000000 --- a/sorter.m +++ /dev/null @@ -1,154 +0,0 @@ -%% -% /--------------------------------------------------------------\ -% | Date: 12/12/2018 | -% | Author: Jonathan Cody | -% | Affiliation: Purdue University | -% | Weldon School of Biomedical Engineering | -% | Pienaar Computational Systems Pharmacology Lab | -% \--------------------------------------------------------------/ - -%% ======================================================================== -% INPUTS -% ======================================================================== - -%% ------------------------------------------------------------------------ -% Inputs for sorting algorithms -% ------------------------------------------------------------------------ - -suffix = 't1_m1' ;% suffix identifying calibrator output file - -sortingmethod = 1 ;% 1 = simple sorting (specific to N803 project) - % 2 = GA-based sorting (generalized) - -% ranks of runs to be sorted -SortRuns = [18, 27, 32, 41, 48, 51, 52, 60, 83, 84, 94, 100, 109, 134, 135, 161, 162, 170, 172, 181, 184, 191, 196, 237, 245, 253, 293, 370, 376, 401, 458, 465] ; - -% for simple sorting... -complement = 1 ;% 1 = return complement of selected runs -foldchange = 1.25 ;% required fold change for both CTLs and NKs - -% for GA-based sorting... -numgroups = 3 ;% number of groups into which the runs will be sorted -sortby = 2 ;% output by which to sort the runs - -%% ------------------------------------------------------------------------ -% Optional inputs for results summary figures (see calibrator.m) -% ------------------------------------------------------------------------ - -D = load('DATA') ;% N803 project data file - -PlotParRANGE = [] ;% restricts plotted results based on parameters -xunits = D.xu ;% x-axis label -Yunits = D.Yu_sep ;% y-axis label -YRANGE = D.Yr_sep ;% y-axis limits -sumruns = 500 ;% number of runs included in parameter summary - -% Dock all plotted figures -set(0,'DefaultFigureWindowStyle','docked') % comment out to undock figures - -%% ======================================================================== -% BODY -% ======================================================================== - -% Load structure file to structure variable 'C' -load(['C_' suffix],'C') ; - -switch sortingmethod - -case 1 -%% ------------------------------------------------------------------------ -% Simple Sorter (specific to N803 project) -% ------------------------------------------------------------------------ - -% Select runs that meet all of the following criteria: -% -> viral load must drop by 10-fold within by week 3 -% -> viral load must recover above 1/10th by week 8 -% -> both CD8 cell types must exceed 'foldchange' at some point during both -% phase 1 (weeks 1-4) and phase 2 (weeks 6-9) - -SelectedRuns = SortRuns*0 ; -for n = SortRuns - if isnan(C(n).modelcost) - continue - end -% if any(C(n).MODELOUT(01:50,1)<=C(n).MODELOUT(1,1)-1) && ... -% any(C(n).MODELOUT(51:85,1)>=C(n).MODELOUT(1,1)-1) && ... -% any(C(n).MODELOUT(01:57,2)>=C(n).MODELOUT(1,2)*foldchange) && ... -% any(C(n).MODELOUT(65:92,2)>=C(n).MODELOUT(1,2)*foldchange) && ... -% any(C(n).MODELOUT(01:57,3)>=C(n).MODELOUT(1,3)*foldchange) && ... -% any(C(n).MODELOUT(65:92,3)>=C(n).MODELOUT(1,3)*foldchange) - if any(C(n).MODELOUT(01:57,2)>=C(n).MODELOUT(1,2)*foldchange) && ... - any(C(n).MODELOUT(65:92,2)>=C(n).MODELOUT(1,2)*foldchange) && ... - any(C(n).MODELOUT(01:57,3)>=C(n).MODELOUT(1,3)*foldchange) && ... - any(C(n).MODELOUT(65:92,3)>=C(n).MODELOUT(1,3)*foldchange) && ... - any(C(n).MODELOUT(:,2)<=C(n).MODELOUT(1,2)*0.1) - SelectedRuns(n) = 1 ; - end -end - -% Plot each group using calibrator -if complement == 1 - PlotRanks = find(SelectedRuns==0) ; - PlotRanks = intersect(PlotRanks,SortRuns) ; -else - PlotRanks = find(SelectedRuns==1) ; -end - -calibrator(C(1).setup.X,C(1).setup.Y,C(1).setup.modelfun,... - C(1).setup.RANGE,suffix,length(C),[],[],... - [],[],[],[],[],[],[],[],[],[],[],... - PlotRanks,PlotParRANGE,xunits,Yunits,YRANGE,sumruns) - -case 2 -%% ======================================================================== -% GA-based sorter (generalized for any calibrator output file) -% ======================================================================== - -% Sort runs into groups of like outputs using genetic algorithm -SortedGroupNums = ga(@(X)targetfun(X,numgroups,sortby,C(SortRuns)),... - length(SortRuns),[],[],[],[],SortRuns*0+1,... - SortRuns*0+numgroups,[],1:length(SortRuns)) ; - -% Plot each group using calibrator -for n = 1:numgroups - - PlotRanks = SortRuns(SortedGroupNums==n) ; - - calibrator(C(1).setup.X,C(1).setup.Y,C(1).setup.modelfun,... - C(1).setup.RANGE,suffix,length(C),[],[],... - [],[],[],[],[],[],[],[],[],[],[],... - PlotRanks,PlotParRANGE,xunits,Yunits,YRANGE,sumruns) -end - -end -disp('Done!') - -%% ------------------------------------------------------------------------ -% 'targetfun' function -% ------------------------------------------------------------------------ - -% Target function for genetic algorithm: calculates the variance in model -% output for each group at each time point, then adds up all variances -function varmax = targetfun(GroupNums,numgroups,sortby,Cs) - - GroupRunIndex = ones(1,numgroups) ; - - RunGroups = cell(1,numgroups) ; - for n = 1:numgroups - RunGroups{n} = cell(1,length(GroupNums)) ; - end - - for n = 1:length(GroupNums) - RunGroups{GroupNums(n)}{GroupRunIndex(GroupNums(n))} ... - = Cs(n).MODELOUT(:,sortby) ; - GroupRunIndex(GroupNums(n)) = GroupRunIndex(GroupNums(n)) + 1 ; - end - - GroupVars = zeros(1,numgroups) ; - for n = 1:numgroups - GROUPRUNS = cat(2,RunGroups{n}{:}) ; - GroupVars(n) = sum(var(GROUPRUNS,0,2)) ; - end - varmax = max(GroupVars) ; - -end \ No newline at end of file