diff --git a/workflow/script-run-workflow b/workflow/script-run-workflow index 05581f03..6c9ca1e4 100755 --- a/workflow/script-run-workflow +++ b/workflow/script-run-workflow @@ -538,11 +538,11 @@ easy() { export SCANS_DIR PROJECT_DATE EASY_DIR PROJECT_USER PROJECT_PREFIX EASY_SUFFIX EASY_RESULTS_DIR MASTER_PLATE_FILE DRUG_MEDIA_FILE echo "Hit enter to use the default EASY results directory $SCANS_DIR/Results_${PROJECT_PREFIX}_($PROJECT_SUFFIX)" (( YES )) || read -r -p "Or enter a custom suffix: " suffix - EASY_RESULTS_DIR="$SCANS_DIR/Results_${PROJECT_PREFIX}_${Ssuffix:-$PROJECT_SUFFIX}" + EASY_RESULTS_DIR="$SCANS_DIR/Results_${PROJECT_PREFIX}_${suffix:-$PROJECT_SUFFIX}" while [[ -d $EASY_RESULTS_DIR ]]; do count=1 if [[ $count -eq 1 ]] && ask "$EASY_RESULTS_DIR already exists, increment dir name (y) or overwrite (N)?"; then - EASY_SUFFIX="${Ssuffix:-$PROJECT_SUFFIX}.$((count++))" + EASY_SUFFIX="${suffix:-$PROJECT_SUFFIX}.$((count++))" EASY_RESULTS_DIR="$SCANS_DIR/Results_${PROJECT_PREFIX}_${EASY_SUFFIX}" else EASY_SUFFIX=${suffix:-$PROJECT_SUFFIX} diff --git a/workflow/templates/easy/DMPexcel2mat.m b/workflow/templates/easy/DMPexcel2mat.m index 14213a2e..a1c834b5 100755 --- a/workflow/templates/easy/DMPexcel2mat.m +++ b/workflow/templates/easy/DMPexcel2mat.m @@ -253,13 +253,13 @@ if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinat if ispc while (~isequal(txt{excLnNum,2},'###')) numb=numb+1; - DM.drug(numb) = {raw(excLnNum,2)}; - DM.conc(numb) = {raw(excLnNum,3)}; - DM.media(numb) = {raw(excLnNum,4)}; - DM.mod1(numb) = {raw(excLnNum,5)}; - DM.conc1(numb) = {raw(excLnNum,6)}; - DM.mod2(numb) = {raw(excLnNum,7)}; - DM.conc2(numb) = {raw(excLnNum,8)}; + DM.drug(numb)={raw(excLnNum,2)}; + DM.conc(numb)={raw(excLnNum,3)}; + DM.media(numb)={raw(excLnNum,4)}; + DM.mod1(numb)={raw(excLnNum,5)}; + DM.conc1(numb)={raw(excLnNum,6)}; + DM.mod2(numb)={raw(excLnNum,7)}; + DM.conc2(numb)={raw(excLnNum,8)}; excLnNum=excLnNum+1; msg=strcat('NumberOf1:1DrugMediaPlates = ',num2str(numb), ' lastLineNo. = ',num2str(excLnNum)); end @@ -268,20 +268,20 @@ if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinat excLnNum=1; while (~isequal(DMcell{excLnNum+1,2},'###')) numb=numb+1; - DM.drug(numb) = {DMtbl(excLnNum,2)}; - DM.drug(numb)= table2cell(DM.drug{numb}); - DM.conc(numb) = {DMtbl(excLnNum,3)}; - DM.conc(numb)= table2cell(DM.conc{numb}); - DM.media(numb) = {DMtbl(excLnNum,4)}; - DM.media(numb)= table2cell(DM.media{numb}); - DM.mod1(numb) = {DMtbl(excLnNum,5)}; - DM.mod1(numb)= table2cell(DM.mod1{numb}); - DM.conc1(numb) = {DMtbl(excLnNum,6)}; - DM.conc1(numb)= table2cell(DM.conc1{numb}); - DM.mod2(numb) = {DMtbl(excLnNum,7)}; - DM.mod2(numb)= table2cell(DM.mod2{numb}); - DM.conc2(numb) = {DMtbl(excLnNum,8)}; - DM.conc2(numb)= table2cell(DM.conc2{numb}); + DM.drug(numb)={DMtbl(excLnNum,2)}; + DM.drug(numb)=table2cell(DM.drug{numb}); + DM.conc(numb)={DMtbl(excLnNum,3)}; + DM.conc(numb)=table2cell(DM.conc{numb}); + DM.media(numb)={DMtbl(excLnNum,4)}; + DM.media(numb)=table2cell(DM.media{numb}); + DM.mod1(numb)={DMtbl(excLnNum,5)}; + DM.mod1(numb)=table2cell(DM.mod1{numb}); + DM.conc1(numb)={DMtbl(excLnNum,6)}; + DM.conc1(numb)=table2cell(DM.conc1{numb}); + DM.mod2(numb)={DMtbl(excLnNum,7)}; + DM.mod2(numb)=table2cell(DM.mod2{numb}); + DM.conc2(numb)={DMtbl(excLnNum,8)}; + DM.conc2(numb)=table2cell(DM.conc2{numb}); excLnNum=excLnNum+1; msg=strcat('NumberOf1:1DrugMediaPlates = ',num2str(numb), ' lastLineNo. = ',num2str(excLnNum)); end @@ -296,28 +296,28 @@ if isequal(Linked,0) % 0 indicates Drugs and Media are combinatorial if ispc while (~isequal(txt{excLnNum,2},'###')) drgCnt=drgCnt+1; - DM.drug(drgCnt) = {raw(excLnNum,2)}; - DM.conc(drgCnt) = {raw(excLnNum,3)}; + DM.drug(drgCnt)={raw(excLnNum,2)}; + DM.conc(drgCnt)={raw(excLnNum,3)}; excLnNum=excLnNum+1; end while (~isequal(txt{excLnNum,4},'###')) medCnt=medCnt+1; - DM.media(medCnt) = {raw(excLnNum,4)}; + DM.media(medCnt)={raw(excLnNum,4)}; excLnNum=excLnNum+1; end else excLnNum=1; while (~isequal(DMcell{excLnNum+1,2},'###')) drgCnt=drgCnt+1; - DM.drug(drgCnt) = {DMtbl(excLnNum,2)}; - DM.conc(drgCnt) = {DMtbl(excLnNum,3)}; + DM.drug(drgCnt)={DMtbl(excLnNum,2)}; + DM.conc(drgCnt)={DMtbl(excLnNum,3)}; excLnNum=excLnNum+1; end while (~isequal(DMcel{excLnNum+1,4},'###')) medCnt=medCnt+1; - DM.media(medCnt) = {DMtbl(excLnNum,4)}; + DM.media(medCnt)={DMtbl(excLnNum,4)}; excLnNum=excLnNum+1; end end diff --git a/workflow/templates/easy/DgenResults.m b/workflow/templates/easy/DgenResults.m index 8247fcfc..1c2d83d1 100755 --- a/workflow/templates/easy/DgenResults.m +++ b/workflow/templates/easy/DgenResults.m @@ -2,12 +2,12 @@ % Updated 240724 Bryan C Roessler to improve file operations and portability % global scansDir -global easyResultsDir global matFile global defImParMat global printResultsDir global fotosResultsDir global pointMapsFile +global pointMapsResultsDir ln=1; @@ -52,6 +52,7 @@ end % localscansDir=scansDir; % end +% TODO this seems weird expNm=scansDir(max(strfind(scansDir,'/'))+1:end); drivePos=min(strfind(scansDir,'/')); drive=scansDir(1:(drivePos-1)); @@ -85,9 +86,9 @@ drgCnt=0; medCnt=0; try - load(fullfile(easyResultsDir,'Fotos','Nbdg')) % Convolute scan array data into plates + load(fullfile(fotosResultsDir,'Nbdg')) % Convolute scan array data into plates catch - load(fullfile(easyResultsDir,'PTmats','Nbdg')) % Convolute scan array data into plates + load(fullfile(pointMapsResultsDir,'Nbdg')) % Convolute scan array data into plates end for s=1:size(scan,2) @@ -102,14 +103,14 @@ for s=1:size(scan,2) for p=1:size((scan(s).plate),2) totPlCnt=totPlCnt+1; if destPerMP>1 && rem(totPlCnt,destPerMP)==1 - mpCnt=mpCnt+1 + mpCnt=mpCnt+1; end if destPerMP==1 - mpCnt=mpCnt+1 + mpCnt=mpCnt+1; end pertCnt=rem(totPlCnt,destPerMP); if pertCnt==0 - pertCnt=destPerMP + pertCnt=destPerMP; end pert=strcat('Perturb_',num2str(pertCnt)); s % TODO seems wrong @@ -365,9 +366,9 @@ if isequal(opt,'DB')||isequal(opt,'Both') try copyfile(DBfilename,DBupload) catch ME - rep = getReport(ME, 'basic'); + rep=getReport(ME, 'basic'); rep=strcat('Failed copyfile to ',DBupload,' -', rep); - errordlg(rep) + errordlg(rep) end end @@ -424,8 +425,8 @@ try asd=cell2mat(scan(s).plate(1).CFparameters{1,1}(1,384)); aucEndPt= strcat('AUC',num2str(asd(9))); end - fprintf(fid, 'Num.\tDiagnostics\tDrug\tConc\tMedia\tModifier1\tConc1\tModifier2\tConc2\tORF\tGene') - fprintf(fid, '\t %s',aucEndPt) + fprintf(fid, 'Num.\tDiagnostics\tDrug\tConc\tMedia\tModifier1\tConc1\tModifier2\tConc2\tORF\tGene'); + fprintf(fid, '\t %s',aucEndPt); fprintf(fid, '\triseTm\tK\tr\tl\tR-squared\tK-lower\tK-upper\tr-lower\tr-upper\tl-lower\tl-upper\tArea\tLastInten\tSplineMaxRateTm\tLastFitTm\t1stFitTm\tMedianBase\tFitBase\tMinTm\tThreshTm\tTotFitPts\tPostThreshFitPts\t1stBackgrd\tLstBackgrd\t1stMeanTotBackgrd\tLstMeanTotBackgrd'); %17_0629 MinBaseIntens update for MedianBase label end clear outTseries @@ -438,7 +439,7 @@ try outIntens=[]; RawIntens=[]; RawIntens=scan(s).plate(p).intens; - RawIntensSize= size(RawIntens,2) + RawIntensSize=size(RawIntens,2); clear Ag; %Ag is Growth Area Ag=scan(s).plate(p).Ag; AgSize= size(Ag); diff --git a/workflow/templates/easy/EASYconsole.m b/workflow/templates/easy/EASYconsole.m index 4353468f..3257376a 100644 --- a/workflow/templates/easy/EASYconsole.m +++ b/workflow/templates/easy/EASYconsole.m @@ -20,6 +20,7 @@ function varargout = EASYconsole(varargin) global mpdmFile global userName global srchRange + global searchRangeFile % Initialize some variables from matlab easyPath=which(mfilename); @@ -115,7 +116,7 @@ function varargout = EASYconsole(varargin) else % Try to find MasterPlate_ file on our own mp=fullfile(scansDir,'MasterPlateFiles',strcat('MasterPlate_', easySuffix,'.xlsx')); - if exist(mp, 'file')) + if exist(mp, 'file') masterPlateFile=mp; disp(strcat('Using drug media file: ', masterPlateFile, ' from internal logic')) else @@ -129,7 +130,7 @@ function varargout = EASYconsole(varargin) else % Try to find MasterPlate_ file on our own dm=fullfile(scansDir,'MasterPlateFiles',strcat('DrugMedia_', easySuffix,'.xlsx')); - if exist(mp, 'file')) + if exist(mp, 'file') drugMediaFile=dm; disp(strcat('Using drug media file: ', drugMediaFile, ' from internal logic')) else @@ -147,16 +148,16 @@ function varargout = EASYconsole(varargin) fotosResultsDir=fullfile(easyResultsDir,'Fotos'); figsResultsDir=fullfile(easyResultsDir,'figs'); pointMapsResultsDir=fullfile(easyResultsDir,'PTmats'); - pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat') - oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat') - CSearchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat'); + pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat'); + oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat'); + searchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat'); mpdmFile=fullfile(matDir,'MPDM.mat'); % This can be removed, I think it should add the previous search range? % Might be nice feature but can remove if it causes issues % We are using searchRangeNum to hold old CSrchRange value(s) - if exist(CSearchRangeFile, 'file') - searchRangeNum=load(CSearchRangeFile); + if exist(searchRangeFile, 'file') + searchRangeNum=load(searchRangeFile); end % Add easyDir to the MATLAB path % I have not idea if this is necessary or works but theoretically should @@ -212,7 +213,6 @@ end % varargin--input arguments to EASYconsole (see VARARGIN) function EASYconsole_OpeningFcn(hObject, ~, handles, varargin) global fhconsole - global easyResultsDir % Choose default command line output for EASYconsole handles.output=hObject; @@ -371,7 +371,7 @@ function LoadDatFile_Callback(~, ~, ~) end % Create supporting dirs - dirs={'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'} + dirs={'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'}; for i=1:length(dirs) d=dirs{i}; if ~exist(fullfile(easyResultsDir, d), 'dir') diff --git a/workflow/templates/easy/NCfitImCFparforFailGbl2.m b/workflow/templates/easy/NCfitImCFparforFailGbl2.m index 1e81b5fa..0952b7b6 100755 --- a/workflow/templates/easy/NCfitImCFparforFailGbl2.m +++ b/workflow/templates/easy/NCfitImCFparforFailGbl2.m @@ -20,18 +20,18 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte par4resMat=zeros(384,27); par4resMatStd=zeros(384,27); - % Spot(cultures) loop - for ii=1:384 %startSpot:numCultures - ii; %%%db print out the culture number + % Spot (cultures) loop + for ii=1:384 % startSpot:numCultures + ii; % db print out the culture number timepts=[]; currValues=[]; currSpotAreas=[]; currSpotArea=[]; dataMatrix=[]; - selTimesStd=[]; %191024 parfor - selIntensStd=[]; %191024 parfor - FiltTimesELr=[]; %191024 parfor - NormIntensELr=[]; %191024 parfor + selTimesStd=[]; % 191024 parfor + selIntensStd=[]; % 191024 parfor + FiltTimesELr=[]; % 191024 parfor + NormIntensELr=[]; % 191024 parfor % add offset...1 offset PER PLATE timepts=times + timeOffsets; % (floor((ii-1)/arrayFormat) + 1); @@ -48,7 +48,7 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte currNormIntens=currValues/currSpotArea; tmpx=find(currNormIntens>5); %15jh % 2.3); validSpot=true; - if(isempty(tmpx) || (length(tmpx)<3)) + if(isempty(tmpx) || length(tmpx)<3) validSpot=false; normIntens=currNormIntens; filterTimes=timepts; %filterTimes; %currTimes; @@ -63,9 +63,9 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte 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; + 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 + Tpt1=0;numFitTpts=0;thresGT2=0;minTime=0;fitbl=0; % diagnostic outputs only timepts=timepts; % timepts=currTimes; parfor normIntens=currNormIntens; @@ -82,7 +82,7 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte threshold=0; end - dropThreshold=-0.0001* max(normIntens); + dropThreshold=-0.0001*max(normIntens); % Initialize dataMatrix dataMatrix(1,:)=timepts; @@ -102,7 +102,7 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte % NCLoIntstdTrim % NCLoSstdTrim.m called by NCfilImCF and NCfil.m flg1=0; - loScurvLim=stdLoIntLim; % + loScurvLim=stdLoIntLim; loStimeN=1; last2n=1; stdDev=[]; @@ -110,26 +110,27 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte for n=1:meanIntIndPt if nrmIntens0(n)<=0 nrmIntens0(n)=0; - end + end if(nrmIntens0(n)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; + dataMatrix(3,1:n)=2; + end + dataMatrix(3,1:(n-2))=2; + last2n=n; + end + if n<(length(nrmIntens0)-3) + x=nrmIntens0(n:(n+3)); + stdDev(n)=std(x); + if (stdDev(n)6 - flg1=1 - end % detect S curve rise->stop stdLoInt detection - end + flg1=1; + end + end end % TODO repetitive code @@ -142,14 +143,14 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte qcutoff=2; qind=find(normIntens>2); %,:,'first'); if ~isempty(qind(3)) - qcutoff=qind(3) + qcutoff=qind(3); end [minInt,I]=min(normIntens(2:qcutoff)); bl=minInt; - minTime=dataMatrix(1,I); %diagnostic output only + minTime=dataMatrix(1,I); if (length(qind)>5)&&I>1 - dataMatrix(3,1:(I-1))=5 + dataMatrix(3,1:(I-1))=5; end tGT2Flg=0; @@ -157,7 +158,7 @@ function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanInte dataMatrix(4,n)=normIntens(n)-bl; if n>I && dataMatrix(4,n)>=2 && tGT2Flg==0 thresGT2=n;thresGT2Tm=dataMatrix(1,n);tGT2Flg=1; - end %diagnostic output only + end end resMat(18)=bl; diff --git a/workflow/templates/easy/NCscurImCF_3parfor.m b/workflow/templates/easy/NCscurImCF_3parfor.m index f557671b..d7f5ea45 100755 --- a/workflow/templates/easy/NCscurImCF_3parfor.m +++ b/workflow/templates/easy/NCscurImCF_3parfor.m @@ -86,7 +86,7 @@ function [resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntens if(isnan(Klow)||isnan(Kup)||isnan(llow)||isnan(lup)||isnan(rlow)||isnan(rup)) NANcond=1; stdNANcond=1; % stdNANcond added to relay not to attempt ELr as there is no curve to find critical point end - catch ME + catch % if no data is given, return zeros AUC=0;MSR=0;K=0;r=0;l=0;rsquare=0;Klow=0;Kup=0; rlow=0;rup=0;lup=0;llow=0; @@ -222,7 +222,7 @@ function [resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntens GrowthELr=K ./ (1 + exp(-r.* (t - l ))); fitblELr=min(GrowthELr); %jh diag end - catch ME + catch % if no data is given, return zeros AUC=0;MSR=0;K=0;r=0;l=0;rsquare=0;Klow=0;Kup=0; rlow=0;rup=0;lup=0;llow=0; %normIntens=[]; @@ -290,7 +290,7 @@ function [resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntens resMat(19)=fitblStd; % only applicable to Std curve Fit; ELr superceeds and makes meaningless resMat(20)=minTime; % only applicable to Std curve Fit; ELr superceeds and makes meaningless end % if r3>r1 - catch ME + catch % if no data is given, return zeros AUC=0;MSR=0;K=0;r=0;l=0;rsquare=0;Klow=0;Kup=0; rlow=0;rup=0;lup=0;llow=0; % normIntens=[]; diff --git a/workflow/templates/easy/NImParamRadiusGui.m b/workflow/templates/easy/NImParamRadiusGui.m index d9976c07..09a79b0a 100755 --- a/workflow/templates/easy/NImParamRadiusGui.m +++ b/workflow/templates/easy/NImParamRadiusGui.m @@ -21,6 +21,7 @@ function NImParamRadiusGui(scansDir) global numCols global scanSize global scanMax + global searchRangeFile % Ncode ImRobot adaptation % TODO this code block and variables needs explanation @@ -38,17 +39,17 @@ function NImParamRadiusGui(scansDir) selScan=1; SWgrowthArea=1; - if exist(pointMapsFile) + if exist(pointMapsFile, 'file') load(pointMapsFile); else load(fullfile(PTmats,'NImParameters')) % hardcoded default disp('WARNING: Using hardcoded NImParameters.mat') end - ImParMat + ImParMat; % if ~exist('searchRangeNum','var') || isempty(searchRangeNum) - if exist(CSearchRangeFile), 'file') - load(CSearchRangeFile); - CSearchRange; + if exist(searchRangeFile, 'file') + load(searchRangeFile); + CSearchRange; % TODO, might be an issue, figure out what this is doing end % yInitPos=0.30; @@ -117,6 +118,8 @@ function NImParamRadiusGui(scansDir) btnNumber=7; yPos=0.85-(btnNumber-1)*(btnHt+spacing); btnPos=[xPos yPos-spacing btnWid btnHt]; + + % TODO, I don't think these are defined? try srchRange=ImParMat(12); catch % Legacy default value was 18 before being made a user input variable (ImParMat(12)). A preferable value now might be 12 or 14. @@ -164,7 +167,6 @@ function NImParamRadiusGui(scansDir) 'callback',{@load_listbox}); %'uiresume(gcbf)'); 'Position', [5 100 60 20]) function load_listbox(source,~) - global userIndx=(get(source,'value')); userStr=(get(source,'string')); %scLstIndx=str2num(char(strrep(userStr(userIndx), 'Scan', ''))) @@ -239,7 +241,7 @@ function NImParamRadiusGui(scansDir) searchRangeNum; save(pointMapsFile, 'ImParMat'); - save(CSearchRangeFile,'searchRangeNum'); + save(searchRangeFile,'searchRangeNum'); close return diff --git a/workflow/templates/easy/NIscanIntensBGpar4GblFnc.m b/workflow/templates/easy/NIscanIntensBGpar4GblFnc.m index 0d6ad8dc..16fa386c 100755 --- a/workflow/templates/easy/NIscanIntensBGpar4GblFnc.m +++ b/workflow/templates/easy/NIscanIntensBGpar4GblFnc.m @@ -1,15 +1,16 @@ %% CALLED BY par4GblFnc8c.m %% function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, TmpFexpScanSpots2, TmpFexpScanBMtp2, TmpanlZoneRefs2,areaOfIntensAboveBG]= ... - NIscanIntensBGpar4GblFnc(Fflg, tifFileLst, ImParMat,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,numRows,numCols,ImHeigth,ImWidth,cirMask, ... - tptLength,selScan,Empsc,~, ~, ~, ~,easyResultsDir, Tmpsbdg1) + NIscanIntensBGpar4GblFnc(Fflg, tifFileLst, ImParMat,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,numRows,numCols,ImHeigth,ImWidth,cirMask, ... + tptLength,selScan,Empsc,~, ~, ~, ~,easyResultsDir, Tmpsbdg1) global matFile global CSrchRng global figsResultsDir global fotosResultsDir - searchIntens=[]; intensMax=[]; detMaxPos=[]; scIntens=[]; areaOfIntensAboveBG=[]; BkgrdMat=[]; + searchIntens=[];intensMax=[];detMaxPos=[];scIntens=[];areaOfIntensAboveBG=[];BkgrdMat=[]; + % TODO needs explanation if Fflg==1 % Preallocation tPtLength=length(tifFileLst); @@ -133,7 +134,7 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, MaxANDVal=0; % sum(sum(BWimage(:,:))); %seed MaxANDVal from the BWimage regDith=4; TestmapOnesDbl=zeros(2075,1400); - + % Create a Search Range centered on C==1 and R==1 of the PinTool map RtopBndry=96; RbotBndry=176; ClfBndry=96; CrtBndry=154; @@ -169,7 +170,7 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, testPosC=PTrefPt(2) + shiftPosC; a=[testPosR,testPosC]; %testPos(r,c)={testPosR,testPosC}; testPos(r,c)={a}; - doCircle + doCircle; TestmapOnesDbl(testPosR:(testPosR+(diaExt-1)),testPosC:(testPosC+(diaExt-1)))=cirMask; %optCirMask; end end @@ -222,7 +223,7 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, MaxPosSkDbl=TestmapSkDbl; end end - end + end if MaxANDValSk> MaxANDVal MaxANDVal=MaxANDValSk; @@ -299,11 +300,11 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, if ANDValCent>=MaxANDVal MaxPosDbl=lastDetMaxCentDbl; MaxPos=lastDetMaxPos; - %detPos=lastDetMaxPos; + % detPos=lastDetMaxPos; end - %detPos=lastDetMaxPos; + % detPos=lastDetMaxPos; detPos=MaxPos; - end %if length(tifFileLst) >2 + end % Preallocation for speed on 2019_1121 *** scIntens=zeros(24,16,length(tifFileLst)); @@ -361,9 +362,9 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, else % standard square analysis area refPtRExt=refPtR+widthEx; if (refPtRExt)> size(fIntsc,1), refPtRExt=size(fIntsc,1); end - refPtCExt=refPtC+widthEx; + refPtCExt=refPtC+widthEx; if (refPtCExt)> size(fIntsc,2), refPtCExt=size(fIntsc,2); end - zeroSearchIntens=sum(sum(fIntsc(refPtR:(refPtRExt),refPtC:(refPtCExt)))); + zeroSearchIntens=sum(sum(fIntsc(refPtR:(refPtRExt),refPtC:(refPtCExt)))); end % clear ('searchIntens') searchIntens=[]; @@ -514,678 +515,711 @@ function [Tmpsbdg2, scanIntens, F_spots, bmtp, optomizedPos, TmpexpScanIntens2, end end - % [F_spots,bmtp, BGthres,bmm,rwm,lstTpt,BGsc,totBkgrd]=... - % NIgenBkGrdDataPar4Fnc(ImParMat, tifFileLst, lastDetMaxPos, numRows, numCols, fullsc, tPt,BGthres, doCircle, cirPixA,diaExt, cirMask, BGTav); - % NIgenBkGrdDataPar4Fnc - % function [F_spots,bmtp, BGthres,bmm,rwm,lstTpt,BGsc,totBkgrd ]=... - % NIgenBkGrdDataPar4Fnc(ImParMat, tifFileLst, lastDetMaxPos, numRows, numCols, fullsc, tPt, BGthres, doCircle, cirPixA, diaExt, cirMask, BGTav) - % Called by NIscanIntensBG.m - - % global easyResultsDir - global matFile - % global pixsAboveBG - MPnum=ImParMat(1); - destPerMP=ImParMat(2); - spotThres=ImParMat(4)/100; %selScan=ImParMat(4); - width=ImParMat(5); - dither=ImParMat(6); - BGthresInput=ImParMat(3); % a value of percent to be added (20=>1.20*BGTav) - lstTpt=length(tifFileLst); - LfOffset=65; %lf; %Ncode - TopOffset=65; %tp; - rtLim=1350; %1400; %1350; - rtNotchOffset=10; - cushion=20; - % close2edgeTol=90; - botLim=2003; - botNotchOffset=60; - - % Initialize - % clear('totBkgrd') - % clear('pixsAboveBG') - % clear('lineV','pixCnt','lineSum,meanBkgrd') - % clear('rw','rwm') - totBkgrd=0; - pixsAboveBG=0; - lineV=0; pixCnt=0; lineSum=0; meanBkgrd=85; - rw=0; rwm=0; - % Start Generation of BackGround data after the 2nd Row (&& 2nd Col) - % Optimized spot positions determined - %if r>=2 && c>=2, - BGsc=zeros(2075,1400); %Empsc; - widthEx=width-1; %width extention from reference point - for r=1:numRows - for c=1:numCols - refP=lastDetMaxPos{r,c}; - if r1, refPrR=lastDetMaxPos{r-1,c}; end - if c>1, refPrC=lastDetMaxPos{r,c-1}; end - - % At least NINE conditions which must be treated differently - % Condition 0: most spots fall in this central category - if r>1 && r1 && c0 - refBG(1)=refP(1)- floor(0.5*(refP(1) - TopOffset)); - refBG(2)=refP(2)- floor(0.5*(refP(2) - LfOffset)); % Icode -0 - refBG(3)=refP(1)+widthEx+ floor(0.5*((refNxR(1)-(refP(1)+widthEx)))); - refBG(4)=refP(2)+widthEx+ floor(0.5*((refNxC(2)-(refP(2)+widthEx)))); - detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell - % clear('lineV','pixCnt','lineSum') - lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); %mean across top rt - if tPt==1 || tPt==lstTpt,rw=lineV';end - pixCnt(1)=nnz(lineV .* uint8(lineV1 && c(size(fullsc,2)-close2edgeTol)%if intens area too close to edge - if refBGcExt>(rtLim-cushion)%if intens area too close to edge - refBG(4)=rtLim-rtNotchOffset; - else - refBG(4)=refP(2)+widthEx+ floor(0.5*(rtLim-refBGcExt)); - end - detBG(r,c)={uint8(refBG)}; %Store Background Reference pt data in a Cell - % clear('lineV','pixCnt','lineSum') - lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt - if tPt==1 || tPt==lstTpt,rw=lineV';end - pixCnt(1)=nnz(lineV .* uint8(lineV(size(fullsc,2)-close2edgeTol) %if intens area too close to edge - if refBGcExt>(rtLim-cushion) %if intens area too close to edge - meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); - if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end - % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(4))./ ... - % ((2*(refBG(4)-refBG(2))+(refBG(3)-refBG(1)))); %divby 2*across+1*down - if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end - else - % clear('lineV') %3 - lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); %mean down rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end - pixCnt(3)=nnz(lineV .* uint8(lineV47 farRight col edge - if r>1 && r(botLim-botNotchOffset)%if intens area not too close to bot edge else - refBG(3)=botLim + cushion; - else - refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); - end - if refBGcExt>(rtLim- cushion)%if intens area not too close to edge else - refBG(4)=rtLim -cushion; - else - refBG(4)=refP(2)+widthEx+ floor(0.5*(rtLim-refBGcExt)); - end - detBG(r,c)={uint8(refBG)}; %Store Background Reference pt data in a Cell - - % clear('lineV','pixCnt','lineSum') %1 - lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt - if tPt==1 || tPt==lstTpt,rw=lineV';end - pixCnt(1)=nnz(lineV .* uint8(lineV1.20*BGTav) + lstTpt=length(tifFileLst); + LfOffset=65; %lf; %Ncode + TopOffset=65; %tp; + rtLim=1350; %1400; %1350; + rtNotchOffset=10; + cushion=20; + % close2edgeTol=90; + botLim=2003; + botNotchOffset=60; - % if refBGcExt>(size(fullsc,2)-close2edgeTol)&&... - if refBGcExt>(rtLim-cushion)&&... - refBGrExt<(botLim-botNotchOffset) % if intens area too close to right edge only - % clear('lineV') %4 - lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); % mean across bot rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end - pixCnt(4)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) && ... - refBGcExt>(rtLim-cushion)%if intens area too close to bottom edge only - % clear('lineV') %3 - lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); % mean down rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end - pixCnt(3)=nnz(lineV .* uint8(lineV(size(fullsc,2)-close2edgeTol)&& ... - elseif refBGcExt>(rtLim-cushion)&& ... - refBGrExt>(botLim-botNotchOffset) % if intens area too close to both right edge and bottom edge - meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); - if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end - % meanBkgrd=(lineSum(1)+lineSum(2))./ ... - % ((refBG(4)-refBG(2)+(refBG(3)-refBG(1)))); %divby 1across+1*down - if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end - else - % clear('lineV') %3 - lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); %mean down rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end - pixCnt(3)=nnz(lineV .* uint8(lineV1 && c(botLim-botNotchOffset) % if intens area not too close to bot edge else - refBG(3)=botLim + cushion; - else - refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); - end - if rem(c,numCols)==0 - refBG(4)=refP(2)+widthEx+ floor(0.5*(plateEdgeSpace)); - else - refBG(4)=refP(2)+widthEx+ floor(0.5*(refNxC(2)-(refP(2)+widthEx))); - %refBG(4)=refP(2)+widthEx+ floor(0.5*(size(fullsc,2)-refBGcExt)); - end - detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell - % clear('lineV','pixCnt','lineSum') %1 - lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt - if tPt==1 || tPt==lstTpt,rw=lineV';end - pixCnt(1)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area too close to bottom edge - meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); - if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end - % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(4))./ ... - % ((refBG(4)-refBG(2)+(2*(refBG(3)-refBG(1))))); %divby 1*across+2*down - if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end - else - % clear('lineV') %4 - lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); % mean across bot rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end - pixCnt(4)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area not too close to bot edge else - refBG(3)=botLim + cushion; - else - refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); - end - refBG(4)=refP(2)+widthEx+ floor(0.5*(refNxC(2)-(refP(2)+widthEx))); - detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell - % clear('lineV','pixCnt','lineSum') %1 - lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt - if tPt==1 || tPt==lstTpt,rw=lineV';end - pixCnt(1)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area too close to bottom edge - meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); - if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end - % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(3))./ ... - % ((refBG(4)-refBG(2)+(2*(refBG(3)-refBG(1))))); % divby 1*across+2*down - if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end - else - % clear('lineV') %4 - lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); %mean across bot rt - if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end - pixCnt(4)=nnz(lineV .* uint8(lineV1 && rBG); %calc non-background within circular analysis area - % pixsAboveBG(r,c)=nnz(fullsc(refPtRx:(refPtRx+ (diaExt-1)),refPtCx:(refPtCx+ (diaExt-1)))>BG); %BG); - else % standard square analysis area - pixsAboveBG(r,c)=nnz(fullsc(refPtRx:(refPtRx+widthEx),refPtCx:(refPtCx+widthEx))>BG); % calc non-background within square analysis area - end - - % TimePT average - % meanBGTsum(r,c)=meanBGTsum(r,c)+meanBkgrd; - % meanBGTav(r,c)=meanBGTsum(r,c) /tPt; - bmm(r,c)=uint8(floor(meanBkgrd)); - - % For FOTOS only - F_spots(r,c,tPt)={refBG}; % Foto spot coordinates - bmtp(r,c,tPt)=bmm(r,c); % Added/used for FOTOS 11_0830 - - % TimePT Average BG intensity calc method - BGTav(r,c)=uint8(round((BGTav(r,c)*(tPt-1))+meanBkgrd)/tPt); - % BGTav(r,c)=((BGTav(r,c)*(tPt-1))+meanBkgrd)/tPt; - - % sliding BG average - % if r==1 && c==1, slavg(1:5)=BG;end % slavg(1:5)=50; %120620 Epsonvalue is 33; end - % slavg(5)=slavg(4); - % slavg(4)=slavg(3); - % slavg(3)=slavg(2); - % slavg(2)=slavg(1); - % slavg(1)=BG; - % slidingAvg=mean(slavg); - - % For Visualization Purposes only - %1->2 across rt 1, 2-4 - BGsc(refBG(1),refBG(2):refBG(4))=1; - %1->4 down lf 1-3, 2 - BGsc(refBG(1):refBG(3),refBG(2))=1; - %2->3 down rt 1-3, 4 - BGsc(refBG(1):refBG(3),refBG(4))=1; - %4->3 Bot Across rt 1, 2-4 - BGsc(refBG(3),refBG(2):refBG(4))=1; - % BGsc(refBG(1):refBG(3),refBG(2):refBG(4)) %just displays matrices - end - end - - BGthres=uint8(double(BGTav) * (1+(BGthresInput/100))); - optomizedPos(:,:,tPt)=lastDetMaxPos; - % if(isequal(SWsingleSc,1))|| ((~isequal(SWsingleSc,1))&&tPt==tptLength) %190731 change to capture last timePt PTmap if(isequal(SWsingleSc,1)) - % if(isequal(SWsingleSc,1))&& (tPt==1 || tPt==guesTpt || tPt==tptLength)|| ((~isequal(SWsingleSc,1))&&tPt==tptLength) %190919 Option for observation - % if (tPt==1 || tPt==guesTpt || tPt==tptLength) %190919 Option for observation - if (tPt==tptLength) % 190919 change to capture ONLY last timePt PTmap - % clear OptmapOnes; - OptmapOnes=[]; - % OptmapOnes=Empsc+ 1.4; - OptmapOnesDbl=double(Empsc)+ .8; - for r=1:numRows + % Initialize + % clear('totBkgrd') + % clear('pixsAboveBG') + % clear('lineV','pixCnt','lineSum,meanBkgrd') + % clear('rw','rwm') + totBkgrd=0; + pixsAboveBG=0; + lineV=0; pixCnt=0; lineSum=0; meanBkgrd=85; + rw=0; rwm=0; + % Start Generation of BackGround data after the 2nd Row (&& 2nd Col) + % Optimized spot positions determined + %if r>=2 && c>=2, + BGsc=zeros(2075,1400); %Empsc; + widthEx=width-1; %width extention from reference point + for r=1:numRows for c=1:numCols - [refPt]=lastDetMaxPos{r,c}; - refPtR=refPt(1); - refPtC=refPt(2); - if doCircle==1 - %OptmapOnesDbl(refPtR:(refPtR+diaExt),refPtC:(refPtC+diaExt))=cirMask; - OptmapOnesDbl(refPtR:(refPtR+(diaExt-1)),refPtC:(refPtC+(diaExt-1)))=optCirMask; - else - refPtRExt=refPtR+widthEx; - if (refPtRExt)> size(fullsc,1), refPtRExt=size(fullsc,1); end - refPtCExt=refPtC+widthEx; - if (refPtCExt)> size(fullsc,2), refPtCExt=size(fullsc,2); end - OptmapOnesDbl(refPtR:(refPtRExt),refPtC:(refPtCExt))=1;%255; + refP=lastDetMaxPos{r,c}; + if r1, refPrR=lastDetMaxPos{r-1,c}; end + if c>1, refPrC=lastDetMaxPos{r,c-1}; end + + % At least NINE conditions which must be treated differently + % Condition 0: most spots fall in this central category + if r>1 && r1 && c0 + refBG(1)=refP(1)- floor(0.5*(refP(1) - TopOffset)); + refBG(2)=refP(2)- floor(0.5*(refP(2) - LfOffset)); % Icode -0 + refBG(3)=refP(1)+widthEx+ floor(0.5*((refNxR(1)-(refP(1)+widthEx)))); + refBG(4)=refP(2)+widthEx+ floor(0.5*((refNxC(2)-(refP(2)+widthEx)))); + detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell + % clear('lineV','pixCnt','lineSum') + lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); %mean across top rt + if tPt==1 || tPt==lstTpt,rw=lineV';end + pixCnt(1)=nnz(lineV .* uint8(lineV1 && c(size(fullsc,2)-close2edgeTol)%if intens area too close to edge + if refBGcExt>(rtLim-cushion)%if intens area too close to edge + refBG(4)=rtLim-rtNotchOffset; + else + refBG(4)=refP(2)+widthEx+ floor(0.5*(rtLim-refBGcExt)); + end + detBG(r,c)={uint8(refBG)}; %Store Background Reference pt data in a Cell + % clear('lineV','pixCnt','lineSum') + lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt + if tPt==1 || tPt==lstTpt,rw=lineV';end + pixCnt(1)=nnz(lineV .* uint8(lineV(size(fullsc,2)-close2edgeTol) %if intens area too close to edge + if refBGcExt>(rtLim-cushion) %if intens area too close to edge + meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); + if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end + % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(4))./ ... + % ((2*(refBG(4)-refBG(2))+(refBG(3)-refBG(1)))); %divby 2*across+1*down + if doCircle==1 + totBkgrd(r,c)=meanBkgrd* cirPixA; + else + totBkgrd(r,c)=meanBkgrd* width^2; + end + else + % clear('lineV') %3 + lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); %mean down rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end + pixCnt(3)=nnz(lineV .* uint8(lineV47 farRight col edge + if r>1 && r(botLim-botNotchOffset)%if intens area not too close to bot edge else + refBG(3)=botLim + cushion; + else + refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); + end + if refBGcExt>(rtLim- cushion)%if intens area not too close to edge else + refBG(4)=rtLim -cushion; + else + refBG(4)=refP(2)+widthEx+ floor(0.5*(rtLim-refBGcExt)); + end + detBG(r,c)={uint8(refBG)}; %Store Background Reference pt data in a Cell + + % clear('lineV','pixCnt','lineSum') %1 + lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt + if tPt==1 || tPt==lstTpt,rw=lineV';end + pixCnt(1)=nnz(lineV .* uint8(lineV(size(fullsc,2)-close2edgeTol)&&... + if refBGcExt>(rtLim-cushion)&&... + refBGrExt<(botLim-botNotchOffset) % if intens area too close to right edge only + % clear('lineV') %4 + lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); % mean across bot rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end + pixCnt(4)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) && ... + refBGcExt>(rtLim-cushion)%if intens area too close to bottom edge only + % clear('lineV') %3 + lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); % mean down rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end + pixCnt(3)=nnz(lineV .* uint8(lineV(size(fullsc,2)-close2edgeTol)&& ... + elseif refBGcExt>(rtLim-cushion)&& ... + refBGrExt>(botLim-botNotchOffset) % if intens area too close to both right edge and bottom edge + meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); + if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end + % meanBkgrd=(lineSum(1)+lineSum(2))./ ... + % ((refBG(4)-refBG(2)+(refBG(3)-refBG(1)))); %divby 1across+1*down + if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end + else + % clear('lineV') %3 + lineV=fullsc(refBG(1):refBG(3)-1,refBG(4)); %mean down rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV];end + pixCnt(3)=nnz(lineV .* uint8(lineV1 && c(botLim-botNotchOffset) % if intens area not too close to bot edge else + refBG(3)=botLim + cushion; + else + refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); + end + if rem(c,numCols)==0 + refBG(4)=refP(2)+widthEx+ floor(0.5*(plateEdgeSpace)); + else + refBG(4)=refP(2)+widthEx+ floor(0.5*(refNxC(2)-(refP(2)+widthEx))); + %refBG(4)=refP(2)+widthEx+ floor(0.5*(size(fullsc,2)-refBGcExt)); + end + detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell + % clear('lineV','pixCnt','lineSum') %1 + lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt + if tPt==1 || tPt==lstTpt,rw=lineV';end + pixCnt(1)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area too close to bottom edge + meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); + if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end + % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(4))./ ... + % ((refBG(4)-refBG(2)+(2*(refBG(3)-refBG(1))))); %divby 1*across+2*down + if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end + else + % clear('lineV') %4 + lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); % mean across bot rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end + pixCnt(4)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area not too close to bot edge else + refBG(3)=botLim + cushion; + else + refBG(3)=refP(1)+widthEx+ floor(0.5*(botLim-refBGrExt)); + end + refBG(4)=refP(2)+widthEx+ floor(0.5*(refNxC(2)-(refP(2)+widthEx))); + detBG(r,c)={uint8(refBG)}; % Store Background Reference pt data in a Cell + % clear('lineV','pixCnt','lineSum') %1 + lineV=fullsc(refBG(1),refBG(2):refBG(4)-1); % across top rt + if tPt==1 || tPt==lstTpt,rw=lineV';end + pixCnt(1)=nnz(lineV .* uint8(lineV(botLim-botNotchOffset) % if intens area too close to bottom edge + meanBkgrd=(sum(lineSum(1:4)))./ (sum(pixCnt(1:4))); + if sum(pixCnt(1:4))==0, meanBkgrd=double(BGthres(r,c));end + % meanBkgrd=(lineSum(1)+lineSum(2)+lineSum(3))./ ... + % ((refBG(4)-refBG(2)+(2*(refBG(3)-refBG(1))))); % divby 1*across+2*down + if doCircle==1, totBkgrd(r,c)=meanBkgrd* cirPixA; else totBkgrd(r,c)=meanBkgrd* width^2; end + else + % clear('lineV') %4 + lineV=fullsc(refBG(3),refBG(2):refBG(4)-1); %mean across bot rt + if tPt==1 || tPt==lstTpt,rw=[rw;lineV'];end + pixCnt(4)=nnz(lineV .* uint8(lineV1 && rBG); %calc non-background within circular analysis area + % pixsAboveBG(r,c)=nnz(fullsc(refPtRx:(refPtRx+ (diaExt-1)),refPtCx:(refPtCx+ (diaExt-1)))>BG); %BG); + else % standard square analysis area + pixsAboveBG(r,c)=nnz(fullsc(refPtRx:(refPtRx+widthEx),refPtCx:(refPtCx+widthEx))>BG); % calc non-background within square analysis area + end + + % TimePT average + % meanBGTsum(r,c)=meanBGTsum(r,c)+meanBkgrd; + % meanBGTav(r,c)=meanBGTsum(r,c) /tPt; + bmm(r,c)=uint8(floor(meanBkgrd)); + + % For FOTOS only + F_spots(r,c,tPt)={refBG}; % Foto spot coordinates + bmtp(r,c,tPt)=bmm(r,c); % Added/used for FOTOS 11_0830 + + % TimePT Average BG intensity calc method + BGTav(r,c)=uint8(round((BGTav(r,c)*(tPt-1))+meanBkgrd)/tPt); + % BGTav(r,c)=((BGTav(r,c)*(tPt-1))+meanBkgrd)/tPt; + + % sliding BG average + % if r==1 && c==1, slavg(1:5)=BG;end % slavg(1:5)=50; %120620 Epsonvalue is 33; end + % slavg(5)=slavg(4); + % slavg(4)=slavg(3); + % slavg(3)=slavg(2); + % slavg(2)=slavg(1); + % slavg(1)=BG; + % slidingAvg=mean(slavg); + + % For Visualization Purposes only + %1->2 across rt 1, 2-4 + BGsc(refBG(1),refBG(2):refBG(4))=1; + %1->4 down lf 1-3, 2 + BGsc(refBG(1):refBG(3),refBG(2))=1; + %2->3 down rt 1-3, 4 + BGsc(refBG(1):refBG(3),refBG(4))=1; + %4->3 Bot Across rt 1, 2-4 + BGsc(refBG(3),refBG(2):refBG(4))=1; + % BGsc(refBG(1):refBG(3),refBG(2):refBG(4)) %just displays matrices end end - % Cross-optimized Map Matrix onto tifFile Matrix - % For visualization purposes only - if tPt==1,figure;end - resIm=uint8((double(BGsc) + OptmapOnesDbl) .* double(fullsc)); - % clear('OptmapOnesDbl') - OptmapOnesDbl=[]; - % hres=imagesc(resIm); - hfscanIm=imagesc(resIm); - hfIm=gcf; - haxis=gca; - title(strcat('Scan',num2str(selScan),'timePt-',num2str(tPt))); - clf(hfscanIm,'reset'); - set(hfIm,'NumberTitle','off') - set(hfIm,'Name', char(matFile)) % strcat('EASYconsole- ',char(easyResultsDir))) - if Fflg==1 - fullfile(fotosResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt))) - hgsave(fullfile(fotosResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt)))); %F 14_0626 + BGthres=uint8(double(BGTav) * (1+(BGthresInput/100))); + optomizedPos(:,:,tPt)=lastDetMaxPos; + % if(isequal(SWsingleSc,1))|| ((~isequal(SWsingleSc,1))&&tPt==tptLength) %190731 change to capture last timePt PTmap if(isequal(SWsingleSc,1)) + % if(isequal(SWsingleSc,1))&& (tPt==1 || tPt==guesTpt || tPt==tptLength)|| ((~isequal(SWsingleSc,1))&&tPt==tptLength) %190919 Option for observation + % if (tPt==1 || tPt==guesTpt || tPt==tptLength) %190919 Option for observation + if (tPt==tptLength) % 190919 change to capture ONLY last timePt PTmap + % clear OptmapOnes; + OptmapOnes=[]; + % OptmapOnes=Empsc+ 1.4; + OptmapOnesDbl=double(Empsc)+ .8; + for r=1:numRows + for c=1:numCols + [refPt]=lastDetMaxPos{r,c}; + refPtR=refPt(1); + refPtC=refPt(2); + if doCircle==1 + % OptmapOnesDbl(refPtR:(refPtR+diaExt),refPtC:(refPtC+diaExt))=cirMask; + OptmapOnesDbl(refPtR:(refPtR+(diaExt-1)),refPtC:(refPtC+(diaExt-1)))=optCirMask; + else + refPtRExt=refPtR+widthEx; + if (refPtRExt)> size(fullsc,1), refPtRExt=size(fullsc,1); end + refPtCExt=refPtC+widthEx; + if (refPtCExt)> size(fullsc,2), refPtCExt=size(fullsc,2); end + OptmapOnesDbl(refPtR:(refPtRExt),refPtC:(refPtCExt))=1;%255; + end + end + end + + % Cross-optimized Map Matrix onto tifFile Matrix + % For visualization purposes only + if tPt==1,figure;end + resIm=uint8((double(BGsc) + OptmapOnesDbl) .* double(fullsc)); + % clear('OptmapOnesDbl') + OptmapOnesDbl=[]; + % hres=imagesc(resIm); + hfscanIm=imagesc(resIm); + hfIm=gcf; + haxis=gca; + title(strcat('Scan',num2str(selScan),'timePt-',num2str(tPt))); + clf(hfscanIm,'reset'); + set(hfIm,'NumberTitle','off') + set(hfIm,'Name', char(matFile)) % strcat('EASYconsole- ',char(easyResultsDir))) + if Fflg==1 + fullfile(fotosResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt))) + hgsave(fullfile(fotosResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt)))); %F 14_0626 + else + hgsave(fullfile(figsResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt)))); + end else - hgsave(fullfile(figsResultsDir,strcat('Scan',num2str(selScan),'_timePt-',num2str(tPt)))); + selScan; + % tifFile end - else - selScan; - % tifFile - end - BkgrdMat=totBkgrd; % BkgrdMat(:,:,tPt)=totBkgrd; %debug parfor effort - areaOfIntensAboveBG(:,:,tPt)=pixsAboveBG; % actual area of growth for each timepoint (used for printout of grArea ?not used in previous analysis) - scanIntens(:,:,tPt)=intens-BkgrdMat; + BkgrdMat=totBkgrd; % BkgrdMat(:,:,tPt)=totBkgrd; %debug parfor effort + areaOfIntensAboveBG(:,:,tPt)=pixsAboveBG; % actual area of growth for each timepoint (used for printout of grArea ?not used in previous analysis) + scanIntens(:,:,tPt)=intens-BkgrdMat; - % Capture first and last background values - if tPt==1 - bdg(:,:,1)=bmm; - bdg(:,:,3)=rwm; - Tmpsbdg1={bdg}; - end - if tPt==lstTpt - bdg(:,:,2)=bmm; - bdg(:,:,4)=rwm; - Tmpsbdg1={bdg}; - end + % Capture first and last background values + if tPt==1 + bdg(:,:,1)=bmm; + bdg(:,:,3)=rwm; + Tmpsbdg1={bdg}; + end + if tPt==lstTpt + bdg(:,:,2)=bmm; + bdg(:,:,4)=rwm; + Tmpsbdg1={bdg}; + end - TmpexpScanIntens1={scanIntens}; % par4Gbl 20_0122 - TmpFexpScanSpots1={F_spots}; - TmpFexpScanBMtp1={bmtp}; - TmpanlZoneRefs1={optomizedPos}; % added to store tPt by tPt positions - TmpexpScanIntens2=TmpexpScanIntens1; - TmpFexpScanSpots2=TmpFexpScanSpots1; - TmpFexpScanBMtp2=TmpFexpScanBMtp1; - TmpanlZoneRefs2=TmpanlZoneRefs1; - Tmpsbdg2=Tmpsbdg1; - + TmpexpScanIntens1={scanIntens}; % par4Gbl 20_0122 + TmpFexpScanSpots1={F_spots}; + TmpFexpScanBMtp1={bmtp}; + TmpanlZoneRefs1={optomizedPos}; % added to store tPt by tPt positions + TmpexpScanIntens2=TmpexpScanIntens1; + TmpFexpScanSpots2=TmpFexpScanSpots1; + TmpFexpScanBMtp2=TmpFexpScanBMtp1; + TmpanlZoneRefs2=TmpanlZoneRefs1; + Tmpsbdg2=Tmpsbdg1; + end end \ No newline at end of file diff --git a/workflow/templates/easy/par4GblFnc8c.m b/workflow/templates/easy/par4GblFnc8c.m index 63833085..7df84c91 100755 --- a/workflow/templates/easy/par4GblFnc8c.m +++ b/workflow/templates/easy/par4GblFnc8c.m @@ -40,7 +40,7 @@ function [p4L2, TmpexpScanIntens3,TmpFexpScanSpots3,TmpFexpScanBMtp3,TmpanlZoneR fFail=((fullfile(printResultsDir,'ImageFileReadFailure.txt'))); fid=fopen(fFail,'a'); %create,open and append % fprintf(fid,'%s \n',char(tifFile)) - fclose(fid) + fclose(fid); nndx=nndx-1; swCatch=1; rep=getReport(ME, 'basic'); @@ -158,8 +158,8 @@ function [p4L2, TmpexpScanIntens3,TmpFexpScanSpots3,TmpFexpScanBMtp3,TmpanlZoneR end locIndx=0; Ag=zeros(1,384); - for m=1:16 %N code change from 16 %Vert back to 16 - for n=1:24 %Ncode change from 24 %Vert back to 24 + for m=1:16 % Ncode change from 16 %Vert back to 16 + for n=1:24 % Ncode change from 24 %Vert back to 24 growthArea=max(grArea(n,m,:,1)); if SWprint==1 fprintf(fid,'%3.f\n',growthArea); @@ -294,7 +294,7 @@ function [p4L2, TmpexpScanIntens3,TmpFexpScanSpots3,TmpFexpScanBMtp3,TmpanlZoneR p4L1{16}=selScan; p4L1{17}=cirPixA; - p4L1{18}=datestr((now),31); + p4L1{18}=datestr((now),31); % TODO this seems bad p4L2=p4L1; end diff --git a/workflow/templates/easy/par4Gbl_Main8c.m b/workflow/templates/easy/par4Gbl_Main8c.m index a60015eb..02b5b2a4 100755 --- a/workflow/templates/easy/par4Gbl_Main8c.m +++ b/workflow/templates/easy/par4Gbl_Main8c.m @@ -100,9 +100,9 @@ NIcircle lastPlateOnLastScan=1; % Ncode if size(scLst,1)==1 - SWsingleSc=1 + SWsingleSc=1; else - SWsingleSc=0 + SWsingleSc=0; end dvec=datevec(datestr(floor(now))); %method to get current offset year '01-Jan-"currentyr"' @@ -220,10 +220,10 @@ end % Save data in .mat files save(matFile,'scan'); % save((fullfile(easyResultsDir,'PTmats','Nbdg')), 'sbdg'); %legacy location can probably get rid of in time -save((fullfile(easyResultsDir,'Fotos','Nbdg')), 'sbdg'); -save((fullfile(easyResultsDir,'Fotos','Coordinates')),'FexpScanSpots') %Saves frames at each tPt -save((fullfile(easyResultsDir,'Fotos','BGatTpts')),'FexpScanBMtp') -save((fullfile(easyResultsDir,'Fotos','anlZones')),'anlZoneRefs')%Saves anl Positions at each tPt +save((fullfile(fotosResultsDir,'Nbdg')), 'sbdg'); +save((fullfile(fotosResultsDir,'Coordinates')),'FexpScanSpots') %Saves frames at each tPt +save((fullfile(fotosResultsDir,'BGatTpts')),'FexpScanBMtp') +save((fullfile(fotosResultsDir,'anlZones')),'anlZoneRefs')%Saves anl Positions at each tPt % Print FitResults fileExt='.txt';