Files
hartman-server/qhtcp-workflow/apps/matlab/ezview/EZmultiGeneRFsLst.m

647 lines
33 KiB
Matlab
Executable File

% EZmultiGeneRFsLst Called by EZmultiExLoad
% Called by EZmultiExLoad about line173 Which is called by EZexpSel
% User Select Reference Gene and Specifics Added
% Compile GeneList and OrfList
% Sort and add the medians of Ref Plates if RF1,RF2 exist
clear aa bb c uu vv drf drfPindx drfr drfc
clear RF1scanN RF2scanN
for mx=1:length(Exp(expN).Dexp(n).MP)
try
char((Exp(expN).Dexp(n).MP(mx).genename{1}(384)))
MPnum=mx;
catch
break
end
end
DMnum=length(Exp(expN).Dexp(n).DM.drug);
tPtsSize=size(Exp(expN).Dexp(n).FexpScanBMtp{1,1},(3)); %size(FexpScanBMtp{1,1},3);
lstindx=0;
lstindxOrf=0;
spN=0;
Exp(expN).Dexp(n).RFrnames %<--???
rfcnt=0;
dRF1indx=0;
RF1mp=[]; RF2mp=[];
rfSp=cell2mat(rfSpec); % user entry of Specifics for Ref selection
for mp=1:MPnum
% RF1fullPlate=0;
for ind384=1:384
spN=spN+1;
try
r=ceil(ind384/24);
if rem(ind384,24)==0, c=24; else c=rem(ind384,24); end
% Insert test for numeric in genename and orf if isnumeric
% Correct common EXCEL problem of converting OCT1 into a date numeric
if cell2mat(Exp(expN).Dexp(n).MP(mp).genename{1}(ind384))==38991,
Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)={'OCT1_'};
elseif isnumeric(cell2mat(Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)))
Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)={' '};
end
%****Check for full(384spot) Reference Plates (RF1 or/and RF2)**************
RF1fullPlate=0;
try RF1fullPlate=sum(ismember((Exp(expN).Dexp(n).MP(mp).genename{1}),rfGene))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
RF2fullPlate=0;
try RF2fullPlate=sum(ismember((Exp(expN).Dexp(n).MP(mp).genename{1}),'RF2'))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
% Capture non-reference spot location and ORF data
if isempty(regexpi(char((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384))),'blank'))... %'\<blank\>'
&& ~isnumeric(Exp(expN).Dexp(n).MP(mp).orf{1}(ind384))...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),' ')...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),' ')...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),'')...
&& ~isempty((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)))...
&& ((~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene)|| ~strcmpi((Exp(expN).Dexp(n).MP(mp).specifics{1}(ind384)),rfSp))...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene)|| ~strcmpi(rfSp,'None')))...
&& ((~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),rfGene)|| ~strcmpi((Exp(expN).Dexp(n).MP(mp).specifics{1}(ind384)),rfSp))...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),rfGene)|| ~strcmpi(rfSp,'None')))...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),'RF2')||~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),'RF2'))...
&& iscellstr((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)))
lstindxOrf=lstindxOrf+1;
Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)=strrep((Exp(expN).Dexp(n).MP(mp).orf{1}(ind384)),':',' ');
bb(lstindxOrf,1)=(Exp(expN).Dexp(n).MP(mp).orf{1}(ind384));
bb(lstindxOrf,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
bb(lstindxOrf,3)={mp};
bb(lstindxOrf,4)={r};
bb(lstindxOrf,5)={c};
mutorfs(lstindxOrf)=spN; %16_0318 added for Interaction EZinteract
% Exp(expN).Dexp(n).mutSpotIndx(lstindxOrf)=spN; %16_0318 added for Interaction EZinteract
end
% Capture non-reference spot location and GENENAME data
if isempty(regexpi(char((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384))),'blank'))... %'\<blank\>'
&& ~isnumeric(Exp(expN).Dexp(n).MP(mp).genename{1}(ind384))...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),' ')...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),' ')...
&& ~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),'')...
&& ~isempty((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)))...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene)...
|| ~strcmpi((Exp(expN).Dexp(n).MP(mp).specifics{1}(ind384)),rfSp))... % AddSpecifics rfSp && ~RF1fullPlate)...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene) || ~strcmpi(rfSp,'None'))...
&& (~strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),'RF2'))... % && ~RF2fullPlate)...
&& iscellstr((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)))
lstindx=lstindx+1;
Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)=strrep((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),':',' ');
aa(lstindx,1)=(Exp(expN).Dexp(n).MP(mp).genename{1}(ind384));
aa(lstindx,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
aa(lstindx,3)={mp};
aa(lstindx,4)={r};
aa(lstindx,5)={c};
mutgenes(lstindx)=spN;
elseif (RF1fullPlate==1 ... % sum(ismember((Exp(expN).Dexp(n).MP(mp).genename{1}),rfGene))==384 || ...
|| (((length(unique(Exp(expN).Dexp(n).MP(mp).genename{1}(1:384))))==1 && mp==1 ) ... % (isequal((Exp(expN).Dexp(n).MP(mp).genename{1}(1:384)), (Exp(expN).Dexp(n).MP(mp).genename{1}(384:-1:1)))&& mp==1 )) && ...
&& ~exist('RF1scanN','var')))
RF1mp=mp
RF1scanN=(mp*DMnum)-(DMnum-1)
rfcnt=rfcnt+1;
RFs(spN:spN+383)=spN:spN+383;
elseif (RF2fullPlate==1|| ... % sum(ismember((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),'RF2'))==384 ||...
(((length(unique(Exp(expN).Dexp(n).MP(mp).genename{1}(1:384))))==1 && mp==MPnum ) && ...
~exist('RF2scanN','var')))
RF2mp=mp
rfcnt=rfcnt+1;
RFs(spN:spN+383)=spN:spN+383;
RF2scanN=(mp*DMnum)-(DMnum-1)
% DISPersed REFerence capture and find Medians
elseif ( ((strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene) ...
&& strcmpi((Exp(expN).Dexp(n).MP(mp).specifics{1}(ind384)),rfSp))) ...
|| ((strcmpi((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),rfGene) ...
&& strcmpi(rfSp,'None'))) ) &&(RF1fullPlate~=1)
dRF1indx=dRF1indx+1;
Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)=strrep((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384)),':',' ');
drf(dRF1indx,1)=(Exp(expN).Dexp(n).MP(mp).genename{1}(ind384));
drf(dRF1indx,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
drf(dRF1indx,3)={mp}; drfMP(dRF1indx,mp)=mp;
drf(dRF1indx,4)={r}; drfr(dRF1indx,mp)=r;
drf(dRF1indx,5)={c}; drfc(dRF1indx,mp)=c;
drf(dRF1indx,6)={ind384}; drfPindx(dRF1indx,mp)=ind384;
% drf(dRF1indx,7)=(Exp(expN).Dexp(n).MP(mp).specifics{1}(ind384));
end % if isempty(regexpi(char((Exp(expN).Dexp(n).MP(mp).genename{1}(ind384))),'blank'))...
catch
mp % Disable in future to prevent a bomb out OR put into a nested TryCatch
ind384 % Disable in future to prevent a bomb out OR put into a nested TryCatch
msgBadGeneName=strcat('check genename at mp=',num2str(mp),' indx=',num2str(ind384))
end
end
mp
end
% Cover case if mutorfs RFs are labeled RF1 or RF2
try
Exp(expN).Dexp(n).mutSpotIndx.wRFs=union(RFs, mutorfs);
catch
msg='No RFs Found in Exp! wRFs'
Exp(expN).Dexp(n).mutSpotIndx.wRFs=mutorfs;
end
try
Exp(expN).Dexp(n).mutSpotIndx.woRFs=setdiff(mutorfs,RFs);
catch
msg='No RFs Found in Exp! woRFs'
Exp(expN).Dexp(n).mutSpotIndx.woRFs=mutorfs;
end
Exp(expN).Dexp(n).RFmd1indx=[];
Exp(expN).Dexp(n).RFmd1pltN=[];
Exp(expN).Dexp(n).RFmd1LB={[]};
Exp(expN).Dexp(n).RFmd1indx=[];
Exp(expN).Dexp(n).RFmd1pltN={};
Exp(expN).Dexp(n).RFmd1val=[];
Exp(expN).Dexp(n).mean1=[];
Exp(expN).Dexp(n).std1=[];
Exp(expN).Dexp(n).min1=[];
Exp(expN).Dexp(n).max1=[];
Exp(expN).Dexp(n).RFcmpK=[]; %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr=[]; %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL=[]; %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFmd2LB={[]};
Exp(expN).Dexp(n).RFmd2indx=[];
Exp(expN).Dexp(n).RFmd2pltN=[];
Exp(expN).Dexp(n).RFmd2val=[];
Exp(expN).Dexp(n).mean2=[];
Exp(expN).Dexp(n).std2=[];
Exp(expN).Dexp(n).min2=[];
Exp(expN).Dexp(n).max2=[];
Exp(expN).Dexp(n).RFmean=[];
Exp(expN).Dexp(n).RFstd=[];
Exp(expN).Dexp(n).RFmin=[];
Exp(expN).Dexp(n).RFmax=[];
Exp(expN).Dexp(n).RFmdPLB={[]};
Exp(expN).Dexp(n).RFmdPindx=[];
Exp(expN).Dexp(n).RFmdPpltN=[];
Exp(expN).Dexp(n).RFmdPscanN=[];
Exp(expN).Dexp(n).RFmedianP=[];
Exp(expN).Dexp(n).stdP=[];
Exp(expN).Dexp(n).meanP=[];
Exp(expN).Dexp(n).minP=[];
Exp(expN).Dexp(n).maxP=[];
Exp(expN).Dexp(n).RFmdGLB={[]};
Exp(expN).Dexp(n).RFmdGindx=[];
Exp(expN).Dexp(n).RFmdGpltN=[];
Exp(expN).Dexp(n).RFmdGscanN=[];
Exp(expN).Dexp(n).RFmedianG=[];
Exp(expN).Dexp(n).RFminG=[];
Exp(expN).Dexp(n).RFmaxG=[];
Exp(expN).Dexp(n).RFstdG=[];
Exp(expN).Dexp(n).RFmeanG=[];
Exp(expN).Dexp(n).RFcmpGK=[]; %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr=[]; %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGL=[]; %For Ref Composite 17_1009
if exist('RF1scanN','var')
for d=0:(DMnum-1)
medianIndx=[];
nonZeroIndx=[];
medValList=[];
rf1scN=RF1scanN+d;
try %if RF1scanN doesn't exist this addition to list will be skipped
nonZeroIndx=find(Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(1:384,5));
if isempty(nonZeroIndx)
nonZeroCnt=0
medianIndx=nonZeroIndx;
else
nonZeroCnt=length(nonZeroIndx);
end
if ~isempty(nonZeroIndx) && mod(nonZeroCnt,2)==0, medianIndx=nonZeroIndx(1:nonZeroCnt-1); end
if ~isempty(nonZeroIndx) && mod(nonZeroCnt,2)~=0, medianIndx=nonZeroIndx; end
clear medValLst
clear kValLst
clear rValLst
if ~isempty(nonZeroIndx) && length(medianIndx) > (.15*384) % To calc. a median, more than 15% of spots must be nonZero
medValLst=Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(medianIndx,5);
medValList1{d+1}=medValLst;
min1=min(medValLst);
max1=max(medValLst);
std1=std(medValLst);
mean1=mean(medValLst);
kValLst=Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(medianIndx,3); % For Ref Composite 17_1009
rValLst=Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(medianIndx,4); % For Ref Composite 17_1009
mval1=median(medValLst); %mval1=median(Exp(expN).Dexp(n).scan(RF1mps).plate(1).CFout(1:384,5)); %CFout(1:383,5));
RFmd1pos=find(mval1==(Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(1:384,5)));
RFmd1loc(1)=ceil(RFmd1pos/24); %calc r value
RFmd1loc(2)=RFmd1pos - ((RFmd1loc(1)-1)*24); %calc c value
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
aa(lstindx,1)={strcat('RF1md(',num2str(d+1),')')}; %{'RF1md'};
aa(lstindx,2)={strcat(':',num2str(RF1mp),':',num2str(RFmd1loc(1)),':',num2str(RFmd1loc(2)))}; %,'std_',num2str(std1))};
bb(lstindxOrf,1)={strcat('RF1md(',num2str(d+1),')')}; %remove string2cell brackets {...} %{'RF1md'};
bb(lstindxOrf,2)={strcat(':',num2str(RF1mp),':',num2str(RFmd1loc(1)),':',num2str(RFmd1loc(2)))}; %,'std_',num2str(std1))};
% Composite Reference Amalgum Plot
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
aa(lstindx,1)={strcat('RF1cmp(',num2str(d+1),')')};
aa(lstindx,2)={''};
bb(lstindxOrf,1)={strcat('RF1cmp(',num2str(d+1),')')};
bb(lstindxOrf,2)={''};
Exp(expN).Dexp(n).RFmd1LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2));
Exp(expN).Dexp(n).RFmd1indx(d+1)=RFmd1pos;
Exp(expN).Dexp(n).RFmd1pltN=RF1mp;
Exp(expN).Dexp(n).RFmd1val(d+1)=mval1;
Exp(expN).Dexp(n).mean1(d+1)=mean1;
Exp(expN).Dexp(n).std1(d+1)=std1;
Exp(expN).Dexp(n).min1(d+1)=min1;
Exp(expN).Dexp(n).max1(d+1)=max1;
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).Lvals=medValLst; %17_1201 TrendOL
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).med=median(medValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).mean=mean(medValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).std=std(medValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).min=min(medValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(1).dm(d+1).max=max(medValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).Kvals=kValLst;
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).med=median(kValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).mean=mean(kValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).std=std(kValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).min=min(kValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(1).dm(d+1).max=max(kValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).rvals=rValLst;
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).med=median(rValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).mean=mean(rValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).std=std(rValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).min=min(rValLst); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(1).dm(d+1).max=max(rValLst); %For Ref Composite 17_1009
else
% Need to set L r K values to zeros or pick the first spot with zeros
% Spot 1 could be other than zero as the median isn't calculated if
% fewer than some percent are nonzero
medianCalcFailed='To Few nonZero spots for valid median RF1 selection'
firstZero=find(((Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(1:384,5))==0),1,'first')
Exp(expN).Dexp(n).RFmd1indx(d+1)=firstZero;
Exp(expN).Dexp(n).RFmd1pltN=RF1mp;
try medValList1{d+1}=Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(medianIndx,5); nonZeroCnt; catch, catcherror='Ln356', end
end
catch
medianCalcTryFailed1='Failed! Failed! Ln362 But process continued with placeholder P1ind384 spot value!'
try
firstZero=find(((Exp(expN).Dexp(n).scan(rf1scN).plate(1).CFout(1:384,5))==0),1,'first')
Exp(expN).Dexp(n).RFmd1indx(d+1)=firstZero;
catch
Exp(expN).Dexp(n).RFmd1indx(d+1)=384; %if crapout,Then use spot384 as default to keep going
end
try
Exp(expN).Dexp(n).RFmd1pltN=RF1mp;
catch
Exp(expN).Dexp(n).RFmd1pltN=1;
end
end
end
end
% Calc RF2 median if a full plate of RF2s exist
Exp(expN).Dexp(n).RFmd2indx=[];
Exp(expN).Dexp(n).RFmd2pltN=[];
if exist('RF2scanN','var')
for d=0:(DMnum-1)
medianIndx2=[];
nonZeroIndx2=[];
medValList2=[];
rf2scN=RF2scanN+d;
try %if RF2scanN doesn't exist this addition to list will be skipped
nonZeroIndx2=find(Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(1:384,5));
if isempty(nonZeroIndx2)
nonZeroCnt2=0;
medianIndx2=nonZeroIndx2;
else
nonZeroCnt2=length(nonZeroIndx2);
end
if ~isempty(nonZeroIndx2) && mod(nonZeroCnt2,2)==0, medianIndx2=nonZeroIndx2(1:nonZeroCnt2-1); end
if ~isempty(nonZeroIndx2) && mod(nonZeroCnt2,2)~=0, medianIndx2=nonZeroIndx2; end
clear medValLst2
clear kValLst2
clear rValLst2
if ~isempty(nonZeroIndx2) && length(medianIndx2) > (.15*384) % to calc. a median, more than 15% of spots must be nonZero
medValLst2=Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(medianIndx2,5);
medValList2{d+1}=medValLst2;
min2=min(medValLst2);
max2=max(medValLst2);
std2=std(medValLst2);
mean2=mean(medValLst2);
kValLst2=Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(medianIndx2,3); %For Ref Composite 17_1009
rValLst2=Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(medianIndx2,4); %For Ref Composite 17_1009
mval2=median(medValLst2); %mval2=median(Exp(expN).Dexp(n).scan(RF2mps).plate(1).CFout(1:383,5));
RFmd2pos=find(mval2==(Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(1:384,5)));
RFmd2loc(1)=ceil(RFmd2pos/24); %calc r value
RFmd2loc(2)=RFmd2pos - ((RFmd2loc(1)-1)*24); %calc c value
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
aa(lstindx,1)={strcat('RF2md(',num2str(d+1),')')}; %{'RF2md'};
aa(lstindx,2)={strcat(':',num2str(RF2mp),':',num2str(RFmd2loc(1)),':',num2str(RFmd2loc(2)))}; %,'std_',num2str(std2))};
bb(lstindxOrf,1)={strcat('RF2md(',num2str(d+1),')')}; %remove string2cell brackets {...} %{'RF2md'};
bb(lstindxOrf,2)={strcat(':',num2str(RF2mp),':',num2str(RFmd2loc(1)),':',num2str(RFmd2loc(2)))}; %,'std_',num2str(std2))};
% Composite Reference Amalgum Plot (CRAP)
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
aa(lstindx,1)={strcat('RF2cmp(',num2str(d+1),')')};
aa(lstindx,2)={''};
bb(lstindxOrf,1)={strcat('RF2cmp(',num2str(d+1),')')};
bb(lstindxOrf,2)={''};
Exp(expN).Dexp(n).RFmd2LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2));
Exp(expN).Dexp(n).RFmd2indx(d+1)=RFmd2pos;
Exp(expN).Dexp(n).RFmd2pltN=RF2mp;
Exp(expN).Dexp(n).RFmd2val(d+1)=mval2;
Exp(expN).Dexp(n).mean2(d+1)=mean2;
Exp(expN).Dexp(n).std2(d+1)=std2;
Exp(expN).Dexp(n).min2(d+1)=min2;
Exp(expN).Dexp(n).max2(d+1)=max2;
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).Lvals=medValLst2; %17_1201 TrendOL
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).med=median(medValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).mean=mean(medValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).std=std(medValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).min=min(medValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpL(2).dm(d+1).max=max(medValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).Kvals=kValLst2;
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).med=median(kValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).mean=mean(kValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).std=std(kValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).min=min(kValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpK(2).dm(d+1).max=max(kValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).rvals=rValLst2;
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).med=median(rValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).mean=mean(rValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).std=std(rValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).min=min(rValLst2); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpr(2).dm(d+1).max=max(rValLst); %For Ref Composite 17_1009
else
% Pick the first spot with zeros
% Use that position to satisfy and keep process OK
medianCalcFailed2='To Few nonZero spots for valid median RF2 selection'
firstZero2=find(((Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(1:384,5))==0),1,'first')
Exp(expN).Dexp(n).RFmd2indx(d+1)=firstZero2;
Exp(expN).Dexp(n).RFmd2pltN=RF2mp;
try medValList2{d+1}=Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(medianIndx2,5); nonZeroCnt2; catch, catchissue='Ln431', end
end
catch
medianCalcTryFailed2='Failed! Failed! Ln436 No RF1median But process continued with placeholder P1ind384 spot value!'
try
firstZero2=find(((Exp(expN).Dexp(n).scan(rf2scN).plate(1).CFout(1:384,5))==0),1,'first');
Exp(expN).Dexp(n).RFmd2indx(d+1)=firstZero2;
catch
catchissue='Ln442'
Exp(expN).Dexp(n).RFmd2indx(d+1)=384; %if crapout,Then use spot384 as default to keep going
end
try
Exp(expN).Dexp(n).RFmd2pltN=RF2mp;
catch
catchissue='Ln448'
Exp(expN).Dexp(n).RFmd2pltN=1;
end
end
clear RFcombValList
RFcombValList=cat(1,medValList1{d+1},medValList2{d+1});
Exp(expN).Dexp(n).RFmean(d+1)=mean(RFcombValList);
Exp(expN).Dexp(n).RFstd(d+1)=std(RFcombValList);
try, Exp(expN).Dexp(n).RFmin(d+1)=min(RFcombValList);
catch, Exp(expN).Dexp(n).RFmin(d+1)=0; end
try, Exp(expN).Dexp(n).RFmax(d+1)=max(RFcombValList);
catch, Exp(expN).Dexp(n).RFmax(d+1)=0; end
end
elseif exist('RF1scanN','var')
Exp(expN).Dexp(n).RFmean=Exp(expN).Dexp(n).mean1;
Exp(expN).Dexp(n).RFstd=Exp(expN).Dexp(n).std1;
Exp(expN).Dexp(n).RFmin=Exp(expN).Dexp(n).min1;
Exp(expN).Dexp(n).RFmax=Exp(expN).Dexp(n).max1;
end
% Disperse reference plates
Exp(expN).Dexp(n).RFmdPindx=[];
Exp(expN).Dexp(n).RFmdPpltN=[];
if exist('drf','var') % ('RF1scanN','var')
% Det. index of change from one MP to the next
i=2;
clear chgIndx
chgIndx(1)=1;
for j=1:length(drf(:,3))
if j>1
if cell2mat(drf(j,3))~=cell2mat(drf((j-1),3)), chgIndx(i)=j; i=i+1; end
end
end
chgIndx(length(chgIndx)+1)=length(drf)+1;
uu=zeros(size(drf,1),4);
uu(:,1:4)=cell2mat(drf(:,3:6));
vv=zeros(size(drf,1),DMnum); %(length(drf),DMnum);
dMPs=unique(cell2mat(drf(:,3)));
%{
for mm=1:MPnum
nonZrfIndx.mp{mm,:}=drfPindx((find(drfPindx(:,mm))),mm);
end
%}
% nzValsG=zeros(DMnum,size(drf,1));
% nzValsAcc=zeros(DMnum,384);
for mm=1:length(dMPs) % length(chgIndx)
for d=1:(DMnum)
medianIndxDisp=[];
NZrefIndxP=[];
nonZeroValsP=[];
medValLstDisp=[];
rf1scNdisp=((dMPs(mm)-1)*DMnum)+(d);
% Determine the dispersed RFs median mean and std if such exist
try
NZrefIndxP=drfPindx((find(drfPindx(:,dMPs(mm)))),dMPs(mm)); % find(Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(drf(chgIndx(cI):chgIndx(cI+1)),5));
% vv=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
vv(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
% For Global Ref Composite 17_1009
vvK(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,3);
vvr(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,4);
nonZeroValsP=nonzeros(Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5));
std1Disp=std(nonZeroValsP);
mean1Disp=mean(nonZeroValsP);
minDisp=min(nonZeroValsP);
maxDisp=max(nonZeroValsP);
drfVals=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
% nzValsAcc(mm).DM(d,:)=nonZeroValsP;
% MEDIAN Determination for PLATES with Dispersed RFs
% NZrefIndxP=NZrefIndxP %find(Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5));
if isempty(NZrefIndxP)
nonZeroCntDisp=0;
medianIndxDisp=NZrefIndxP;
else
nonZeroCntDisp=length(NZrefIndxP);
end
if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)==0, medianIndxDisp=NZrefIndxP(1:nonZeroCntDisp-1); end
if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)~=0, medianIndxDisp=NZrefIndxP; end
if ~isempty(NZrefIndxP) && length(medianIndxDisp) > 0 %(.15*384) %To calc. a median, more than 15% of spots must be nonZero
medValLstDisp=Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(medianIndxDisp,5);
%medValList1Disp{d}=medValLstDisp;
mval1Disp=median(medValLstDisp); % mval1=median(Exp(expN).Dexp(n).scan(RF1mps).plate(1).CFout(1:384,5)); %CFout(1:383,5));
nonZeroMedPosIndx=find(mval1Disp==nonZeroValsP); % (Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5))); %(nonZeroIndxDisp,5))); %((nonZrfIndx.mp{dMPs(mm),:}),5)));
RFmd1posD=NZrefIndxP(nonZeroMedPosIndx); % drfPindx((RFmd1posIndx),dMPs(mm));
RFmd1locD(1)=ceil(RFmd1posD/24); % calc r value
RFmd1locD(2)=RFmd1posD - ((RFmd1locD(1)-1)*24); % calc c value
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
if usrRefFg==0, rfPLbl='RF1mdP('; else rfPLbl=strcat('RF-',rfGnSp,'mdP('); end % accomodate User Ref Selection
if iscell(strcat(rfPLbl,num2str(d),')')),
aa(lstindx,1)=strcat(rfPLbl,num2str(d),')');
bb(lstindxOrf,1)=strcat(rfPLbl,num2str(d),')'); % remove string2cell brackets {...}
else
aa(lstindx,1)={strcat(rfPLbl,num2str(d),')')};
bb(lstindxOrf,1)={strcat(rfPLbl,num2str(d),')')}; %remove string2cell brackets {...}
end
aa(lstindx,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))};
bb(lstindxOrf,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))};
Exp(expN).Dexp(n).RFmdPLB(d,dMPs(mm))=strcat(aa(lstindx,1),aa(lstindx,2));
Exp(expN).Dexp(n).RFmdPindx(d,dMPs(mm))=RFmd1posD;
Exp(expN).Dexp(n).RFmdPpltN(d,dMPs(mm))=dMPs(mm); %This is a storage of the MasterPlate used NOT the ScanPlate? WeMight wish to store the ScanPlateNumber also???
Exp(expN).Dexp(n).RFmdPscanN(d,dMPs(mm))=rf1scNdisp;
Exp(expN).Dexp(n).RFmedianP(d,dMPs(mm))=mval1Disp;
Exp(expN).Dexp(n).stdP(d,dMPs(mm))=std1Disp;
Exp(expN).Dexp(n).meanP(d,dMPs(mm))=mean1Disp;
Exp(expN).Dexp(n).minP(d,dMPs(mm))=minDisp;
Exp(expN).Dexp(n).maxP(d,dMPs(mm))=maxDisp;
else
% Need to set L r K values to zeros or pick the first spot with zeros
% Spot 1 could be other than zero as the median isn't calculated if fewer than some percent are nonzero
medianCalcFailedD='To Few nonZero spots for valid median RF1 selection'
firstZeroDindx=find(((Exp(expN).Dexp(n).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5))==0),1,'first');
firstZeroD=drfPindx((firstZeroDindx),dMPs(mm));
Exp(expN).Dexp(n).RFmdPindx(d,dMPs(mm))=firstZeroD;
Exp(expN).Dexp(n).RFmdPpltN(d,dMPs(mm))=dMPs(mm); % RF1mp; % Is this supposed to be the MP number or the ScanPlate number???
end
catch
medianCalcTryFailed1D='Failed! Failed! Ln565 {Dispersed RF1s} "try" But process continued with placeholder Plate spot value!'
try
firstZeroindxD=find(vv((chgIndx(d):chgIndx(d+1)-1),5)==0,1,'first');
firstZeroPindx=uu(firstZeroindxD,4);
Exp(expN).Dexp(n).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
Exp(expN).Dexp(n).RFmdPindx(d,dMPs(mm))=firstZeroPindx;
catch
catchissue='try at Ln565'
Exp(expN).Dexp(n).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
Exp(expN).Dexp(n).RFmdPindx(d,dMPs(mm))=384; % if crapout,Then use spot384 as default to keep going
end
try
Exp(expN).Dexp(n).RFmdPpltN=dMPs(mm);
catch
catchissue='Ln619'
Exp(expN).Dexp(n).RFmdPpltN=1; % this might keep from breaking BUT ???
end
end
end
end
% Calc. Global Mean, Std, And Median For Distributed References
uu=horzcat(uu,vv);
for d=1:DMnum
medianIndxG=[];
NZrfIndxG=[];
minG=min(nonzeros(vv(:,d)));
maxG=max(nonzeros(vv(:,d)));
RFmeanG=mean(nonzeros(vv(:,d)));
RFstdG=std(nonzeros(vv(:,d)));
NZrfIndxG=find(vv(:,d)); % find(nonzeros(vv(:,d)));
if isempty(RFmeanG)
nonZeroCntD=0 % medianIndxDisp=RFmeanG(d);
else
nonZeroCntD=length(nonzeros(vv(:,d)));
end
% Calc. of median requires an odd number of indx items
if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)==0, medianIndxD=NZrfIndxG(1:(size(NZrfIndxG,1)-1)); end
if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)~=0, medianIndxD=NZrfIndxG(:); end
if ~isempty(NZrfIndxG) && length(medianIndxD) > 0 %(.15*size(drf,1)) % to calc. a median, more than 15% of spots must be nonZero
mvalsDG=median(vv(medianIndxD,d)); % (nonzeros(vv(:,d)));
nzPosIndxDG=find(mvalsDG==vv(:,d));
RFmdDGloc(d,1)=uu(nzPosIndxDG,1); % MP of distributedGlobal Median value
RFmdDGloc(d,2)=uu(nzPosIndxDG,2); % calc r value
RFmdDGloc(d,3)=uu(nzPosIndxDG,3); % calc c value
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
if usrRefFg==0, rfGLbl='RF1mdG('; else rfGLbl=strcat('RF-',rfGnSp,'mdG('); end %accomodate User Ref Selection
if iscell(strcat(rfPLbl,num2str(d),')')),
aa(lstindx,1)=strcat(rfGLbl,num2str(d),')'); % remove string2cell brackets {...}
bb(lstindxOrf,1)=strcat(rfGLbl,num2str(d),')'); % remove string2cell brackets {...}
else
aa(lstindx,1)={strcat(rfGLbl,num2str(d),')')};
bb(lstindxOrf,1)={strcat(rfGLbl,num2str(d),')')};
end
aa(lstindx,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
bb(lstindxOrf,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
% Composite Reference Amalgum Plot
lstindx=lstindx+1;
lstindxOrf=lstindxOrf+1;
if usrRefFg==0, rfcmpGLbl='RFcmpG('; else rfcmpGLbl=strcat('RFcmpG-',rfGnSp,'('); end %accomodate User Ref Selection
if iscell(strcat(rfcmpGLbl,num2str(d),')')),
aa(lstindx,1)=strcat(rfcmpGLbl,num2str(d),')'); % strcat('RFcmpG(',num2str(d),')');
bb(lstindxOrf,1)=strcat(rfcmpGLbl,num2str(d),')'); % strcat('RFcmpG(',num2str(d),')');
else
aa(lstindx,1)={strcat(rfcmpGLbl,num2str(d),')')};
bb(lstindxOrf,1)={strcat(rfcmpGLbl,num2str(d),')')};
end
aa(lstindx,2)={''};
bb(lstindxOrf,2)={''};
Exp(expN).Dexp(n).RFmdGLB(d)=strcat(aa(lstindx,1),aa(lstindx,2));
Exp(expN).Dexp(n).RFmdGindx(d)=nzPosIndxDG;
Exp(expN).Dexp(n).RFmdGpltN(d)=RFmdDGloc(d,1);
Exp(expN).Dexp(n).RFmdGscanN(d)=uu(nzPosIndxDG,4);
Exp(expN).Dexp(n).RFmedianG(d)=mvalsDG;
Exp(expN).Dexp(n).RFminG(d)=minG;
Exp(expN).Dexp(n).RFmaxG(d)=maxG;
Exp(expN).Dexp(n).RFstdG(d)=RFstdG;
Exp(expN).Dexp(n).RFmeanG(d)=RFmeanG;
Exp(expN).Dexp(n).RFcmpGL.dm(d).Lvals=vv(medianIndxD,d); %17_1201 TrendOL
Exp(expN).Dexp(n).RFcmpGL.dm(d).med=median(vv(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGL.dm(d).mean=mean(vv(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGL.dm(d).std=std(vv(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGL.dm(d).min=min(vv(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGL.dm(d).max=max(vv(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGK.dm(d).Kvals=vvK(medianIndxD,d); %17_1201 TrendOL
Exp(expN).Dexp(n).RFcmpGK.dm(d).med=median(vvK(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGK.dm(d).mean=mean(vvK(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGK.dm(d).std=std(vvK(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGK.dm(d).min=min(vvK(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGK.dm(d).max=max(vvK(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr.dm(d).rvals=vvr(medianIndxD,d); %17_1201 TrendOL
Exp(expN).Dexp(n).RFcmpGr.dm(d).med=median(vvr(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr.dm(d).mean=mean(vvr(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr.dm(d).std=std(vvr(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr.dm(d).min=min(vvr(medianIndxD,d)); %For Ref Composite 17_1009
Exp(expN).Dexp(n).RFcmpGr.dm(d).max=max(vvr(medianIndxD,d)); %For Ref Composite 17_1009
end
end
end
% EZusrSelRef
gnLstRaw=strcat(aa(:,1),aa(:,2));
Exp(expN).Dexp(n).srtGnLst=sort(gnLstRaw);
orfLstRaw=strcat(bb(:,1),bb(:,2));
Exp(expN).Dexp(n).srtOrfLst=sort(orfLstRaw);
%{
%set(handles.MPsldr2,'max',length(MP));
%set(handles.DMsldr2,'max',length(DM.drug));
%set(handles.Tptsldr2,'max',tPtsSize);
%set(handles.MPsldr2,'min',1,'max',MPnum)
%set(handles.DMsldr2,'min',1,'max',DMnum)
%tPtsSize=size(Exp(expN).Dexp(n).FexpScanBMtp{1,1},(3));
%set(handles.Tptsldr2,'min',1,'max',tPtsSize)
%set(handles.MPsldr2,'value',1)
%set(handles.DMsldr2,'value',1)
%set(handles.Tptsldr2,'value',1)
%set(handles.MPed2,'string','1')
%set(handles.DMed2,'string','1')
%set(handles.Tpted2,'string','1')
%set(handles.MPsldr2,'SliderStep',[1/length(MP) 1/length(MP)]);
%set(handles.DMsldr2,'SliderStep',[1/length(DM.drug) 1/length(DM.drug)]);
%set(handles.Tptsldr2,'SliderStep',[1/tPtsSize 1/tPtsSize]);
%}