EASY refactor: First attempt

This commit is contained in:
2024-07-27 02:58:49 -04:00
parent 5269962927
commit bce30095aa
11 changed files with 340 additions and 301 deletions

View File

@@ -1,43 +1,22 @@
%% CALLED BY EASYconsole.m %%
w=pwd;
%function NImStartupImCF02par4Gbl
Fflg=1; %0;
fclose('all'); %close all open files
clear('plate2', 'scanIntens','Scanfiles','pathname','tifFileLstP4')
%global SWsingleSc
global SWgrowthArea
global scLst
global ImParMat
%global CSearchRange
%global CSrchRng
global expDir
global SWnewExp
global openExpfile
global openExppath
global newExpfile
global newExppath
global ExpOutmat
global scansDir
global matFile
global fhconsole
global ExpPath
global resDir
global wCodeDir
global easyResultsDir
global pointMapsResultsDir
global fotosResultsDir
global matDir
global ImWidth
global ImHeigth
global numRows;
global numCols;
%global SWprintLeg
global numRows
global numCols
global scan
%global scanSize
global scanMax
global tptLength
%global scanPar4x
%global sols
%global CFmeth
numRows=24; % for Single Vertical
numCols=16; % for Single Vertical
@@ -48,22 +27,31 @@ radius=14;
ImParMat(10)=radius;
ImParMat(11)=doCircle;
% TODO what is this for?
Fflg=1;
% Don't think we need this
% fclose('all'); % close all open files
% Unset some vars just in case they are already set
clear('scanIntens','Scanfiles','pathname','tifFileLstP4')
try
clf(fhconsole,'reset')
catch ME
end
close
EASYconsole
try
load(ExpOutmat)
copyfile(ExpOutmat,(fullfile(matDir,'BkUp',strcat((num2str(datenum(now))),'.mat'))))
catch
end
% No idea why we're doing this so commenting out
% close
% EASYconsole
if exist(matFile, 'file')
bkUpMatFile=fullfile(matDir,'BkUp',matFile)
copyfile(matFile,(fullfile(matDir,'BkUp',matFile)))
end
try
load(fullfile(resDir,'Fotos','Nbdg')) %Modified to load from 'Fotos' 20_0819
load(fullfile(easyResultsDir,'Fotos','Nbdg')) %Modified to load from 'Fotos' 20_0819
catch
% Reloacated from 'PTmats' to prevent potential overwrite when PTmats is
% copied into new job when the PT template is about the same. We also
@@ -74,35 +62,34 @@ catch
% A copy of Ndbg.mat is placed also saved to the 'PTmats' directory
% after each run to allow previous version of EASY to access data made
% by EASY versions after 20_0819.
load(fullfile(resDir,'PTmats','Nbdg')) %Left in to accomodate loads of work before 20_0819
load(fullfile(easyResultsDir,'PTmats','Nbdg')) %Left in to accomodate loads of work before 20_0819
end
% Load Fotos stored data
try
load(fullfile(resDir,'Fotos','Coordinates'))
load(fullfile(easyResultsDir,'Fotos','Coordinates'))
catch
end
try
load(fullfile(resDir,'Fotos','BGatTpts'))
load(fullfile(easyResultsDir,'Fotos','BGatTpts'))
catch
end
try
load(fullfile(resDir,'Fotos','anlZones'))
load(fullfile(easyResultsDir,'Fotos','anlZones'))
catch
end
% autoImCF
try
load(fullfile(resDir,'PTmats','NCFparms'))
load(fullfile(easyResultsDir,'PTmats','NCFparms'))
catch ME
load parameters
end
% Get Print Times
PrintTimes=[];
expDir=fullfile(ExpPath);
scLst={};
% Parameter Entry
NImParamRadiusGui(expDir) % Ncode 122111replaced removed ,numOfPrtTimes)
NImParamRadiusGui(scansDir) % Ncode 122111replaced removed ,numOfPrtTimes)
width=24;
widthEx=width-1; % width extention from reference point
dither=ImParMat(6);
@@ -131,25 +118,16 @@ else
end
SWgrowthArea=ImParMat(9);
load(fullfile(resDir,'PTmats','NPTmapSearch'))
load(fullfile(pointMapsResultsDir,'NPTmapSearch'))
PTmapPos=detPos;
selScanNumLst=[];
Scanfiles=[];
pathname=[];
% TODO BCR this probably doesn't need to be here but I'm leaving it for now
if ispc
cd(char(strcat(expDir,scLst(1))))
elseif (isunix || ismac)
cd(fullfile(expDir,cell2mat(scLst(1))));
end
Scanfiles=[];
pathname=[];
for ii=1:length(scLst)
if (SWsingleSc == 1)
[Scanfiles, pathname]=uigetfile('*.bmp', 'Select files','MultiSelect','on');% change '*hr*.bmp' 12/20/2011
% TODO proably need to make this more explicit with paths
[Scanfiles, pathname]=uigetfile('*.bmp', 'Select files','MultiSelect','on'); % change '*hr*.bmp' 12/20/2011
if ischar(Scanfiles)
scd=imread(char(Scanfiles));
tptLength=1;
@@ -159,32 +137,30 @@ for ii=1:length(scLst)
end
ImHeigth=size(scd,1);
ImWidth=size(scd,2);
sc=scd(1:ImHeigth,1:ImWidth); %?Not used RefOnly
sc=scd(1:ImHeigth,1:ImWidth);
end
cd(w);
numFiles=size(Scanfiles,2);
% Initialize tifFilesLst for parfor loop
dir(fullfile(expDir, char(scLst(ii)), '*.bmp'));
dir(fullfile(scansDir, char(scLst(ii)), '*.bmp'));
numFiles=length(tifFileLst4MultiT);
tptLength=numFiles;
tifFileLstP4{ii}={tifFileLst4MultiT.name};
end
for jj=1:numScans %startScan:numScans
for jj=1:numScans % startScan:numScans
selScan=str2double(char(scLst(jj)));
selScanNumLst(jj)=selScan;
end
selScanNumLst2=selScanNumLst; %function passthrough, passback to par4gbl_Main 20_0205
selScanNumLst2=selScanNumLst; % function passthrough, passback to par4gbl_Main 20_0205
% PREALLOCATION
% Preallocation
scCount=[];
TmpexpScanIntens00=cell(1); %cell(1,scanMax);
TmpFexpScanSpots00=cell(1); %cell(1,scanMax);
TmpFexpScanBMtp00=cell(1); %cell(1,scanMax);
TmpanlZoneRefs00=cell(1); %cell(1,scanMax);
TmpexpScanIntens00=cell(1); % cell(1,scanMax);
TmpFexpScanSpots00=cell(1); % cell(1,scanMax);
TmpFexpScanBMtp00=cell(1); % cell(1,scanMax);
TmpanlZoneRefs00=cell(1); % cell(1,scanMax);
Tmpsbdg00=cell(1);
TmpexpScanIntens4=cell(1,numScans);
TmpFexpScanSpots4=cell(1,numScans);
@@ -206,11 +182,11 @@ CFscanIntens=zeros(16,24);
[p4L4,TmpexpScanIntens5,TmpFexpScanSpots5,TmpFexpScanBMtp5,TmpanlZoneRefs5,Tmpsbdg5]= ...
p4loop8c(parMat,tptLength,numScans,selScanNumLst,SWsingleSc,Fflg,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,cirMask,width, ...
TmpexpScanIntens00,TmpFexpScanSpots00,TmpFexpScanBMtp00,TmpanlZoneRefs00,scCount,tifFileLstP4,pathname,ImParMat, ...
numRows,numCols,scLst,resDir,expDir, p4L00,TmpexpScanIntens4,TmpFexpScanSpots4,TmpFexpScanBMtp4,TmpanlZoneRefs4, ...
numRows,numCols,scLst,easyResultsDir,scansDir, p4L00,TmpexpScanIntens4,TmpFexpScanSpots4,TmpFexpScanBMtp4,TmpanlZoneRefs4, ...
Tmpsbdg00,Tmpsbdg4);
for scanCnt=1:numScans
selScan=p4L4{16,scanCnt}; %determine the actual scan in the scanCnt parfor distributed "id"
selScan=p4L4{16,scanCnt}; % determine the actual scan in the scanCnt parfor distributed "id"
scan(selScan).plate(1).tSeries=cell2mat(p4L4(1,scanCnt));
scan(selScan).plate(1).t0Series=cell2mat(p4L4(2,scanCnt));
scan(selScan).plate(1).printTm=cell2mat(p4L4(3,scanCnt));
@@ -222,7 +198,7 @@ for scanCnt=1:numScans
scan(selScan).plate(1).selTimes=p4L4(9,scanCnt);
scan(selScan).plate(1).filterTimes=p4L4(10,scanCnt);
scan(selScan).plate(1).normIntens=p4L4(11,scanCnt);
%scan(selScan).plate(1).CFparameters=p4L4(12,scanCnt); %Need to convert to a matrix form like Old versions
% scan(selScan).plate(1).CFparameters=p4L4(12,scanCnt); %Need to convert to a matrix form like Old versions
CFparm(1:384)=p4L4{12,scanCnt}(1:384);
scan(selScan).plate(1).CFparameters=CFparm;
scan(selScan).plate(1).CFdate=p4L4(13,scanCnt);
@@ -241,31 +217,31 @@ for scanCnt=1:numScans
end
end
%SAVE DATA in .mat files
save(ExpOutmat,'scan');
% save((fullfile(resDir,'PTmats','Nbdg')), 'sbdg'); %legacy location can probably get rid of in time
save((fullfile(resDir,'Fotos','Nbdg')), 'sbdg');
save((fullfile(resDir,'Fotos','Coordinates')),'FexpScanSpots') %Saves frames at each tPt
save((fullfile(resDir,'Fotos','BGatTpts')),'FexpScanBMtp')
save((fullfile(resDir,'Fotos','anlZones')),'anlZoneRefs')%Saves anl Positions at each tPt
% 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
%Print FitResults *******************************************************
% Print FitResults
fileExt='.txt';
filePrefix='FitResults_';
for scanCnt=1:numScans
selScan=p4L4{16,scanCnt}; %determine the actual scan in the scanCnt parfor distributed "id"
selScan=p4L4{16,scanCnt}; % determine the actual scan in the scanCnt parfor distributed "id"
fileSuffix=strcat('Scan', num2str(selScan),'_Plate', num2str(1));
fileNamePlate=[filePrefix fileSuffix fileExt];
fileName=fullfile(resDir,'PrintResults', fileNamePlate); %[outputDirectory fileNamePlate];
fileName=fullfile(easyResultsDir,'PrintResults', fileNamePlate); % [outputDirectory fileNamePlate];
%This,fprint for loop,is an very old legacy feature which slows processing. Could be
%removed but allows easy observation of how a run is progressing and can be
%used as a diagnostic tool.
% This,fprint for loop,is an very old legacy feature which slows processing. Could be
% removed but allows easy observation of how a run is progressing and can be
% used as a diagnostic tool.
outCprint=p4L4;
fid=fopen(fileName,'w');
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');
for n=1:384 %startCount:numCultures
for n=1:384 % startCount:numCultures
fprintf(fid,'%d\t',n);
fprintf(fid, '%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\n',...
outCprint{14,scanCnt}(n,1),outCprint{14,scanCnt}(n,2),outCprint{14,scanCnt}(n,3),outCprint{14,scanCnt}(n,4),...