Format NCfitImCFparforFailGbl2.m

This commit is contained in:
2024-07-25 13:45:58 -04:00
parent d569bc4be7
commit df3f9e324e

View File

@@ -1,38 +1,32 @@
%% CALLED BY par4GblFnc8c.m %% %% CALLED BY par4GblFnc8c.m %%
function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanIntensELr,par4scanCFparameters,par4scanCFdate,outC,outCstd]= ... function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanIntensELr,par4scanCFparameters,par4scanCFdate,outC,outCstd]= ...
NCfitImCFparforFailGbl2(parMat,times, values, timeOffsets, fileSuffix, AUCfinalTime, ~, spotAreas, outputDirectory, ~,~, sols, ~) %,scan) NCfitImCFparforFailGbl2(parMat,times, values, timeOffsets, fileSuffix, AUCfinalTime, ~, spotAreas, outputDirectory, ~,~, sols, ~) %,scan)
% Preallocation for parfor loop
st(1,1:size(times,2))=1111;
resMat(1,1:27)=0;
resMatStd=resMat;
outC=zeros(384,27);
outCstd=zeros(384,27);
for m=1:384
pa{m}=st;
par4scanCFparameters{m}=parMat;
par4scanCFdate{m}=datestr((now),31);
end
par4scanselTimesStd=pa;
par4scanselIntensStd=pa;
par4scanTimesELr=pa;
par4scanIntensELr=pa;
par4resMat=zeros(384,27);
par4resMatStd=zeros(384,27);
%Preallocation for parfor loop********************************** % Spot(cultures) loop
st(1,1:size(times,2))= 1111; for ii=1:384 %startSpot:numCultures
resMat(1,1:27)= 0;
resMatStd= resMat;
outC= zeros(384,27);
outCstd= zeros(384,27);
for m=1:384
pa{m}= st;
par4scanCFparameters{m}= parMat;
par4scanCFdate{m}= datestr((now),31);
end
par4scanselTimesStd= pa;
par4scanselIntensStd= pa;
par4scanTimesELr= pa;
par4scanIntensELr= pa;
par4resMat= zeros(384,27);
par4resMatStd= zeros(384,27);
%****************************************************************
%*****************Begin the Spot(cultures) loop****************************
for ii= 1:384 %startSpot:numCultures
%parfor ii= 1:384 %startSpot:numCultures
ii; %%%db print out the culture number ii; %%%db print out the culture number
timepts=[];
timepts= [];
currValues=[]; currValues=[];
currSpotAreas=[]; currSpotAreas=[];
currSpotArea=[]; currSpotArea=[];
dataMatrix=[]; dataMatrix=[];
selTimesStd=[]; %191024 parfor selTimesStd=[]; %191024 parfor
selIntensStd=[]; %191024 parfor selIntensStd=[]; %191024 parfor
@@ -40,236 +34,201 @@ for ii= 1:384 %startSpot:numCultures
NormIntensELr=[]; %191024 parfor NormIntensELr=[]; %191024 parfor
% add offset...1 offset PER PLATE % add offset...1 offset PER PLATE
timepts = times + timeOffsets; %(floor((ii-1)/arrayFormat) + 1); timepts=times + timeOffsets; % (floor((ii-1)/arrayFormat) + 1);
currValues = values(ii,:); %change values(spotNum,:); currValues=values(ii,:); % change values(spotNum,:);
% get spot areas for this culture % get spot areas for this culture
currSpotArea = spotAreas(:,ii); currSpotArea=spotAreas(:,ii);
% just use the area at the last time point % just use the area at the last time point
%currSpotArea = currSpotAreas(1); % currSpotArea=currSpotAreas(1);
%-------------------------------------------------------------- % Preallocate to accomodate parfor loop
resMatStd=zeros(1,27);
resMat=zeros(1,27);
currNormIntens=currValues/currSpotArea;
tmpx=find(currNormIntens>5); %15jh % 2.3);
validSpot=true;
if(isempty(tmpx) || (length(tmpx)<3))
validSpot=false;
normIntens=currNormIntens;
filterTimes=timepts; %filterTimes; %currTimes;
selTimesStd=timepts;
selIntensStd=currNormIntens;
FiltTimesELr=timepts;
NormIntensELr=currNormIntens;
else
% NCfilImCF.m
% Preallocate incase something bails in NCscurImCFparfor
resMatStd=zeros(1,27);
resMat=zeros(1,27);
hold off;
dataMatrix=[];
K=0;r=0;l=0;Klow=0;Kup=0;rlow=0;rup=0;llow=0;lup=0;AUC=0;MSR=0; rsquare=0;
bl=0;
Tpt1=0; numFitTpts =0;thresGT2=0;minTime=0;fitbl=0; %diagnostic outputs only
%Preallocate to accomodate parfor loop ************************** timepts=timepts; % timepts=currTimes; parfor
resMatStd= zeros(1,27); normIntens=currNormIntens;
resMat= zeros(1,27);
currNormIntens = currValues/currSpotArea;
tmpx=find(currNormIntens>5); %15jh % 2.3);
validSpot=true;
if(isempty(tmpx) || (length(tmpx)<3))
validSpot= false;
normIntens= currNormIntens;
filterTimes= timepts; %filterTimes; %currTimes;
selTimesStd= timepts; dataMatrix=[]; % arfor move clear from NCfitImCF...m
selIntensStd= currNormIntens; loIntensThres=parMat(4);
FiltTimesELr= timepts; stdLoIntLim=parMat(5);
NormIntensELr= currNormIntens;
else % Basic filtering
% [loInten Thres,stdbased Trim before Scurve start, and dropout detection]
if(max(normIntens) > 2.29)
threshold=loIntensThres; %1.9; %Increase this value to reduce low data point (flag=2)
else
threshold=0;
end
%******************************************************* dropThreshold=-0.0001* max(normIntens);
%NCfilImCF
%NCfilImCF.m called from NCfitImCF.m line 119*******************
%Preallocate incase something bails in NCscurImCFparfor
resMatStd= zeros(1,27);
resMat= zeros(1,27);
hold off %09_0704 % Initialize dataMatrix
dataMatrix=[]; dataMatrix(1,:)=timepts;
K=0;r=0;l=0;Klow=0;Kup=0;rlow=0;rup=0;llow=0;lup=0;AUC=0;MSR=0; rsquare=0; dataMatrix(2,:)=normIntens;
bl=0; dataMatrix(3,:)=ones;
Tpt1=0; numFitTpts =0;thresGT2=0;minTime=0;fitbl=0; %diagnostic outputs only dataMatrix(4,:)=normIntens;
timepts= timepts; %timepts= currTimes; parfor % Determine a mean Intensity Index point and assoc'd TimePt
normIntens= currNormIntens; a=min(normIntens(normIntens>=0)); %(find(normIntens>=0)));
b=max(normIntens(normIntens>=0)); %(find(normIntens>=0)));
c=0.5*(b-a);
d=b-c;
meanIntIndPt=find(normIntens>d,1);
meanInt=normIntens(meanIntIndPt);
meanTime=times(meanIntIndPt);
dataMatrix= []; %parfor move clear from NCfitImCF...m % NCLoIntstdTrim
loIntensThres=parMat(4); % NCLoSstdTrim.m called by NCfilImCF and NCfil.m
stdLoIntLim=parMat(5); flg1=0;
loScurvLim=stdLoIntLim; %
%******Begin basic filter********** loStimeN=1;
%[loInten Thres,stdbased Trim before Scurve start, and dropout detection] last2n=1;
if(max(normIntens) > 2.29) stdDev=[];
threshold = loIntensThres; %1.9; %Increase this value to reduce low data point (flag=2) nrmIntens0=normIntens;
else for n=1:meanIntIndPt
threshold = 0; if nrmIntens0(n)<=0
end nrmIntens0(n)=0;
end
dropThreshold= -0.0001* max(normIntens); if(nrmIntens0(n)<threshold)
%Initialize dataMatrix********************************** if (loStimeN-2)>0
dataMatrix(1,:)=timepts; dataMatrix(3,1:(n-2))=2; % add to lowIntensity cull flags, the pre S cull data
dataMatrix(2,:)=normIntens; else
dataMatrix(3,:)= ones; dataMatrix(3,1:n)=2;end
dataMatrix(4,:)=normIntens; dataMatrix(3,1:(n-2))=2;
%Determine a mean Intensity Index point and assoc'd TimePt
a= min(normIntens(normIntens>=0)); %(find(normIntens>=0)));
b= max(normIntens(normIntens>=0)); %(find(normIntens>=0)));
c= 0.5*(b-a);
d= b-c;
meanIntIndPt= find(normIntens>d,1);
meanInt= normIntens(meanIntIndPt);
meanTime= times(meanIntIndPt);
%**********************************************************
%**************************************************************************
% NCLoIntstdTrim
%NCLoSstdTrim.m called by NCfilImCF and NCfil.m
flg1=0;
loScurvLim=stdLoIntLim; %
loStimeN=1;
last2n=1;
stdDev= [];
nrmIntens0= normIntens;
for n=1:meanIntIndPt
if nrmIntens0(n)<=0
nrmIntens0(n)=0;
end
if(nrmIntens0(n)<threshold)
if (loStimeN-2)>0,dataMatrix(3,1:(n-2))= 2; %add to lowIntensity cull flags, the pre S cull data
else dataMatrix(3,1:n)= 2;end
dataMatrix(3,1:(n-2))= 2;
last2n=n; last2n=n;
end end
if n<(length(nrmIntens0)-3) if n<(length(nrmIntens0)-3)
x=nrmIntens0(n:(n+3)); x=nrmIntens0(n:(n+3));
stdDev(n)=std(x); stdDev(n)=std(x);
if (stdDev(n)<loScurvLim && flg1~=1) if (stdDev(n)<loScurvLim && flg1~=1)
loStime=timepts(n); loStime=timepts(n);
loStimeN=n; loStimeN=n;
end end
if stdDev(n)>6 ,flg1=1;end %detect S curve rise->stop stdLoInt detection if stdDev(n)>6
flg1=1
end % detect S curve rise->stop stdLoInt detection
end
end
end % TODO repetitive code
if (loStimeN-2)>0
dataMatrix(3,1:(loStimeN-2))=2; % add to lowIntensity cull flags, the pre S cull data
else
dataMatrix(3,1:(loStimeN-2))=2
end
end %end for qcutoff=2;
qind=find(normIntens>2); %,:,'first');
if ~isempty(qind(3))
qcutoff=qind(3)
end
[minInt,I]=min(normIntens(2:qcutoff));
bl=minInt;
minTime=dataMatrix(1,I); %diagnostic output only
if (loStimeN-2)>0,dataMatrix(3,1:(loStimeN-2))= 2; %add to lowIntensity cull flags, the pre S cull data if (length(qind)>5)&&I>1
else dataMatrix(3,1:(loStimeN-2))= 2;end dataMatrix(3,1:(I-1))=5
end
qcutoff=2; tGT2Flg=0;
qind=find(normIntens>2); %,:,'first'); for n=1:length(normIntens)
if ~isempty(qind(3)), qcutoff=qind(3);end dataMatrix(4,n)=normIntens(n)-bl;
[minInt,I]= min(normIntens(2:qcutoff)); if n>I && dataMatrix(4,n)>=2 && tGT2Flg==0
bl=minInt; thresGT2=n;thresGT2Tm=dataMatrix(1,n);tGT2Flg=1;
minTime=dataMatrix(1,I); %diagnostic output only end %diagnostic output only
end
if (length(qind)>5)&&I>1,dataMatrix(3,1:(I-1))=5; end resMat(18)=bl;
resMatStd(18)=bl;
resMatStd(20)=minTime;
resMat(20)=minTime;
tGT2Flg=0; % DropOut cull section (single drop points)
for n=1:length(normIntens) DropOutStartPt=length(normIntens);
dataMatrix(4,n)=normIntens(n)-bl; for n=1:length(normIntens)
if n>I && dataMatrix(4,n)>=2 && tGT2Flg==0
thresGT2=n;thresGT2Tm=dataMatrix(1,n);tGT2Flg=1;
end %diagnostic output only
end
resMat(18)= bl;
resMatStd(18)= bl;
resMatStd(20)= minTime;
resMat(20)= minTime;
%&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&
%*********************************************************
%DropOut cull section(single drop points)*******************
DropOutStartPt=length(normIntens);
for n=1:length(normIntens)
if(n>1) if(n>1)
if(((normIntens(n)- normIntens(n-1))< dropThreshold))&& ... if(((normIntens(n)- normIntens(n-1))< dropThreshold)) && ...
(n > max(meanIntIndPt,thresGT2) ) (n > max(meanIntIndPt,thresGT2) )
dataMatrix(3,n)= 6; dataMatrix(3,n)=6;
end
end end
end end
end
%??????should/could this be removed as recreated in%NCscurImCF_3parfor.m???????????????????? % TODO should/could this be removed as recreated in%NCscurImCF_3parfor.m
%Post Stdtest cull for low intensities inclusion of additional low value points % Post Stdtest cull for low intensities inclusion of additional low value points
%selTimes= [--,--] %don't know size before as it is a filtered output % selTimes=[--,--] %don't know size before as it is a filtered output
tmpIndx= 0; tmpIndx=0;
for n=1:length(normIntens) for n=1:length(normIntens)
if (dataMatrix(3,n)==1) if (dataMatrix(3,n)==1)
tmpIndx= tmpIndx+1; tmpIndx=tmpIndx+1;
selTimes(tmpIndx)= dataMatrix(1,n); %selTimes(nn)= dataMatrix(1,n); selTimes(tmpIndx)=dataMatrix(1,n); % selTimes(nn)=dataMatrix(1,n);
selIntens(tmpIndx)= dataMatrix(4,n); %selIntens(nn)= dataMatrix(4,n); selIntens(tmpIndx)=dataMatrix(4,n); %s elIntens(nn)=dataMatrix(4,n);
end end
end
selTimes=selTimes';
selIntens=selIntens';
filtNormIntens=normIntens;
dataMatrix0=dataMatrix;
filterTimes=timepts; % parfor
%NCscurImCF
%NCscurImCF_1
%NCscurImCF_2
%NCscurImCF_3
%NCscurImCF_3parfor
%NCscurImCF_3parfor(dataMatrix, AUCfinalTime)
%dataMatrix %debugging parfor gbl ok 85.7145; 126.4579,6, 124.5264 37tPt
%adsfj %debugging parfor gbl
[resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntensELr] =...
NCscurImCF_3parfor(dataMatrix0, AUCfinalTime, currSpotArea, sols, bl, minTime);
end end
par4scanselTimesStd{ii}=selTimesStd %timepts'; %filterTimes';
par4scanselIntensStd{ii}=selIntensStd; %normIntens';
par4scanTimesELr{ii}=FiltTimesELr; % 19_1021 preserve for CurveDisplay and EZview
par4scanIntensELr{ii}=NormIntensELr; % 19_1021 preserve for CurveDisplay and EZview
selTimes=selTimes'; outC(ii,:)=resMat; %{ii, par4resMat};
selIntens=selIntens'; outCstd(ii,:)=resMatStd; %{ii, par4resMatStd};
%??????????????????????????????????????????????????? end
%**********End Basic filter******************
%*********************************19_1001***********************************
%To accomodate parfor copy par4scan thru global p4 functions inside of
%parfor loop --then outside to par4Gbl_Main8b.m
%****************************************************** %**************************************************************************
fileExt='.txt';
filtNormIntens=normIntens; filePrefix='FitResultsComplete_';
fileNamePlate=[filePrefix fileSuffix fileExt];
dataMatrix0= dataMatrix; fileName=fullfile(outputDirectory, fileNamePlate); %[outputDirectory fileNamePlate];
filterTimes= timepts; %parfor fid=fopen(fileName,'w');
fprintf(fid, 'Fit Results Complete\n');
%_____________________________________________________________ %fprintf(fid, 'Num.\tAUC\tMSR\tK\tr\tl\tR-squared\tK-lower\tK-upper\tr-lower\tr-upper\tl-upper\tl-lower\tArea\tLastInten\tSpineMaxRateTimePt\tLastFitTimePt\n');
%******************************************* fclose(fid);
%NCscurImCF end
%NCscurImCF_1
%NCscurImCF_2
%NCscurImCF_3
%NCscurImCF_3parfor
%NCscurImCF_3parfor(dataMatrix, AUCfinalTime)
%dataMatrix %debugging parfor gbl ok 85.7145; 126.4579,6, 124.5264 37tPt
%adsfj %debugging parfor gbl
[resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntensELr] =...
NCscurImCF_3parfor(dataMatrix0, AUCfinalTime, currSpotArea, sols, bl, minTime);
end % end JUMP OVER associated with if(find(intensities>1000)<5)
%resMatStd
%asdf
%To accommodate parfor can't use global 'scan' variable 191002================
% {
par4scanselTimesStd{ii}= selTimesStd; %timepts'; %filterTimes';
par4scanselIntensStd{ii}= selIntensStd; %normIntens';
par4scanTimesELr{ii}= FiltTimesELr; %19_1021 preserve for CurveDisplay and EZview
par4scanIntensELr{ii}= NormIntensELr; %19_1021 preserve for CurveDisplay and EZview
%}
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%************* striped down OutCell code was put back into NCfitImCF
outC(ii,:)= resMat; %{ii, par4resMat};
outCstd(ii,:)= resMatStd; %{ii, par4resMatStd};
end %Multispot parfor ii loop end PARFOR LOOP END##############################################################################
%###############################################################################################################################
%###############################################################################################################################
%outC
%*********************************19_1001***********************************
%To accomodate parfor copy par4scan thru global p4 functions inside of
%parfor loop --then outside to par4Gbl_Main8b.m
%**************************************************************************
fileExt = '.txt';
filePrefix = 'FitResultsComplete_';
fileNamePlate = [filePrefix fileSuffix fileExt];
fileName= fullfile(outputDirectory, fileNamePlate); %[outputDirectory fileNamePlate];
fid = fopen(fileName,'w');
fprintf(fid, 'Fit Results Complete\n');
%fprintf(fid, 'Num.\tAUC\tMSR\tK\tr\tl\tR-squared\tK-lower\tK-upper\tr-lower\tr-upper\tl-upper\tl-lower\tArea\tLastInten\tSpineMaxRateTimePt\tLastFitTimePt\n');
fclose(fid);
end %function end
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
%##########################################################################