Squashed initial commit

This commit is contained in:
2024-09-10 13:47:29 -04:00
commit 8ebb6ad265
6221 changed files with 2512206 additions and 0 deletions

View File

@@ -0,0 +1,325 @@
%% CALLED BY EASYconsole.m %%
global mpdmFile
global masterPlateFile
global drugMediaFile
global matDir
% If we already have mpdmFile, don't recreate
if (exist(mpdmFile, 'file') && ~isempty(mpdmFile))
fprintf('The Drug Media/MasterPlate Annotation File: %s exists, skipping DMPexcel2mat.m\n', mpdmFile);
return
end
% Do our best to find and load a relevant MasterPlate file
if ~exist(masterPlateFile, 'file') || isempty(masterPlateFile)
if exist(fullfile(matDir), 'dir')
% Try to find the masterPlateFile automatically (newest created first)
try
files=dir(matDir);
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
if isempty(mpFiles)
throw(MException('MATLAB:dir', 'No MasterPlate_ files in the default MasterPlate directory'));
end
% this sorts by date (newest first)
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
sortedFiles=mpFiles(sortedIndices);
masterPlateFile=sortedFiles{1};
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
catch ME
% This can be silent, not really an error
end
try
% For standalone mode
% GUI input for selecting a MasterPlate Excel file
questdlg('Select MasterPlate Directory (containing DrugMedia_ & MasterPlate_ files)','Directory Selection','OK',...
struct('Default','OK','Interpreter','tex'))
dirToScan=uigetdir();
files=dir(dirToScan);
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
if isempty(mpFiles)
throw(MException('MATLAB:dir', 'No MasterPlate_ files in directory'))
end
% this sorts by date (newest first)
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
sortedFiles=mpFiles{sortedIndices};
masterPlateFile=sortedFiles{1};
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
break
catch ME
h=msgbox(ME.message, 'Error', 'error');
disp('Rerunning directory selection');
% I don't know what else we'll need to do here
end
else
try
% For standalone mode
% GUI input for selecting a MasterPlate Excel file
questdlg('Select MasterPlate Directory (containing DrugMedia_ & MasterPlate_ files)','Directory Selection','OK',...
struct('Default','OK','Interpreter','tex'))
dirToScan=uigetdir();
files=dir(dirToScan);
mpFiles={files(strncmp(files.name, 'MasterPlate_', 12)).name};
if isempty(mpFiles)
throw (MException('MATLAB:dir', 'No MasterPlate_ files in directory'));
end
% this sorts by date (newest first)
[~, sortedIndices]=sort(datenum({files(strncmp(mpFiles.name, 'MasterPlate_', 12)).date}), 'descend');
sortedFiles=mpFiles{sortedIndices};
masterPlateFile=sortedFiles{1};
disp('Using newest MasterPlate file: ', masterPlateFile, ', skipping directory selection');
break
catch ME
h=msgbox(ME.message, 'Error', 'error');
uiwait(h);
disp('Rerunning directory selection');
% I don't know what else we'll need to do here
end
end
else
fprintf('Using MasterPlate file: %s skipping directory selection\n', masterPlateFile);
end
% fid=fopen(masterPlateFile)%('exp23PrintTimes.xls'); % textread puts date and time sequentially into vector
% TODO needs explanation, it isn't clear what it is for
% The input files should be csv, not xlsx
% This whole file could be much better and more portable
if ispc
[num, txt, raw]=xlsread(masterPlateFile); %,'Yor1HitsMPsetFinal');
fields={txt(2,1:15)}; %or 1:17 for later but dont wish to exceed and cause error ? if used
else
clear MPtbl
opts=detectImportOptions(masterPlateFile);
MPtbl=readtable(masterPlateFile,opts);
MPtbl=readtable(masterPlateFile);
fields={opts.VariableNames}; %? if used anywhere although 'saved' to MPDMmat
MPcell=readcell(masterPlateFile);
end
numb=0;
clear MP;
try
if ispc
excLnNum=3;
while (isequal(txt{excLnNum,1},'###'))
numb=numb+1;
MP(numb).head={raw(excLnNum,2:6)};
MP(numb).recNum={raw((excLnNum+1):(excLnNum+384),1)};
MP(numb).orf={raw((excLnNum+1):(excLnNum+384),2)};
MP(numb).strain={raw((excLnNum+1):(excLnNum+384),3)};
MP(numb).genename={raw((excLnNum+1):(excLnNum+384),12)};
MP(numb).drug={raw((excLnNum+1):(excLnNum+384),8)};
MP(numb).media={raw((excLnNum+1):(excLnNum+384),7)};
if size(raw,2)>15
MP(numb).orfRep={raw((excLnNum+1):(excLnNum+384),16)}; % added 12_1005 to specify replicates Orfs in MP
MP(numb).specifics={raw((excLnNum+1):(excLnNum+384),17)}; % added 12_1008 to specify replicates Specific details in MP
else
MP(numb).orfRep=' ';
MP(numb).specifics= ' ';
end
% Future MP field
% if size(raw,2)>17
% MP(numb).specifics2= {raw((excLnNum+1):(excLnNum+384),18)}; % added 12_1008 to specify strain Bkground in MP
% else
% MP(numb).specifics2=' ';
% end
excLnNum=excLnNum+385;
msg=strcat('NumberOfMP=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
end
else
excLnNum=1;
while (isequal(MPcell{(excLnNum+2),1},'###'))
numb=numb+1;
MP(numb).head={MPtbl(excLnNum,2:6)};
MP(numb).head{1}=table2cell(MP(numb).head{1});
MP(numb).recNum={MPtbl((excLnNum+1):(excLnNum+384),1)};
MP(numb).recNum{1}=table2cell(MP(numb).recNum{1});
MP(numb).orf={MPtbl((excLnNum+1):(excLnNum+384),2)};
MP(numb).orf{1}=table2cell(MP(numb).orf{1});
MP(numb).strain={MPtbl((excLnNum+1):(excLnNum+384),3)};
MP(numb).strain{1}=table2cell(MP(numb).strain{1});
MP(numb).genename={MPtbl((excLnNum+1):(excLnNum+384),12)};
MP(numb).genename{1}= table2cell(MP(numb).genename{1});
MP(numb).media= {MPtbl((excLnNum+1):(excLnNum+384),7)};
MP(numb).media{1}= table2cell(MP(numb).media{1});
if size(MPtbl,2)>15
MP(numb).orfRep= {MPtbl((excLnNum+1):(excLnNum+384),16)}; % added 12_1005 to specify replicates Orfs in MP
MP(numb).orfRep{1}=table2cell(MP(numb).orfRep{1});
MP(numb).specifics={MPtbl((excLnNum+1):(excLnNum+384),17)}; % added 12_1008 to specify replicates Specific details in MP
MP(numb).specifics{1}=table2cell(MP(numb).specifics{1});
else
MP(numb).orfRep= ' ';
MP(numb).specifics= ' ';
end
excLnNum=excLnNum+385;
msg=strcat('NumberOfMP=',num2str(numb), 'lastLineNo.=',num2str(excLnNum));
end
end
catch ME
h=msgbox(ME.message, 'Error', 'error');
uiwait(h);
end
%DMupload
%Drug and Media Plate setup Upload from Excel
excLnNum=1;
numOfDrugs=0;
numOfMedias=0;
% Grabbing the bare filename from the MasterPlate file to see if we can automatically
% find a matching DrugMedia file
[mpFile, mpPath]=fullfile(masterPlateFile);
mpFileParts=strsplit(mpFile, '_');
mpBareFileName=strjoin(mpFileParts(2:end-1), '_');
if ~exist(drugMediaFile, 'file') || isempty(drugMediaFile)
if exist(fullfile(matDir), 'dir')
try
dmFileToTest=fullfile(mpPath, 'DrugMedia_', mpBareFileName, '.xlsx');
if exist(dmFileToTest, 'file') % Try to find a matching drug media file
drugMediaFile=dmFileToTest;
fprintf('Using matching DrugMedia file: %s, skipping directory selection\n', drugMediaFile);
else
% Try to find the DrugMedia file automatically (newest created first)
files=dir(matDir);
dmFiles={files(strncmp(files.name, 'DrugMedia_', 10)).name};
if isempty(dmFiles)
throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'));
end
% this sorts by date (newest first)
[~, sortedIndices]=sort(datenum({files(strncmp(dmFiles.name, 'DrugMedia_', 10)).date}), 'descend');
sortedFiles=dmFiles{sortedIndices};
drugMediaFile=sortedFiles{1};
fprintf('Using newest DrugMedia file: %s, skipping directory selection\n', drugMediaFile);
end
catch Me
% This can be silent, not really an error
end
else
for i=1:5 % give users 5 chances to get it right
try
% GUI input for selecting a DrugMedia file
% sort by newest matching DrugMedia file and return that if we find one
% For standalone mode
% GUI input for selecting a MasterPlate Excel file
questdlg('Select DrugMedia directory','Directory Selection','OK',...
struct('Default','OK','Interpreter','tex'))
dirToScan=uigetdir();
files=dir(dirToScan);
dmFiles={files(strncmp(files.name, 'DrugMedia_', 10)).name};
if isempty(dmFiles)
throw (MException('MATLAB:dir', 'No DrugMedia_ files in directory'));
end
% this sorts by date (newest first)
[~, sortedIndices]=sort(datenum({files(strncmp(dmFiles.name, 'DrugMedia_', 10)).date}), 'descend');
sortedFiles=dmFiles{sortedIndices};
drugMediaFile=sortedFiles{1};
catch ME
h=msgbox(ME.message, 'Error', 'error');
uiwait(h);
disp('Rerunning directory selection');
% I don't know what else we'll need to do here
end
end
end
else
fprintf('Using drugMediaFile: %s, skipping directory selection\n', drugMediaFile);
end
% Drug and Media Plate setup
% TODO needs better explanation
if ispc
[num, txt, raw]=xlsread(drugMediaFile); %'Yor1HitsMPsetFinal');
fields={txt(2,1:5)};
Linked=num(1,1);
else
opts=detectImportOptions(drugMediaFile);
DMtbl=readtable(drugMediaFile,opts);
fields=opts.VariableOptions;
Linked=DMtbl{1,1};
DMcell=readcell(drugMediaFile);
end
% TODO needs better explanation
numb=0;
if isequal(Linked,1) % Drugs and Media are linked 1 to 1; else they are combinatorial
clear DM;
excLnNum=2;
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)};
excLnNum=excLnNum+1;
msg=strcat('NumberOf1:1DrugMediaPlates=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
end
else
clear DM
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});
excLnNum=excLnNum+1;
msg=strcat('NumberOf1:1DrugMediaPlates=',num2str(numb), ' lastLineNo.=',num2str(excLnNum));
end
end
end
% Legacy contengency: not ever used
if isequal(Linked,0) % 0 indicates Drugs and Media are combinatorial
clear DM;
excLnNum=2;
drgCnt=0;
medCnt=0;
if ispc
while (~isequal(txt{excLnNum,2},'###'))
drgCnt=drgCnt+1;
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)};
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)};
excLnNum=excLnNum+1;
end
while (~isequal(DMcel{excLnNum+1,4},'###'))
medCnt=medCnt+1;
DM.media(medCnt)={DMtbl(excLnNum,4)};
excLnNum=excLnNum+1;
end
end
msg=strcat('NumberOfDrugs=',num2str(drgCnt), ' NumberOfMedias=',num2str(medCnt) );
end
save(mpdmFile, 'fields','MP','DM','Linked');
msgbox(sprintf('Drug-Media-MasterPlate Annotation File %s Generation Complete', mpdmFile))

View File

@@ -0,0 +1,652 @@
global projectScansDir
global projectName
global matFile
global defImParMat
global printResultsDir
global fotosResultsDir
global pointMapsFile
global pointMapsResultsDir
ln=1;
% Version compatability fixes
if verLessThan('matlab','8.3')
fd4=diff(sym('K / (1 + exp(-r* (t - l )))'),4);
sols=solve(fd4);
else % accomodate new matlab changes after 2014a
syms t K r l;
fd4=diff(K / (1 + exp(-r* (t - l ))),t,4);
sols=solve(fd4);
tmpswap=sols(1);
sols(1)=sols(3);
sols(3)=tmpswap;
end
% MPnum=ImParMat(1);
% opt=questdlg('Print Results Only (RES), DB Only (DB), or Both','Results Printout Options','Res','DB','Both','Both');
opt='Res';
if ~exist('defImParMat','var') || isempty(defImParMat) % TODO needs explanation
load(pointMapsFile);
end
destPerMP=ImParMat(2); % TODO this is weird, needs explanation
load(matFile);
load(mpdmFile)
numOfDrgs=length(DM.drug);
numOfMeds=length(DM.media);
destPerMP=numOfDrgs;
% TODO this should be rewritten or is unnecessary, what is this for
% Determine the longest set of intensity(tPts) for the Experiment Data Set
maxNumIntens=0;
for n=1:size(scan,2)
for m=1:size(scan(n).plate,2)
maxNumIntens=max(maxNumIntens,size(scan(n).plate(m).intens,2));
end
end
% if length(projectScansDir) == max(strfind(projectScansDir,'\'))
% localprojectScansDir=projectScansDir(1:end-1);
% else
% localprojectScansDir=projectScansDir;
% end
% DBupload=fullfile(drive,'EZdbFiles','DBupLOADfiles');
resultsFilename=fullfile(printResultsDir, 'results_elr.txt');
DBfilename=fullfile(printResultsDir, 'DbaseELr.txt');
if isequal(opt,'Res')||isequal(opt,'Both'),fid=fopen(resultsFilename,'w');end
if isequal(opt,'DB')||isequal(opt,'Both'),fid2=fopen(DBfilename,'w');end
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid,'%d\t',ln); % Results header
fprintf(fid,'%s\t\n',projectScansDir);
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
mpCnt=0;
totPlCnt=0;
drgCnt=0;
medCnt=0;
try
load(fullfile(fotosResultsDir,'Nbdg')) % Convolute scan array data into plates
catch
load(fullfile(pointMapsResultsDir,'Nbdg')) % Convolute scan array data into plates
end
for s=1:size(scan,2)
% Convolute scan array data into plates DconB for DBcombo
clear Diag
try
Diag(:,:,:,1)=sbdg{s}(1:1:24,16:-1:1,:);
catch
sbdg{s};
end
for p=1:size((scan(s).plate),2)
totPlCnt=totPlCnt+1;
if destPerMP>1 && rem(totPlCnt,destPerMP)==1
mpCnt=mpCnt+1;
end
if destPerMP==1
mpCnt=mpCnt+1;
end
pertCnt=rem(totPlCnt,destPerMP);
if pertCnt==0
pertCnt=destPerMP;
end
pert=strcat('Perturb_',num2str(pertCnt));
s % TODO seems wrong
p % TODO seems wrong
clear outCmat
outCmat=scan(s).plate(p).CFout;
% Print Time Point HEADER for each plate for newly added intensity data
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
fprintf(fid,'Scan\tPlate\tRow\tCol\t');
try
asd=cell2mat(scan(s).plate(1).CFparameters(1));
aucEndPt=strcat('AUC',num2str(asd(9)));
catch
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, '\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');
if size(outCmat,2)==27
fprintf(fid, '\ttc11Cut\ttc12Cut\ttc21Cut\ttc22Cut'); % '\tEarly1\tEarly2\tLate1\tLate2'); 17_0629 MinBaseIntens update for MedianBase label
end
fprintf(fid, '\tTotFitPts\tPostThreshFitPts\t1stBackgrd\tLstBackgrd\t1stMeanTotBackgrd\tLstMeanTotBackgrd');
end
clear outTseries
outTseries=[];
outTseries=scan(s).plate(p).tSeries;
TseriesSize=size(outTseries,1);
clear outIntens
outIntens=[];
RawIntens=[];
RawIntens=scan(s).plate(p).intens;
RawIntensSize=size(RawIntens,2)
clear Ag; %Ag is Growth Area
Ag=scan(s).plate(p).Ag;
AgSize=size(Ag);
dataLength=min(TseriesSize,RawIntensSize);
if isequal(opt,'Res')||isequal(opt,'Both')
for j=1:dataLength
fprintf(fid, '\t%.5f', outTseries(j));
end
end
numBlkCol=(maxNumIntens - dataLength); % size(outTseries,1));
if isequal(opt,'Res')||isequal(opt,'Both')
for nn=1:numBlkCol % extend to col beyond longest rawDataSet
fprintf(fid, '\t');
end
fprintf(fid,'\tOrfRep');
fprintf(fid,'\tSpecifics');
fprintf(fid,'\tStrainBkGrd');
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
% Data
n=0;
for r=1:16
for c=1:24
n=n+1;
clear selcode;
Kval=outCmat(n,3);
rSq=outCmat(n,6);
lval=outCmat(n,5);
if Kval>160, selcode='K_Hi'; else selcode=' ';end
if Kval<40, selcode=strcat(selcode,' K_Lo');end
if rSq<.97 && rSq>0, selcode=strcat(selcode,' rSqLo');end
if lval>(0.85*(max(outTseries))), selcode=strcat(selcode,' late');end
if isnan(outCmat(n,7))||isnan(outCmat(n,8))||isnan(outCmat(n,9))...
|| isnan(outCmat(n,10))||isnan(outCmat(n,11))...
|| isnan(outCmat(n,12)), selcode=strcat(selcode,' NaN');
end
% RiseTime Calculation
K=(outCmat(n,3));
R=(outCmat(n,4));
L=(outCmat(n,5));
if R>0 && L>0 && K>0
rr=R; ll=L;
tc1=eval(sols(2));
tc2=eval(sols(3));
LL=eval(sols(1));
riseTm=LL-tc1;
else
riseTm=0;
end
if Ag(n)< .30*(scan(s).Awindow),selcode=strcat(selcode,' smArea'); end
if outCmat(n,3)==0,selcode=strcat('0 ',selcode);end
orf=cell2mat(MP(mpCnt).orf{1}(n));
gene=cell2mat(MP(mpCnt).genename{1}(n));
orfRep=cell2mat(MP(mpCnt).orfRep{1}(n));
specifics=cell2mat(MP(mpCnt).specifics{1}(n));
strain=cell2mat(MP(mpCnt).strain{1}(n));
drug=char(DM.drug{pertCnt});
conc=char(DM.conc{pertCnt});
media=char(DM.media{pertCnt});
try
mod1=char(DM.mod1{pertCnt});
conc1=char(DM.conc1{pertCnt});
catch
mod1=' ';
conc1=' ';
end
try
mod2=char(DM.mod2{pertCnt});
conc2=char(DM.conc2{pertCnt});
catch
mod2=' ';
conc2=' ';
end
if ~isempty(outCmat)
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid,'%d\t %d\t %d\t %d\t %d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t',s,p,r,c,n,selcode,drug,conc,media,mod1,conc1,mod2,conc2,orf,gene);
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',...
outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
outCmat(n,5),outCmat(n,6),outCmat(n,7),outCmat(n,8),...
outCmat(n,9),outCmat(n,10),outCmat(n,11),outCmat(n,12),...
outCmat(n,13),outCmat(n,14),outCmat(n,15),outCmat(n,16));
fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f',...
outCmat(n,17),outCmat(n,18),outCmat(n,19),...
outCmat(n,20),outCmat(n,21));
% Added for data cut times used in 'r'optomized method 06/14/2018
if (size(outCmat,2) == 27)
fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f',...
outCmat(n,24),outCmat(n,25),outCmat(n,26),outCmat(n,27));
end
fprintf(fid, '\t%d\t%d\t%d\t%d\t%d\t%d',...
outCmat(n,22),outCmat(n,23),Diag(c,r,1,p),Diag(c,r,2,p),Diag(c,r,3,p),Diag(c,r,4,p)); %,Diag(r,c,3,p),Diag(r,c,4,p));
end
% DBfile
if isequal(opt,'DB')||isequal(opt,'Both')
dbRsq=0;dbKup=0; dbKlo=0; dbrup=0; dbrlo=0; dbLlo=0; dbLup=0;
if isnumeric(outCmat(n,6)), dbRsq=outCmat(n,6);end
if isnumeric(outCmat(n,7)), dbKup=outCmat(n,7);end
if isnumeric(outCmat(n,8)), dbKlo=outCmat(n,8);end
if isnumeric(outCmat(n,9)), dbrup=outCmat(n,9);end
if isnumeric(outCmat(n,10)), dbrlo=outCmat(n,10);end
if isnumeric(outCmat(n,11)), dbLlo=outCmat(n,11);end
if isnumeric(outCmat(n,12)), dbLup=outCmat(n,12);end
end
if isequal(opt,'DB')||isequal(opt,'Both')
fprintf(fid2,'%s\t %d\t %d\t %d\t %d\t %d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t',projectName,s,p,r,c,n,selcode,drug,conc,media,mod1,conc1,mod2,conc2,orf,gene);
fprintf(fid2, '%.5f\t %.5f\t %.5f\t %.5f\t %.5f\t %.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f',...
outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
outCmat(n,5),dbRsq,dbKup,dbKlo,dbrup,dbrlo,dbLlo,dbLup); %\t%.5f\t%.5f\t%.5f\t%.5f
end
% Add Intensities series to end of curve fit data
outIntens=[];
outIntens=zeros(384,dataLength);
intensBlob='';
tmBlob='';
for j=1:dataLength %size(RawIntens,2) %size(outTseries,1)
if Ag(n)==0,Ag(n)=scan(s).Awindow;end
outIntens(n,j)=RawIntens(n,j)/Ag(n);
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid, '\t%.5f', outIntens(n,j)); % Results print Intens
end
if isequal(opt,'DB')||isequal(opt,'Both')
if j<dataLength
intensBlob=strcat(intensBlob,num2str(outIntens(n,j)),';');
else
intensBlob=strcat(intensBlob,num2str(outIntens(n,j)));
end
if outTseries(j)<.0001,outTseries(j)=0;end
if j<dataLength
tmBlob=strcat(tmBlob,num2str(outTseries(j)),';');
else
tmBlob=strcat(tmBlob,num2str(outTseries(j)));
end
end
end
% Results
if isequal(opt,'Res')||isequal(opt,'Both')
for nn=1:numBlkCol %extend to col beyond longest rawDataSet
fprintf(fid, '\t');
end
% Masterplate sheet
if ~isnan(orfRep)
fprintf(fid, '\t%s', orfRep); %print OrfRep
else
fprintf(fid, '\t%s', ' ');
end
if ~isnan(specifics)
fprintf(fid, '\t%s', specifics);
else
fprintf(fid, '\t%s', ' ');
end
if ~isnan(strain)
fprintf(fid, '\t%s', strain);
else
fprintf(fid, '\t%s', ' ');
end
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
% DB Raw Intensities and Timepoints
if isequal(opt,'DB')||isequal(opt,'Both')
fprintf(fid2, '\t%s\t%s',intensBlob,tmBlob );
% Masterplate sheet
if ~isnan(orfRep)
fprintf(fid2, '\t%s',orfRep );
else
fprintf(fid2, '\t%s', ' ');
end
if ~isnan(specifics)
fprintf(fid2, '\t%s',specifics );
else
fprintf(fid2, '\t%s', ' ');
end
if ~isnan(strain)
fprintf(fid2, '\t%s',strain );
else
fprintf(fid2, '\t%s', ' ');
end
fprintf(fid2, '\n');
end
end
end
end
end
end
if isequal(opt,'Res')||isequal(opt,'Both')
fclose(fid);
end
% if isequal(opt,'DB')||isequal(opt,'Both')
% fclose(fid2);
% try
% copyfile(DBfilename,DBupload)
% catch ME
% fprintf('DB upload failed with error: %s\n', getReport(ME, 'basic'));
% rep=sprintf('Failed copyfile to %s - %s', DBupload, rep);
% errordlg(rep);
% end
% end
% Print results using the standard method
try
scan(1).plate(1).CFoutStd(1,1) %Test for 2018 r_refined version
ln=1;
resultsFilename=fullfile(printResultsDir, 'results_std.txt');
DBfilename=fullfile(printResultsDir, 'DbaseStd.txt');
if isequal(opt,'Res')||isequal(opt,'Both'),fid=fopen(resultsFilename,'w');end
if isequal(opt,'DB')||isequal(opt,'Both'),fid2=fopen(DBfilename,'w');end %121012 Combo
if isequal(opt,'Res')||isequal(opt,'Both') %print Results
fprintf(fid,'%d\t',ln); %Results header
fprintf(fid,'%s\t\n',projectScansDir);
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
mpCnt=0;
totPlCnt=0;
drgCnt=0;
medCnt=0;
for s=1:size(scan,2)
%Convolute scan array data into plates DconB for DBcombo
clear Diag
try
Diag(:,:,:,1)= sbdg{s}(1:1:24,16:-1:1,:);
catch
sbdg{s};
end
for p=1:size((scan(s).plate),2)
totPlCnt=totPlCnt+1;
if destPerMP>1 &&rem(totPlCnt,destPerMP)==1, mpCnt=mpCnt+1; end
if destPerMP==1,mpCnt=mpCnt+1; end
pertCnt=rem(totPlCnt,destPerMP);
if pertCnt==0, pertCnt= destPerMP;end
pert=strcat('Perturb_',num2str(pertCnt));
s % BCR seems wrong
%Print Time Point HEADER for each plate for newly added intensity data
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
fprintf(fid,'Scan\tPlate\tRow\tCol\t');
try
asd=cell2mat(scan(s).plate(1).CFparameters(1));
aucEndPt=strcat('AUC',num2str(asd(9)));
catch
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, '\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
outTseries=[];
outTseries=scan(s).plate(p).tSeries;
TseriesSize= size(outTseries,1);
clear outCmat
outCmat=scan(s).plate(p).CFoutStd;
clear outIntens
outIntens=[];
RawIntens=[];
RawIntens=scan(s).plate(p).intens;
RawIntensSize=size(RawIntens,2);
clear Ag; %Ag is Growth Area
Ag=scan(s).plate(p).Ag;
AgSize= size(Ag);
dataLength= min(TseriesSize,RawIntensSize);
if isequal(opt,'Res')||isequal(opt,'Both')
for j=1:dataLength
fprintf(fid, '\t%.5f', outTseries(j));
end
end
numBlkCol=(maxNumIntens - dataLength); %size(outTseries,1));
if isequal(opt,'Res')||isequal(opt,'Both')
for nn=1:numBlkCol %extend to col beyond longest rawDataSet
fprintf(fid, '\t');
end
fprintf(fid,'\tOrfRep');
fprintf(fid,'\tSpecifics');
fprintf(fid,'\tStrainBkGrd');
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
% Data
n=0;
for r=1:16
for c=1:24
n=n+1;
clear selcode;
Kval=outCmat(n,3);
rSq=outCmat(n,6);
lval=outCmat(n,5);
if Kval>160, selcode='K_Hi'; else selcode=' ';end
if Kval<40, selcode=strcat(selcode,' K_Lo');end % TODO sprintf if you want a space
if rSq<.97 && rSq>0, selcode=strcat(selcode,' rSqLo');end
if lval>(0.85*(max(outTseries))), selcode=strcat(selcode,' late');end
if isnan(outCmat(n,7))||isnan(outCmat(n,8))||isnan(outCmat(n,9))...
||isnan(outCmat(n,10))||isnan(outCmat(n,11))...
||isnan(outCmat(n,12)), selcode=strcat(selcode,' NaN');
end
% RiseTime Calculation
K=(outCmat(n,3));
R=(outCmat(n,4));
L=(outCmat(n,5));
if R>0 && L>0 && K>0
rr=R; ll=L;
tc1=eval(sols(2));
tc2=eval(sols(3));
LL=eval(sols(1));
riseTm= LL-tc1;
else
riseTm=0;
end
if Ag(n)< .30*(scan(s).Awindow),selcode=strcat(selcode,' smArea'); end % same, need sprintf for space
if outCmat(n,3)==0,selcode=strcat('0 ',selcode); end
orf=cell2mat(MP(mpCnt).orf{1}(n));
gene=cell2mat(MP(mpCnt).genename{1}(n));
orfRep=cell2mat(MP(mpCnt).orfRep{1}(n));
specifics=cell2mat(MP(mpCnt).specifics{1}(n));
strain=cell2mat(MP(mpCnt).strain{1}(n));
drug=char(DM.drug{pertCnt});
conc=char(DM.conc{pertCnt});
media=char(DM.media{pertCnt});
try
mod1=char(DM.mod1{pertCnt});
conc1=char(DM.conc1{pertCnt});
catch
mod1=' ';
conc1=' ';
end
try
mod2=char(DM.mod2{pertCnt});
conc2=char(DM.conc2{pertCnt});
catch
mod2=' ';
conc2=' ';
end
if ~isempty(outCmat)
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid,'%d\t %d\t %d\t %d\t %d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t',s,p,r,c,n,selcode,drug,conc,media,mod1,conc1,mod2,conc2,orf,gene);
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',...
outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
outCmat(n,5),outCmat(n,6),outCmat(n,7),outCmat(n,8),...
outCmat(n,9),outCmat(n,10),outCmat(n,11),outCmat(n,12),...
outCmat(n,13),outCmat(n,14),outCmat(n,15),outCmat(n,16));
fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%d\t%d',...
outCmat(n,17),outCmat(n,18),outCmat(n,19),...
outCmat(n,20),outCmat(n,21),outCmat(n,22),outCmat(n,23));
fprintf(fid, '\t%d\t%d\t%d\t%d',...
Diag(c,r,1,p),Diag(c,r,2,p),Diag(c,r,3,p),Diag(c,r,4,p)); %,Diag(r,c,3,p),Diag(r,c,4,p));
end
% DBFile
% RiseTime calculation
if isequal(opt,'DB')||isequal(opt,'Both')
dbRsq= 0;dbKup= 0; dbKlo= 0; dbrup= 0; dbrlo= 0; dbLlo= 0; dbLup= 0;
if isnumeric(outCmat(n,6)), dbRsq= outCmat(n,6);end
if isnumeric(outCmat(n,7)), dbKup= outCmat(n,7);end
if isnumeric(outCmat(n,8)), dbKlo= outCmat(n,8);end
if isnumeric(outCmat(n,9)), dbrup= outCmat(n,9);end
if isnumeric(outCmat(n,10)), dbrlo= outCmat(n,10);end
if isnumeric(outCmat(n,11)), dbLlo= outCmat(n,11);end
if isnumeric(outCmat(n,12)), dbLup= outCmat(n,12);end
end
if isequal(opt,'DB')||isequal(opt,'Both')
fprintf(fid2,'%s\t %d\t %d\t %d\t %d\t %d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t',projectName,s,p,r,c,n,selcode,drug,conc,media,mod1,conc1,mod2,conc2,orf,gene);
fprintf(fid2, '%.5f\t %.5f\t %.5f\t %.5f\t %.5f\t %.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f',...
outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
outCmat(n,5),dbRsq,dbKup,dbKlo,...
dbrup,dbrlo,dbLlo,dbLup);
end
% DB Analysis
% Add Intensities series to end of curve fit data
outIntens=[];
outIntens=zeros(384,dataLength);
intensBlob='';
tmBlob='';
for j=1:dataLength %size(RawIntens,2) %size(outTseries,1)
if Ag(n)==0,Ag(n)=scan(s).Awindow;end
outIntens(n,j)= RawIntens(n,j)/Ag(n);
if isequal(opt,'Res')||isequal(opt,'Both')
fprintf(fid, '\t%.5f', outIntens(n,j)); % Results print Intens
end
if isequal(opt,'DB')||isequal(opt,'Both')
if j<dataLength
intensBlob=strcat(intensBlob,num2str(outIntens(n,j)),';');
else
intensBlob=strcat(intensBlob,num2str(outIntens(n,j)));
end
if outTseries(j)<.0001,outTseries(j)=0;end
if j<dataLength
tmBlob=strcat(tmBlob,num2str(outTseries(j)),';');
else
tmBlob=strcat(tmBlob,num2str(outTseries(j)));
end
end
end
% Results fprint
if isequal(opt,'Res')||isequal(opt,'Both')
for nn=1:numBlkCol %extend to col beyond longest rawDataSet
fprintf(fid, '\t');
end
% Masterplate sheet
if ~isnan(orfRep)
fprintf(fid, '\t%s', orfRep); %print OrfRep
else
fprintf(fid, '\t%s', ' ');
end
if ~isnan(specifics)
fprintf(fid, '\t%s', specifics);
else
fprintf(fid, '\t%s', ' ');
end
if ~isnan(strain)
fprintf(fid, '\t%s', strain);
else
fprintf(fid, '\t%s', ' ');
end
fprintf(fid, '\n');
ln=ln+1;
fprintf(fid,'%d\t',ln);
end
% Raw Intensities and Timepoints
if isequal(opt,'DB')||isequal(opt,'Both')
fprintf(fid2, '\t%s\t%s',intensBlob,tmBlob );
% Masterplate sheet
if ~isnan(orfRep)
fprintf(fid2, '\t%s',orfRep );
else
fprintf(fid2, '\t%s', ' ');
end
if ~isnan(specifics)
fprintf(fid2, '\t%s',specifics );
else
fprintf(fid2, '\t%s', ' ');
end
if ~isnan(strain)
fprintf(fid2, '\t%s',strain );
else
fprintf(fid2, '\t%s', ' ');
end
fprintf(fid2, '\n');
end %DB print
end %if ~isempty(outCmat)
end %c
end %r
end %p
end %s
if isequal(opt,'Res')||isequal(opt,'Both')
fclose(fid);
end
% if isequal(opt,'DB')||isequal(opt,'Both')
% fclose(fid2);
% try
% copyfile(DBfilename,DBupload)
% catch ME
% fsprintf('DB upload failed with error: %s\n', getReport(ME, 'basic'));
% rep=sprintf('Failed copyfile to %s - %s\n', DBupload, rep);
% errordlg(rep)
% end
% end
msgbox([sprintf('Printing script complete. Check results sheets in %s for results.', printResultsDir)])
catch ME
fprintf('Printing script failed with error: %s\n', getReport(ME, 'basic'));
end

Binary file not shown.

View File

@@ -0,0 +1,508 @@
% Launch the MATLAB EASY console
% Updated 240727 Bryan C Roessler to improve file operations and portability
function varargout = EASYconsole(varargin)
global easyDir
global projectName
global projectScansDir
global easyResultsDir
global easyProjectName
global fotosResultsDir
global figsResultsDir
global pointMapsResultsDir
global pointMapsFile
global printResultsDir
global matDir
global matFile
global drugMediaFile
global masterPlateFile
global mpdmFile
global userName
global srchRange
global searchRangeFile
% Initialize some variables from matlab
easyPath=which(mfilename);
[easyDir,easyFileName]=fileparts(easyPath);
easyDir=fullfile(easyDir);
[parentDir, ~]=fileparts(easyDir);
parentDir=fullfile(parentDir); % ../easy/apps
userName=getenv('USER');
dt=datetime;
todayStr=char(dt, 'yyyyMMdd'); % This should match the parent workflow script 'hardcode'
outDir=fullfile(parentDir, '..','..', 'out'); % This should match the parent workflow script 'hardcode'
debug=1;
if debug
disp('Running in debug mode');
disp('Initialized variables:');
whos;
end
fprintf('This script name: %s\n', easyFileName);
% Allow EASY_DIR env to override hardcoded default EASY directory
if ~isempty(getenv('EASY_DIR'))
ed=fullfile(getenv('EASY_DIR'));
if ~strcmp(easyDir, ed) % sanity check
disp("WARNING: EASY_DIR does not match this script's hardcoded EASY location");
disp("This is probably OK but this pathway is not well-tested");
easyDir=ed;
end
fprintf('Using EASY script directory: %s from environment variable EASY_DIR\n', easyDir);
else
fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
end
whos
% Set projectScansDir intelligently
if ~isempty(getenv('PROJECT_SCANS_DIR'))
projectScansDir=fullfile(getenv('PROJECT_SCANS_DIR'));
if exist(projectScansDir, 'dir')
fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', projectScansDir);
disp('This usually indicates that we are in module mode');
else
disp('WARNING: PROJECT_SCANS_DIR does not exist');
end
elseif ~isempty(getenv('PROJECT_NAME')) % for standalone mode
projectName=getenv('PROJECT_NAME');
projectScansDir=fullfile(parentDir, '..', '..', 'scans', projectName);
fprintf('Using project path: %s from environment variable PROJECT\n', projectScansDir);
disp('This usually indicates that we are in standalone mode');
else
% TODO Lots of hardcoded logic, this TODO is just a reminder to change this block
% when changing EASY and other variables in the parent script
fprintf('WARNING: Running in standalone mode without PROJECT or PROJECT_SCANS_DIR environment variables (not recommended)\n');
fprintf('Beginning parent scans directory search\n');
dirsToScan={
fullfile(parentDir, '..', '..', 'scans')
fullfile(parentDir, '..', '..', 'ExpJobs')
fullfile('mnt','data','scans')
fullfile('mnt','data', 'ExpJobs')
fullfile(parentDir, '..', '..', 'templates', 'scans-demo')
};
for i=1:length(dirsToScan)
d=dirsToScan(i);
d=char(d);
if exist(d, 'dir')
matchedDirs={};
subDirs=dir(d);
pattern='^\d{6}_.*_.*';
for i=1:length(subDirs)
if ~isempty(strmatch(subDirs(i).name, pattern))
matchedDirs{end+1}=subDirs(i).name;
end
end
whos
if ~isempty(matchedDirs)
fprintf('Using scansDir %s\n', char(d));
end
fprintf('Scanning inside %s for a project directory\n', d);
sortedMatchedDirs=sortrows(matchedDirs);
projectScansDir=fullfile(sortedMatchedDirs{end}); % select the latest dir (by date prefix)
fprintf('Using project scans directory: %s\n', char(projectScansDir));
break
end
end
end
% Get the name of the project
[~, projectName]=fileparts(projectScansDir);
% Set the run-specific EASY output directory
if ~isempty(getenv('EASY_RESULTS_DIR'))
easyResultsDir=fullfile(getenv('EASY_RESULTS_DIR'));
fprintf('Using output directory: %s from environment variable EASY_RESULTS_DIR\n', easyResultsDir);
else
easyProjectName=strcat(todayStr, '_',userName, '_', projectName);
easyResultsDir=fullfile(parentDir, '..', '..', 'out', projectName, 'easy', easyProjectName);
if exist(easyResultsDir, 'dir')
fprintf('WARNING: EASY results dir %s already exists\n', easyResultsDir);
disp('Files in this directory may be overwritten')
fprintf('Using output directory: %s\n', easyResultsDir);
end
end
% Get the name of the EASY project
if ~isempty(getenv('EASY_PROJECT_NAME'))
easyProjectName=getenv('EASY_PROJECT_NAME');
else
[~, easyProjectName]=fileparts(easyResultsDir);
end
% User sanity check and warning
if ~isempty(getenv('PROJECT_USER'))
if ~strcmp(getenv('PROJECT_USER'), userName)
disp("WARNING: PROJECT_USER does not match the current namespace");
end
end
if ~isempty(getenv('MASTER_PLATE_FILE'))
masterPlateFile=fullfile(getenv('MASTER_PLATE_FILE'));
fprintf('Using drug media file: %s from environment variable MASTER_PLATE_FILE\n', masterPlateFile);
else % try to find MasterPlate_ file on our own
mp=fullfile(easyResultsDir, strcat('MasterPlate_', projectName,'.xlsx'));
if exist(mp, 'file')
masterPlateFile=mp;
fprintf('Using master plate file: %s from internal logic\n', masterPlateFile);
else
fprintf('WARNING: Could not find MasterPlate file: %s\n', mp);
fprintf('WARNING: Have you created a MasterPlate_ file in %s', easyResultsDir);
end
end
if ~isempty(getenv('DRUG_MEDIA_FILE'))
drugMediaFile=fullfile(getenv('DRUG_MEDIA_FILE'));
fprintf('Using drug media file: %s from environment variable DRUG_MEDIA_FILE\n', drugMediaFile);
else
dm=fullfile(easyResultsDir, strcat('DrugMedia_', projectName,'.xlsx'));
if exist(dm, 'file')
drugMediaFile=dm;
fprintf('Using drug media file: %s from internal logic\n', drugMediaFile);
else
fprintf('WARNING: Have you created a DrugMedia_ file in %s?\n', easyResultsDir);
end
end
matDir=fullfile(easyResultsDir, 'matResults');
matFile=fullfile(matDir,easyProjectName,'.mat');
mpdmFile=fullfile(matDir,'MPDM.mat');
printResultsDir=fullfile(easyResultsDir,'PrintResults');
fotosResultsDir=fullfile(easyResultsDir,'Fotos');
figsResultsDir=fullfile(easyResultsDir,'figs');
pointMapsResultsDir=fullfile(easyResultsDir,'PTmats');
pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat');
oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat');
searchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat');
% Decent time to print some helpful vars
if debug
disp('Vars at end of main loop:')
whos;
end
% 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(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
% reduce directory scoping issues when calling scripts w/o a path
addpath(easyDir);
% GUI interface design
gui_Singleton=1;
gui_State=struct(...
'gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EASYconsole_OpeningFcn, ...
'gui_OutputFcn', @EASYconsole_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
if nargout
[varargout{1:nargout}]=gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
end
% GUI
% Easyconcole_OpeningFcn executes just before the EASYconsole GUI is made visible.
% This function has no output args, see OutputFcn.
% hObject--handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles--structure with handles and user data (see GUIDATA)
% varargin--input arguments to EASYconsole (see VARARGIN)
function EASYconsole_OpeningFcn(hObject, ~, handles, varargin)
global fhconsole
global projectScansDir
% Choose default command line output for EASYconsole
handles.output=hObject;
% Update handles structure
guidata(hObject, handles);
%Figure header, Toolbar, etc. Setup
fhconsole=gcf;
set(fhconsole,'Toolbar','none');
fhconsole=gcf;
% Pulled this out of the opening function
% Seems better to wait until we have our vars set though?
if exist('projectScansDir','var') && ~isempty(projectScansDir)
set(fhconsole,'Name', sprintf('EASYconsole - %s', projectScansDir));
else
set(fhconsole,'Name','EASYconsole - No Active Experiment.')
end
end
% EASYconsole output
% Outputs from this function are returned to the command line.
% varargout--cell array for returning output args (see VARARGOUT);
% hObject--handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles--structure with handles and user data (see GUIDATA)
function varargout = EASYconsole_OutputFcn(~, ~, handles)
% Get default command line output from handles structure
varargout{1}=handles.output;
end
% Console button interfaces
% File Button Interface
function FileMenu_Callback(~, ~, ~)
% returnStartDir
end
% Load Experiment Button Interface
function LoadExp_Callback(~, ~, ~)
% returnStartDir
end
% New Experiment Button Interface
function NewExpDat_Callback(~, ~, ~)
global matDir
global matFile
global easyResultsDir
global easyProjectName
global fhconsole
global scan
global userName
global todayStr
% Create a new experiment
try
questdlg('Name the file and navigate to the directory with the image folders.','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[matfile,easyResultsDir]=uiputfile('.mat');
inputFileName=strrep(inputFile,'.mat','');
[~, projectName]=fileparts(easyResultsDir);
% Set paths
matDir=fullfile(easyResultsDir,'matResults');
matFile=fullfile(matDir, projectName, '.mat');
% Added for 'parfor global' to preallocate 'scan' structure
nlist=dir(fullfile(projectScansDir,'*'));
nnn=0;
for n=1:size(nlist,1)
if (~isempty(str2num(nlist(n).name)))
nnn=nnn+1;
PnumLst(nnn)= (str2num(nlist(n).name));
sl(nnn,1)={(nlist(n).name)};
end
end
scanSize=size(sl,1);
scanMax=max(str2double(sl));
clear scan;
scan(scanMax)=struct(); % changed for parfor global 20_0118
save(matFile,'scan')
% create supporting dirs
% this is also in the workflow script but here for standalone mode
dirs={'PrintResults', 'CFfigs', 'Fotos'};
for i=1:length(dirs)
d=dirs{i};
if ~exist(fullfile(easyResultsDir, d), 'dir')
mkdir(fullfile(easyResultsDir, d));
end
end
% templateDirs are stored in the easy template directory
templates={'figs', 'PTmats'};
for i=1:length(templates)
d=dirs{i};
if ~exist(fullfile(easyResultsDir, d), 'dir')
copyfile((fullfile(easyDir,d)), (fullfile(easyResultsDir,d)));
end
end
clear sbdg % reduce possible retention of a previous job sdbg
sbdg= cell(1,scanMax);
save((fullfile(easyResultsDir,'Fotos','Nbdg')),'sbdg');
catch ME
fprintf('ERROR: %s\n', ME.message);
end
% set the title for fhconsole depending on existence
if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
set(fhconsole,'Name',sprintf('EASYconsole - %s', easyResultsDir));
else
set(fhconsole,'Name','EASYconsole - Master Plate directory not selected.');
end
end
% Load a previous experiment
function LoadDatFile_Callback(~, ~, ~)
global matDir
global matFile
global projectName
global easyResultsDir
global easyProjectName
global easyPath
global fhconsole
try
questdlg('Load results .mat from ../out/project/','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[matDir,matFile]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off');
load(matFile);
easyResultsDir=fullfile(matDir,'..');
[~, projectName]=fileparts(easyResultsDir);
projectScansDir=fullfile(easyResultsDir, '..', '..', 'scans', projectName);
% TODO this is pretty hacky and needs something more explicit
if isfolder(fullfile(matDir, '..','..','1')) % If Inovation Vrobot Then
if load(pointMapsFile);
elseif load(fullfile(easyPath,'NImParameters.mat')); % hardcoded default
elseif load(fullfile(pointMapsResultsDir,'ImParameters.mat'));
elseif load(fullfile(easyPath,'ImParameters.mat'));
else
disp("Could not load the ImParameters.mat file");
end
else
disp('WARNING: cannot find project scans');
end
% Create supporting dirs
dirs={'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'};
for i=1:length(dirs)
d=dirs{i};
if ~exist(fullfile(easyResultsDir, d), 'dir')
mkdir(fullfile(easyResultsDir, d));
end
end
catch
end
clear scan
if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
fhconsole=gcf;
set(fhconsole,'Name',sprintf('EASYconsole - %s', easyResultsDir));
else
set(fhconsole,'Name','EASYconsole - Exp. Analysis NOT selected.');
end
end
% Callbacks
% 'Run' in the dropdown menu
function run_Callback(~, ~, ~)
end
function runPlateMapPintool_Callback(~, ~, ~)
try
NImapPT
catch
EASYconsole
end
end
function NImCFcombo_Callback(~, ~, ~)
try
par4Gbl_Main8c
EASYconsole
catch
EASYconsole
end
end
function runPlateImAnal_Callback(~, ~, ~)
try
NImStartupOnly
catch
EASYconsole
end
end
function PlateCFit_Callback(~, ~, ~)
% global matFile % TODO BCR not sure if needed
try
NCstart
catch
EASYconsole
end
end
function GenPrintouts_Callback(~, ~, ~)
end
function uploadExcelMP2DB_Callback(~, ~, ~)
end
function runDMPexcel_Callback(~, ~, ~)
try
DMPexcel2mat
catch
EASYconsole
end
end
function runResults_DBcombo_Callback(~, ~, ~)
try
DgenResults
catch ME
fprintf('Error in DgenResults: %s\n', ME.message);
EASYconsole
end
end
function Tools_Callback(~, ~, ~)
end
function runOverlayPlots_Callback(~, ~, ~)
try
DoverlayPlots2
EASYconsole
catch
EASYconsole
end
end
function runFotoStrip_Callback(~, ~, ~)
try
F_NImStartup_CentCir
EASYconsole
catch
EASYconsole
end
end
function runDisplayFig_Callback(~, ~, ~)
try
UfigDisplay
catch
EASYconsole
end
end
function runViewParameters_Callback(~, ~, ~)
try
catch
EASYconsole
end
end
function QkviewN_Callback(~, ~, ~)
try
QkviewImages
catch
EASYconsole
end
end
function CFdisplay_Callback(~, ~, ~)
try
NCsingleDisplay
EASYconsole
catch
EASYconsole
end
end

View File

@@ -0,0 +1,458 @@
%% CALLED WHEN ACCESSING 'CurveFit Display' %%
function [scLst, row, col] = NCdisplayGui(projectScansDir)
xPos=0.05;
btnWid=0.10;
btnHt=0.05;
spacing=0.02; % Spacing between the button and the next command's label
% Figure
% The ADD Groups button
btnNumber=1;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
row=1;
hedit=uicontrol(...
'Style', 'edit',...
'String',row,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@editRowNum}); % 'Position', [5 100 60 20])
function editRowNum(source,~)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<0)||(user_entry>17) )
errordlg('Enter a Row between 1 and 16','Bad Input','modal')
return
end
row=user_entry;
end
btnNumber=2;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
col=1;
hedit=uicontrol(...
'Style', 'edit',...
'String',col,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@entryColNum}); % 'Position', [5 100 60 20])
function entryColNum(source,~)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<0)||(user_entry>25))
errordlg('Enter a Column between 1 and 24','Bad Input','modal')
return
end
col=user_entry;
end
% Read in numeric folder names
nlist=dir(fullfile(projectScansDir,'*'));
nnn=0;
for n=1:size(nlist,1)
if (~isempty(str2num(nlist(n).name)))
nnn=nnn+1;
PnumLst(nnn)=(str2num(nlist(n).name));
slst(nnn,1)={nlist(n).name};
slst(nnn,1)={(nlist(n).name)};
end
end
hListbox=uicontrol(...
'Style', 'listbox',...
'String',sort(slst),...
'value',[],...
'max',1000,...
'min',1,...
'Units','normalized',...
'Position', [.40 .40 .10 .60],...
'callback',{@load_listbox}); %'uiresume(gcbf)'); 'Position', [5 100 60 20])
function load_listbox(source,~)
userIndx=(get(source,'value'));
userStr=(get(source,'string'));
%scLstIndx=str2num(char(strrep(userStr(userIndx), 'Scan', '')))
user_entry=userStr(userIndx);
scLst=user_entry;
end
btnNumber=10;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
hedit8=uicontrol(...
'Style', 'pushbutton',...
'String',{'Continue'},...
'Units','normalized',...
'Position', btnPos,...
'callback','uiresume(gcbf)');
% Labels
xLPos=0.175;
yPos=0;
btnWid=0.20;
lblNumber=1;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Row',...
'Units','normalized',...
'Position', btnPos);
lblNumber=2;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Column',...
'Units','normalized',...
'Position', btnPos);
% Not needed for Ncode ImRobot
uiwait(gcf);
end %function end $$$$$[/INST]
%}
%{
%-------------------333333-----------
lblNumber=3;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','BG Threshold (%above) Detection',...
'Units','normalized',...
'Position', btnPos);
%-------------------4-----------
lblNumber=4;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','SpotDetThres(1-60%)',...
'Units','normalized',...
'Position', btnPos);
%-------------------55555-----------
lblNumber=5;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Radius',... %'String','Width',...
'Units','normalized',...
'Position', btnPos);
%-------------------66666-----------
lblNumber=6;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Dither',...
'Units','normalized',...
'Position', btnPos);
%-------------------77777-----------
lblNumber=7;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','SearchRange',...
'Units','normalized',...
'Position', btnPos);
%-------------------88888-----------
%{
lblNumber=8;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Blank2',...
'Units','normalized',...
'Position', btnPos);
%----------------------------------------
%}
%}
%{
%-------------------66666-----------
btnNumber=6;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcExtendFactor=ImParMat(7);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcLoIntensThres,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entryExtendFactor});
function entryExtendFactor(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<1.8)||(user_entry>4.0))
errordlg('You must enter a numeric value between 1.8 and 2.1','Bad Input','modal')
return
end
ExtendFactor=user_entry
ImParMat(7)= ExtendFactor
ExtendFactor
end
%}
%{
%-------------------333333-----------
btnNumber=3;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcBGthreshold=ImParMat(3);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcBGthreshold,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@entryBGthreshold}); % 'Position', [5 100 60 20])
function entryBGthreshold(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<1)||(user_entry>100))
errordlg('Enter a numeric value between 1 and 100 percent to produce a Background Threshold value as a percent above the time series average background for each spot.','Bad Input','modal')
return
end
BGthresInput=user_entry
ImParMat(3)= BGthresInput
BGthresInput
end
%-------------------444444-----------
btnNumber=4; %Enter spot detection threshold (lock-in Image frame)
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcSpotThres=ImParMat(4);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcSpotThres,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entrySpotThres});
function entrySpotThres(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<1)||(user_entry>60))
errordlg('You must enter a numeric value between 1 and 60','Bad Input','modal')
return
end
spotThres=user_entry
ImParMat(4)= spotThres
spotThres
end
%
%---------555555 Radius Entry After Sept.2014---------------------------------**
btnNumber=5;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcRadius=ImParMat(10);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcRadius,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@entryRadius}); % 'Position', [5 100 60 20])
function entryRadius(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<12)||(user_entry>17))
errordlg('You must enter a numeric value between 12 and 17','Bad Input','modal')
return
end
Radius=user_entry
ImParMat(10)= Radius
Radius
end
%---------555555 Width Entry prior the Sept.2014---------------------------------**
%{
btnNumber=5;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcWidth=ImParMat(5);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcWidth,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@entryWidth}); % 'Position', [5 100 60 20])
function entryWidth(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<5)||(user_entry>41))
errordlg('You must enter a numeric value between 5 and 40','Bad Input','modal')
return
end
Width=user_entry
ImParMat(5)= Width
Width
end
%}
%-------------------66666 Dither unnecessary after Sept.2014-----------
btnNumber=6;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcDither= ImParMat(6);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcDither,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entryDither});
function entryDither(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<0)||(user_entry>5))
errordlg('You must enter a numeric value between 1 and 4','Bad Input','modal')
return
end
Dither=user_entry
ImParMat(6)= Dither
Dither
end
%-------------------77777----------- Added July 7,2015 to allow Search Range constraint
btnNumber=7;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
try
srchRange=ImParMat(12);
searchRangeNum=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.
srchRange=18;
ImParMat(12)=18
searchRangeNum=ImParMat(12)
end
%{
if size(scLst)>1
srchRange=ImParMat(12);
else
try
srchRange=CSearchRange(str2double(scLst))
catch
srchRange=ImParMat(12);
end
end
%}
hSearchRange=uicontrol(...
'Style', 'edit',...
'String',srchRange,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@CsearchRange});
function CsearchRange(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<1)||(user_entry>50)) %originally 18; 19_0729 increased
errordlg('You must enter a numeric value between 1 and 18 12->18 recommended. (ImParMat(12)))','Bad Input','modal')
return
end
searchRangeNum=user_entry
end
%-------------------77777-----------
%{
btnNumber=7;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcExtend=ImParMat(7);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcExtend,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entryExtend});
function entryExtend(source,eventdata)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<-0.10)||(user_entry>0.4))
errordlg('You must enter a numeric value between 0 and 0.4. 0.10 recommended','Bad Input','modal')
return
end
extend=user_entry
ImParMat(7)= extend
extend
end
%-------------------888888-----------
btnNumber=8;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
%ImParMat(8)=1;
srcpointExtend=ImParMat(8);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcpointExtend,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entrypointExtend});
function entrypointExtend(source,eventdata)
user_entry=str2double(get(source,'string'));
user_entry= floor(user_entry);
if (isnan(user_entry)||(user_entry<-3)||(user_entry>5))
errordlg('You must enter an integer value between 0 and 5. 1 recommended','Bad Input','modal')
return
end
pointExtend=user_entry
ImParMat(8)= pointExtend
pointExtend
end
%}
%-------------------999999-----------
btnNumber=9;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
hedit=uicontrol(...
'Style', 'popupmenu',...
'String',{'GrowthArea','FixedArea'},...
'Units','normalized',...
'Position', btnPos,...
'callback',{@grwArea});
function grwArea(source,eventdata)
str=get(source, 'String');
val=get(source,'Value');
% Set current data to the selected data set.
switch str{val};
case 'GrowthArea' ;% User selects Peaks.
SWgrowthArea=1
case 'FixedArea' % User selects Membrane.
SWgrowthArea=0
end
end
%}

View File

@@ -0,0 +1,232 @@
%% CALLED BY par4GblFnc8c.m %%
function [par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanIntensELr,par4scanCFparameters,par4scanCFdate,outC,outCstd]= ...
NCfitImCFparforFailGbl2(parMat,times, values, timeOffsets, fileSuffix, AUCfinalTime, ~, spotAreas, printResultsDir, ~,~, 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);
% 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
% add offset...1 offset PER PLATE
timepts=times + timeOffsets; % (floor((ii-1)/arrayFormat) + 1);
currValues=values(ii,:); % change values(spotNum,:);
% get spot areas for this culture
currSpotArea=spotAreas(:,ii);
% just use the area at the last time point
% 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
timepts=timepts; % timepts=currTimes; parfor
normIntens=currNormIntens;
dataMatrix=[]; % arfor move clear from NCfitImCF...m
loIntensThres=parMat(4);
stdLoIntLim=parMat(5);
% 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);
% Initialize dataMatrix
dataMatrix(1,:)=timepts;
dataMatrix(2,:)=normIntens;
dataMatrix(3,:)=ones;
dataMatrix(4,:)=normIntens;
% 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;
end
if n<(length(nrmIntens0)-3)
x=nrmIntens0(n:(n+3));
stdDev(n)=std(x);
if (stdDev(n)<loScurvLim && flg1~=1)
loStime=timepts(n);
loStimeN=n;
end
if stdDev(n)>6
flg1=1;
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
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);
if (length(qind)>5)&&I>1
dataMatrix(3,1:(I-1))=5;
end
tGT2Flg=0;
for n=1:length(normIntens)
dataMatrix(4,n)=normIntens(n)-bl;
if n>I && dataMatrix(4,n)>=2 && tGT2Flg==0
thresGT2=n;thresGT2Tm=dataMatrix(1,n);tGT2Flg=1;
end
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(((normIntens(n)- normIntens(n-1))< dropThreshold)) && ...
(n > max(meanIntIndPt,thresGT2) )
dataMatrix(3,n)=6;
end
end
end
% TODO should/could this be removed as recreated in%NCscurImCF_3parfor.m
% Post Stdtest cull for low intensities inclusion of additional low value points
% selTimes=[--,--] %don't know size before as it is a filtered output
tmpIndx=0;
for n=1:length(normIntens)
if (dataMatrix(3,n)==1)
tmpIndx=tmpIndx+1;
selTimes(tmpIndx)=dataMatrix(1,n); % selTimes(nn)=dataMatrix(1,n);
selIntens(tmpIndx)=dataMatrix(4,n); %s elIntens(nn)=dataMatrix(4,n);
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
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
outC(ii,:)=resMat; %{ii, par4resMat};
outCstd(ii,:)=resMatStd; %{ii, par4resMatStd};
end
% 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(printResultsDir, fileNamePlate); %[printResultsDir 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

View File

@@ -0,0 +1,353 @@
%% CALLED BY NCfitImCFparforFailGbl2.m %%
function [resMatStd, resMat, selTimesStd, selIntensStd, FiltTimesELr, NormIntensELr] =...
NCscurImCF_3parfor(dataMatrix, AUCfinalTime, currSpotArea, sols, bl, minTime)
% Preallocate
resMatStd=zeros(1,27);
resMat=zeros(1,27);
% Set internal variables sent to matlab fit function
me=200;
meL=750;
mi=25;
miL=250;
rmsStg1=0;
rmsStg1I(1)=0;
slps=1;
filterTimes=[];
normIntens=[];
nn=1;
numFitTpts=0;
% Build filterTimes and normIntens from spot dataMatrix selection codes produced in filter section
for n=1:size(dataMatrix,2)
if (((dataMatrix(3,n)==1))||(dataMatrix(3,n)==3)||(dataMatrix(3,n)==2)...
||(dataMatrix(3,n)==0))
filterTimes(nn)=dataMatrix(1,n);
normIntens(nn)=dataMatrix(4,n);
nn=nn+1;
end
end
filterTimes=filterTimes';
selTimesStd=filterTimes;
normIntens=normIntens';
selIntensStd=normIntens;
lastTptUsed=1;
lastIntensUsed=1;
thresGT2TmStd=0;
try
lastTptUsed=max(filterTimes);
lastIntensUsed=normIntens(length(normIntens));
lastIntensUsedStd=lastIntensUsed;
lastTptUsedStd=lastTptUsed;
Tpt1Std=filterTimes(1);
numFitTptsStd=nnz((normIntens(:)>=0)==1);
thresGT2=find(((normIntens(:)>2)==1), 1);
if isempty(thresGT2)
thresGT2TmStd=0;
else
thresGT2TmStd=filterTimes(thresGT2);
end
numTptsGT2Std=nnz((normIntens(:)>=2)==1); % nnz(filterTimes(find(filterTimes>=thresGT2Tm)));
K_Guess=max(normIntens);
numTimePts=length(filterTimes);
opts=fitoptions('Method','Nonlinear','Robust','On','DiffMinChange',1.0E-11,'DiffMaxChange',0.001,...
'MaxFunEvals',me, 'MaxIter', mi, 'TolFun', 1.0E-12, 'TolX', 1.0E-10, 'Lower', [K_Guess*0.5,0,0],...
'StartPoint', [K_Guess,filterTimes(floor(numTimePts/2)),0.30], 'Upper', [K_Guess*2.0,max(filterTimes),1.0],'Display','off');
ftype=fittype('K / (1 + exp(-r* (t - l )))','independent','t','dependent',['K','r','l'],'options',opts);
% Carry out the curve fitting process
[fitObject, errObj]=fit(filterTimes,normIntens,ftype);
coeffsArray=coeffvalues(fitObject);
rmsStg1=errObj.rsquare;
rmsStg1I(slps)=errObj.rsquare;
sDat(slps,1)=errObj.rsquare;
K=coeffsArray(1); sDat(slps,2)=coeffsArray(1); % Carrying Capacity
l=coeffsArray(2); sDat(slps,3)=coeffsArray(2); % lag time
r=coeffsArray(3); sDat(slps,4)=coeffsArray(3); % rateS
% Integrate (from first to last time point)
numVals=size(filterTimes);
numVals=numVals(1);
t_begin=0;
t_end=AUCfinalTime;
AUC=(K/r*log(1+exp(-r*(t_end-l)))-K/r*log(exp(-r*(t_end-l)))) - (K/r*log(1+exp(-r*(t_begin-l)))-K/r*log(exp(-r*(t_begin-l))));
MSR=r;
rsquare=errObj.rsquare;
confObj=confint(fitObject,0.9); % get the 90% confidence
NANcond=0; stdNANcond=0; % stdNANcond added to relay not to attempt ELr as there is no curve to find critical point
confObj_filtered=confObj;
Klow=confObj(1,1); sDat(slps,5)=confObj(1,1);
Kup=confObj(2,1); sDat(slps,6)=confObj(2,1);
llow=confObj(1,2); sDat(slps,7)=confObj(1,2);
lup=confObj(2,2); sDat(slps,8)=confObj(2,2);
rlow=confObj(1,3); sDat(slps,9)=confObj(1,3);
rup=confObj(2,3); sDat(slps,10)=confObj(2,3);
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
% 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;
NANcond=1; stdNANcond=1; %stdNANcond added to relay not to attempt ELr as there is no curve to find critical point
end
if (exist('K','var')&& exist('r','var') && exist('l','var'))
t=(0:1:200);
Growth=K ./ (1 + exp(-r.* (t - l )));
fitblStd=min(Growth);
end
cutTm(1:4)=1000; %-1 means cuts not used or NA
% Preserve for ResultsStd
resMatStd(1)=AUC;
resMatStd(2)=MSR;
resMatStd(3)=K;
resMatStd(4)=r;
resMatStd(5)=l;
resMatStd(6)=rsquare;
resMatStd(7)=Klow;
resMatStd(8)=Kup;
resMatStd(9)=rlow;
resMatStd(10)=rup;
resMatStd(11)=llow;
resMatStd(12)=lup;
resMatStd(13)=currSpotArea;
resMatStd(14)=lastIntensUsedStd; % filtNormIntens(length(filtNormIntens));
maxRateTime=0; %[]; %Std shows []; ELr shows 0; %parfor
resMatStd(15)=0; %maxRateTimestdMeth;
resMatStd(16)=lastTptUsedStd;
if isempty(Tpt1Std)
Tpt1Std=777;
end
resMatStd(17)=Tpt1Std;
resMatStd(18)=bl; % perform in the filter section of NCfitImCFparfor
resMatStd(19)=fitblStd; % taken from NCfil... and not affected by NCscur...changes
resMatStd(20)=minTime; % not affected by changes made in NCscur...for refined 'r'
resMatStd(21)=thresGT2TmStd;
resMatStd(22)=numFitTptsStd;
resMatStd(23)=numTptsGT2Std;
resMatStd(24)=999; % yhe Standard method has no cuts .:.no cutTm
resMatStd(25)=999;
resMatStd(26)=999;
resMatStd(27)=999;
% ELr New Experimental data through L+deltaS Logistic fit for 'Improved r' Fitting
FiltTimesELr=[]; %{ii}=filterTimes;
NormIntensELr=[]; %{ii}=normIntens;
normIntens=selIntensStd;
filterTimes=selTimesStd;
stdIntens=selIntensStd;
tmpIntens=selIntensStd;
stdTimes=selTimesStd;
if stdNANcond==0
% Determine critical points and offsets for selecting Core Data based on
% Standard curve fit run. Put diff into NImStartupImCF02.m calling source
% to reduce repeated execution since it doesn't change.
% fd4=diff(sym('K / (1 + exp(-r* (t - l )))'),4);
% sols=solve(fd4);
tc1=eval(sols(2));
tc2=eval(sols(3));
LL=l; %eval(sols(1)); %exactly the same as 'l' from std. fit method-Save time
rsTmStd=LL-tc1; %%riseTime (first critical point to L)
deltS=rsTmStd/2;
tc1Early=tc1-deltS; %AKA- tc1AdjTm %2*tc1 -LL
L_Late=LL+deltS;
tc1EdatPt=find(filterTimes>(tc1Early),1,'first');
cutTm(1)=filterTimes(2);
cutDatNum(1)=2;
cutTm(2)=tc1Early;
cutDatNum(2)=tc1EdatPt-1;
L_LDatPt=find(filterTimes< L_Late,1,'last');
tc2LdatPt=find(filterTimes< tc2+rsTmStd,1,'last');
cutTm(3)=L_Late;
cutDatNum(3)=L_LDatPt;
% Select Core Data Set (Remove Early data before critical point)
ints=[];
ints(1:L_LDatPt-tc1EdatPt+2)=(tmpIntens(L_LDatPt));
ints(2:end)=tmpIntens(tc1EdatPt:L_LDatPt);
ints(1)=tmpIntens(1);
tms=[];
tms(1:L_LDatPt-tc1EdatPt+2)=(stdTimes(L_LDatPt));
tms(2:end)=stdTimes(tc1EdatPt:L_LDatPt);
tms(1)=stdTimes(1);
% Include/Keep late data that define K
if length(tmpIntens(tc2LdatPt:end))> 4
KlastInts=tmpIntens(tc2LdatPt:end);
KlastTms=stdTimes(tc2LdatPt:end);
lengthKlast=length(tmpIntens(tc2LdatPt:end));
ints(end:(end+ lengthKlast-1))=KlastInts;
tms(end:(end+ lengthKlast-1 ))=KlastTms;
cutTm(4)=tc2+rsTmStd;
cutDatNum(4)=tc2LdatPt-1;
else
lengthKlast=length(tmpIntens(tc2LdatPt-1:end));
if lengthKlast>1
KlastInts=tmpIntens(end-(lengthKlast-1):end);
KlastTms=stdTimes(end-(lengthKlast-1):end);
ints(end:(end+ lengthKlast-1 ))=KlastInts;
tms(end:(end+ lengthKlast-1 ))=KlastTms;
end
cutTm(4)=stdTimes(tc2LdatPt-1);
cutDatNum(4)=tc2LdatPt-2; %length(stdTimes(end-(lengthKlast-1):end));
end
Ints=[];
Tms=[];
Ints=ints';
Tms=tms';
try
filterTimes=Tms; filterTimes4=Tms;
normIntens=Ints; normIntens4=Ints;
% Classic symmetric logistic curve fit setup restated as COMMENTS for reference convenience
% opts=fitoptions is the same as for Std and so is redundant
% opts=fitoptions('Method','Nonlinear','Robust','On',...
% 'DiffMinChange',1.0E-11,'DiffMaxChange',0.001,...
% 'MaxFunEvals',me, 'MaxIter', mi, 'TolFun', 1.0E-12, 'TolX', 1.0E-10, 'Lower', [K_Guess*0.5,0,0], 'StartPoint', [K_Guess,filterTimes(floor(numTimePts/2)),0.30], 'Upper', [K_Guess*2.0,max(filterTimes),1.0]);
ftype=fittype('K / (1 + exp(-r* (t - l )))','independent','t','dependent',['K','l','r'],'options',opts);
fitObject=[]; errObj=[];
% carry out the curve fitting process
[fitObject, errObj]=fit(Tms,Ints,ftype);
coeffsArray=coeffvalues(fitObject);
r3=coeffsArray(3); % sDat(slps,4)=coeffsArray(3); % rateS
if (exist('K','var')&& exist('r','var') && exist('l','var'))
t=(0:1:200);
GrowthELr=K ./ (1 + exp(-r.* (t - l )));
fitblELr=min(GrowthELr); %jh diag
end
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=[];
end
end
% Update values if r is better(higher) with removal of early data
try
if r3>r && stdNANcond==0
r=r3; sDat(slps,4)=sDat(slps,4); % rateS
K=coeffsArray(1); sDat(slps,2)=coeffsArray(1); % Carrying Capacity
l=coeffsArray(2); sDat(slps,3)=coeffsArray(2); % lag time
coeffsArray=coeffvalues(fitObject);
rmsStg1=errObj.rsquare;
rmsStg1I(slps)=errObj.rsquare;
sDat(slps,1)=errObj.rsquare;
% JH diagnostics
numFitTpts=nnz((normIntens(:)>=0)==1);
thresGT2=find(((normIntens(:)>2)==1), 1);
thresGT2Tm=filterTimes(thresGT2);
numTptsGT2=nnz((normIntens(:)>=2)==1);
numTimePts=length(filterTimes);
AUC=(K/r*log(1+exp(-r*(t_end-l)))-K/r*log(exp(-r*(t_end-l)))) - (K/r*log(1+exp(-r*(t_begin-l)))-K/r*log(exp(-r*(t_begin-l))));
MSR=r3;
rsquare=errObj.rsquare;
confObj=confint(fitObject,0.9); % get the 90% confidence
NANcond=0;
confObj_filtered=confObj;
Klow=confObj(1,1); sDat(slps,5)=confObj(1,1);
Kup=confObj(2,1); sDat(slps,6)=confObj(2,1);
llow=confObj(1,2); sDat(slps,7)=confObj(1,2);
lup=confObj(2,2); sDat(slps,8)=confObj(2,2);
rlow=confObj(1,3); sDat(slps,9)=confObj(1,3);
rup=confObj(2,3); sDat(slps,10)=confObj(2,3);
if(isnan(Klow)||isnan(Kup)||isnan(llow)||isnan(lup)||isnan(rlow)||isnan(rup))
NANcond=1;
end
filterTimes=Tms;
normIntens=Ints;
resMat(17)=.00002;
resMat(18)=bl;
resMat(19)=fitblELr;
resMat(20)=minTime;
else % r is better than r3 so use the Std data in the ELr result sheet
filterTimes=selTimesStd;
normIntens=selIntensStd;
lastTptUsed=lastTptUsedStd; % Reinstall Std values for jh diags
Tpt1=filterTimes(1);
try
if isempty(Tpt1)
Tpt1=0.00002; %777;
end
catch
Tpt1=0.00002; %777;
end
resMat(17)=Tpt1;
numFitTpts=numFitTptsStd;
numTptsGT2=numTptsGT2Std;
thresGT2Tm=thresGT2TmStd;
cutTm(1:4)=1000; % 1 means cuts not used or NA
resMat(18)=bl; % only applicable to Std curve Fit; ELr superceeds and makes meaningless
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
% 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=[];
end
resMat(1)=AUC;
resMat(2)=MSR;
resMat(3)=K;
resMat(4)=r;
resMat(5)=l;
resMat(6)=rsquare;
resMat(7)=Klow;
resMat(8)=Kup;
resMat(9)=rlow;
resMat(10)=rup;
resMat(11)=llow;
resMat(12)=lup;
resMat(13)=currSpotArea;
resMat(14)=lastIntensUsed; %filtNormIntens(length(filtNormIntens));
% spline fit unneccessary and removed therfor no max spline rate time->set 0
maxRateTime=0; % ELr will show 0; Std will show []
resMat(15)=maxRateTime;
resMat(16)=lastTptUsed; % filterTimes(length(filterTimes));
try % if Std fit used no cuts .:. no cutTm
resMat(24)=cutTm(1);
resMat(25)=cutTm(2);
resMat(26)=cutTm(3);
resMat(27)=cutTm(4);
catch
resMat(24)=999; % if Std fit used no cuts .:. no cutTm
resMat(25)=999;
resMat(26)=999;
resMat(27)=999;
end
FiltTimesELr=filterTimes;
NormIntensELr=normIntens;
lastTptUsed=max(filterTimes);
lastIntensUsed=normIntens(length(normIntens));
if (exist('K','var')&& exist('r','var') && exist('l','var'))
t=(0:1:200);
Growth=K ./ (1 + exp(-r.* (t - l )));
fitbl=min(Growth); % jh diag
end
try % jh diag
if isempty(thresGT2Tm)
thresGT2Tm=0
end
catch
thresGT2Tm=0;
numTptsGT2=0;
end
resMat(21)=thresGT2Tm;
resMat(22)=numFitTpts;
resMat(23)=numTptsGT2;
end

View File

@@ -0,0 +1,89 @@
%% CALLED WHEN ACCESSING 'CurveFit Display' %%
global scLst
global scan
hf=figure;
% Parameter Entry
[scLst, row, col]=NCdisplayGui(projectScansDir);
close(hf)
selSpot=(row-1)*24 + col;
for iPlate=1:length(scLst)
scanPltNum=str2double(scLst(iPlate));
K=scan(scanPltNum).plate(1).CFout((selSpot),3);
r=scan(scanPltNum).plate(1).CFout((selSpot),4);
l=scan(scanPltNum).plate(1).CFout((selSpot),5);
suffix=strcat('Scan-Plate', scLst(iPlate)); % char(QspLst(n));
% fileSpotSuffix=strcat('-Spot#',num2str(selSpot),'-Row=',selSpotRC(1),'-Col=',selSpotRC(2),'-FitData','-L=',num2str(l),'-r=',num2str(r),'-K=',num2str(K));
fileSpotSuffix=strcat('-Spot#',num2str(selSpot),'-Row=',num2str(row),'-Col=',num2str(col),'-FitData','-L=',num2str(l),'-r=',num2str(r),'-K=',num2str(K));
filenameNoExt=[suffix fileSpotSuffix];
timeArr=scan(scanPltNum).plate(1).tSeries;
rawIntens=scan(scanPltNum).plate(1).intens((selSpot),:)/scan(scanPltNum).plate(1).Ag((selSpot));
try
filterTms=scan(scanPltNum).plate(1).filterTimes{(selSpot)};
normInts=scan(scanPltNum).plate(1).normIntens{(selSpot)};
catch
end
if (exist('K','var')&& exist('r','var') && exist('l','var'))
t=(0:1:200);
Growth=K ./ (1 + exp(-r.* (t - l )));
end
if length(scLst)>1
figure
else
cla
end
hold on
plot(timeArr,rawIntens,'g*');
try
plot(filterTms,normInts,'o');
catch
end
hold on;
title(filenameNoExt); % this didn't make sense so changed
xlabel('Hours');
ylabel('Intensities Normalized by Area');
grid on;
if (exist('K','var')&& exist('r','var') && exist('l','var'))
plot(t, Growth,'b-');
% Plot L on curvefit figure
grL=Growth(round(l)); % growthCurve timePT for l in hours
plot(l,0:grL,'-b') % to display position of l
plot(l,grL,'^b') % to display l position on curve as an arrowhead
% Plot Arbitrary User Entry AUC "finalTimePt"
% plot(finalTimePt,0,'+m')
% plot(0:finalTimePt,bl,'-m')
end
end
%Spot entry form------------------------------------------------------
%{
prompt={'Enter spot to analyse:'};
dlg_title='Input spot to curve fit';
num_lines=1;
def={'1'};
selSpot=inputdlg(prompt,dlg_title,num_lines,def);
K=scan(scanPltNum).plate(1).CFout(str2double(selSpot),3);
r=scan(scanPltNum).plate(1).CFout(str2double(selSpot),4);
l=scan(scanPltNum).plate(1).CFout(str2double(selSpot),5);
suffix=strcat('Scan-Plate', scLst); %char(QspLst(n));
fileSpotSuffix=strcat('-Spot#',selSpot,'-FitData','-L=',num2str(l),'-r=',num2str(r),'-K=',num2str(K));
filenameNoExt=[suffix fileSpotSuffix];
timeArr=scan(scanPltNum).plate(1).tSeries;
rawIntens=scan(scanPltNum).plate(1).intens(str2double(selSpot),:)/scan(scanPltNum).plate(1).Ag(str2double(selSpot));
filterTms=scan(scanPltNum).plate(1).filterTimes{str2double(selSpot)};
normInts=scan(scanPltNum).plate(1).normIntens{str2double(selSpot)};
%}
%-----------------------------------------------------------------------
%{
prompt={'Enter Spot row:','Enter Spot column:'};
dlg_title='Input spot to curve fit';
num_lines=2;
def={'1','1'};
selSpotRC=inputdlg(prompt,dlg_title,num_lines,def);
row=str2double(selSpotRC(1)); col=str2double(selSpotRC(2));
%}
%row=cell2mat(row);

View File

@@ -0,0 +1,59 @@
%% CALLED BY par4Gbl_Main8c.m %%
%{
%Imaging ToolBox method
r=14;
A=zeros(70,70); %(fIntsc(refPtR:(refPtRExt),refPtC:(refPtCExt)))
m={40,40};
A(m{:})=1;
B=imdilate(A,strel('disk',r,0) );
imshow(B)
area=pi*r^2
clear all
%}
%without Image Proc. Toolbox
%r=14;
%A=zeros(70,70);
%A=zeros(r,r);
%P=[40,40];
%center=[refPtR+ round(.5*width), refPtC+ round(.5*width)];
%A=zeros(70,70);
%---------------------------------------------------------------------
%radius=14;
diaExt=2*(radius+1);
circBoxA=zeros(diaExt,diaExt);
center=[radius+2, radius+2];
[m,n]=size(circBoxA);
X=bsxfun(@plus,(1:m)', zeros(1,n));
Y=bsxfun(@plus,(1:n), zeros(m,1));
cirMask=sqrt(sum(bsxfun(@minus,cat(3,X,Y),reshape(center,1,1,[])) .^2,3))<=radius;
area=pi*radius^2;
cirPixA=nnz(cirMask);
optCirMask=double(cirMask);
optCirMask(optCirMask==0)=0.8;
% Foto Circle Fram(e)
expansion=2;
radExpan=radius+expansion;
FdiaExt=2*(radExpan);
circBoxA=zeros(FdiaExt,FdiaExt);
center=[radExpan+1, radExpan+1];
[m, n ]=size(circBoxA);
X=bsxfun(@plus,(1:m)', zeros(1,n));
Y=bsxfun(@plus,(1:n), zeros(m,1));
FcirMask=sqrt(sum(bsxfun(@minus,cat(3,X,Y),reshape(center,1,1,[])) .^2,3))<=radExpan;
%FcirPixA=nnz(cirMask);
FoptCirMask=double(FcirMask);
FoptCirMask(FoptCirMask==1)=2;
%FoptCirMask(FoptCirMask==0)=1;
%********Combine Masks to create circular boundry************
padOptCirMask=padarray(optCirMask,[expansion-1 expansion-1],0.8);
FoptCirMask=FoptCirMask .* padOptCirMask;
FoptCirMask(FoptCirMask==1.6)=0.8;
FoptCirMask(FoptCirMask==0)=1;
FoptCirMask(FoptCirMask==2)=1;
%---------------------------------------------------
%imagesc(cirMask)

View File

@@ -0,0 +1,247 @@
%% CALLED BY par4Gbl_Main8c.m %%
% TODO Should some of these vars be pulled out higher so they are easier to change?
%
function NImParamRadiusGui(projectScansDir)
global SWsingleSc
global SWgrowthArea
global scan
global scLst
global ImParMat
global searchRangeNum
global defImParMat
global fhImRun
global fhconsole
global easyResultsDir
global fotosResultsDir
global pointMapsResultsDir
global pointMapsFile
global matFile
global numRows
global numCols
global scanSize
global scanMax
global searchRangeFile
% Ncode ImRobot adaptation
% TODO this code block and variables needs explanation
defImParMat=[1,1,15,34,24,1,0,0,1,14,1,18];
if ImParMat(3)==0 || ImParMat(4)==0 ||ImParMat(5)==0 || ImParMat(10)==0 ||ImParMat(11)==0
ImParMat=defImParMat;
end
if size(ImParMat,2)<12
ImParMat(12)=18; % default before user input CsearchRange value
msg='Data made before SearchRange user entry added (ImParMat(12). 18 was the set value and the current default.)';
end
% ImParMat=defImParMat; %Activate for INITIAL USE only
MPnum=1;
destPerMP=1;
selScan=1;
SWgrowthArea=1;
if exist(pointMapsFile, 'file')
load(pointMapsFile);
else
load(fullfile(easyDir, 'PTmats', 'NImParameters')) % hardcoded default
disp('WARNING: Using hardcoded NImParameters.mat')
end
ImParMat;
% if ~exist('searchRangeNum','var') || isempty(searchRangeNum)
if exist(searchRangeFile, 'file')
load(searchRangeFile);
CSearchRange; % TODO, might be an issue, figure out what this is doing
end
% yInitPos=0.30;
xPos=0.05;
btnWid=0.10;
btnHt=0.05;
spacing=0.02;% Spacing between the button and the next command's label
% The ADD Groups button
btnNumber=1;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
fhImParm=gcf;
if exist('easyResultsDir','var')&& ~isempty(easyResultsDir)
set(fhImParm,'NumberTitle','off')
set(fhImParm,'Name',strcat('ImageAnalysis- ',char(easyResultsDir)))
else
set(fhImParm,'NumberTitle','off')
set(fhImParm,'Name','EASYconsole - Exp. Analysis NOT selected.')
end
btnNumber=5;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcRadius=ImParMat(10);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcRadius,...
'Units','normalized',...
'Position', btnPos,... % [.002 .70 .08 .10],...
'callback',{@entryRadius}); % 'Position', [5 100 60 20])
function entryRadius(source,~)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<12)||(user_entry>17))
errordlg('You must enter a numeric value between 12 and 17','Bad Input','modal')
return
end
Radius=user_entry;
ImParMat(10)=Radius;
Radius;
end
btnNumber=6;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
srcDither=ImParMat(6);
hedit=uicontrol(...
'Style', 'edit',...
'String',srcDither,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@entryDither});
function entryDither(source,~)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<0)||(user_entry>5))
errordlg('You must enter a numeric value between 1 and 4','Bad Input','modal')
return
end
Dither=user_entry;
ImParMat(6)=Dither;
Dither;
end
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.
srchRange=18;
ImParMat(12)=18;
end
hSearchRange=uicontrol(...
'Style', 'edit',...
'Value',searchRangeNum,...
'Units','normalized',...
'Position', btnPos,...
'callback',{@searchRangeCallback});
function searchRangeCallback(source,~)
user_entry=str2double(get(source,'string'));
if (isnan(user_entry)||(user_entry<1)||(user_entry>50)) %originally 18; 19_0729 increased
errordlg('You must enter a numeric value between 1 and 18 12->18 recommended. (ImParMat(12)))','Bad Input','modal')
return
end
searchRangeNum=user_entry;
end
% Ncode 12_0120 for reading in numeric folder names
nlist=dir(fullfile(projectScansDir,'*'));
nnn=0;
for n=1:size(nlist,1)
if (~isempty(str2num(nlist(n).name)))
nnn=nnn+1;
PnumLst(nnn)=(str2num(nlist(n).name));
sl(nnn,1)={(nlist(n).name)};
end
end
scanSize=size(sl,1);
scanMax=max(str2double(sl));
hListbox=uicontrol(...
'Style', 'listbox',...
'String',sort(sl),...
'value',[],...
'max',1000,...
'min',1,...
'Units','normalized',...
'Position', [.70 .40 .10 .60],...
'callback',{@load_listbox}); %'uiresume(gcbf)'); 'Position', [5 100 60 20])
function load_listbox(source,~)
userIndx=(get(source,'value'));
userStr=(get(source,'string'));
%scLstIndx=str2num(char(strrep(userStr(userIndx), 'Scan', '')))
user_entry=userStr(userIndx);
scLst=user_entry;
if size(scLst,1)>1
% searchRangeNum=num2str(ImParMat(12))
set(hSearchRange,'string',num2str(ImParMat(12)))
else
try
searchRangeNum=CSearchRange(str2double(scLst));
set(hSearchRange,'string',CSearchRange(str2double(scLst)))
catch
% CSrchRng=num2str(ImParMat(12))
% set(hSearchRange,'string',num2str(ImParMat(12)))
end
end
end
scLst;
btnNumber=10;
yPos=0.85-(btnNumber-1)*(btnHt+spacing);
btnPos=[xPos yPos-spacing btnWid btnHt];
hedit8=uicontrol(...
'Style', 'pushbutton',...
'String',{'Continue'},...
'Units','normalized',...
'Position', btnPos,...
'callback','uiresume(gcbf)');
% Labels
xLPos=0.175;
yPos=0;
btnWid=0.20;
lblNumber=5;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Radius',... %'String','Width',...
'Units','normalized',...
'Position', btnPos);
lblNumber=6;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','Dither',...
'Units','normalized',...
'Position', btnPos);
lblNumber=7;
yPos=0.85-(lblNumber-1)*(btnHt+spacing);
btnPos=[xLPos yPos-spacing btnWid btnHt];
htxt=uicontrol(...
'Style', 'text',...
'String','SearchRange',...
'Units','normalized',...
'Position', btnPos);
uiwait(gcf);
for i=1:length(scLst)
CSearchRange(str2double(scLst(i)))=CSrchRng;
ImParMat(12)=CSrchRng;
end
ImParMat;
searchRangeNum;
save(pointMapsFile, 'ImParMat');
save(searchRangeFile,'searchRangeNum');
close
return
end

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,15 @@
%% PART OF GUI FUNCTIONALITY %%
% Display the position of the data cursor
function output_txt = datatipp(~,event_obj)
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos=get(event_obj,'Position');
output_txt={['X: ',num2str(pos(1),4)],['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1}=['Z: ',num2str(pos(3),4)];
end
end

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,36 @@
%% CALLED BY par4Gbl_Main8c.m %%
function[p4L4,...
TmpexpScanIntens4,TmpFexpScanSpots4,TmpFexpScanBMtp4,TmpanlZoneRefs4,Tmpsbdg4]= ...
p4loop8c(parMat,tptLength,numScans,selScanNumLst,SWsingleSc,Fflg,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,cirMask,width, ...
TmpexpScanIntens00,TmpFexpScanSpots00,TmpFexpScanBMtp00,TmpanlZoneRefs00,~,tifFileLstP4,pathname,ImParMat, ...
numRows,numCols,scLst,easyResultsDir,projectScansDir, p4L00,TmpexpScanIntens4,TmpFexpScanSpots4,TmpFexpScanBMtp4,TmpanlZoneRefs4, Tmpsbdg00, Tmpsbdg4)
p4L0=p4L00;
TmpexpScanIntens0=TmpexpScanIntens00;
TmpFexpScanSpots0=TmpFexpScanSpots00;
TmpFexpScanBMtp0=TmpFexpScanBMtp00;
TmpanlZoneRefs0=TmpanlZoneRefs00;
Tmpsbdg0= Tmpsbdg00;
% for scCount=1:numScans
if SWsingleSc==1
parforArg=0;
else
parforArg=inf;
end
% for (scCount=1:numScans)
parfor (scCount=1:numScans,parforArg)
scCount % for debugging
p4L0=cell(18,1);
[p4L3,TmpexpScanIntens3,TmpFexpScanSpots3,TmpFexpScanBMtp3,TmpanlZoneRefs3,Tmpsbdg3]= ...
par4GblFnc8c(parMat,tptLength,numScans,selScanNumLst,SWsingleSc,Fflg,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,cirMask,width, ...
TmpexpScanIntens0,TmpFexpScanSpots0,TmpFexpScanBMtp0,TmpanlZoneRefs0,scCount,tifFileLstP4,pathname,ImParMat, ...
numRows,numCols, scLst,easyResultsDir,projectScansDir, p4L0,Tmpsbdg0);
p4L4(:,scCount)=p4L3; % (:,scCount);
TmpexpScanIntens4(scCount)=TmpexpScanIntens3;
TmpFexpScanSpots4(scCount)=TmpFexpScanSpots3;
TmpFexpScanBMtp4(scCount)=TmpFexpScanBMtp3;
TmpanlZoneRefs4(scCount)=TmpanlZoneRefs3;
Tmpsbdg4(scCount)=Tmpsbdg3;
end

View File

@@ -0,0 +1,300 @@
%% CALLED By p4loop8c.m %%
function [p4L2, TmpexpScanIntens3,TmpFexpScanSpots3,TmpFexpScanBMtp3,TmpanlZoneRefs3,Tmpsbdg3]= ...
par4GblFnc8c(parMat,tptLength,~,selScanNumLst,~,Fflg,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,cirMask,~,...
TmpexpScanIntens,TmpFexpScanSpots,TmpFexpScanBMtp,TmpanlZoneRefs,scCount,tifFileLstP4,~,ImParMat, ...
numRows,numCols,scLst,easyResultsDir,projectScansDir,~, Tmpsbdg)
global printResultsDir
selScan=selScanNumLst(scCount);
tptLength0=length(tifFileLstP4{scCount});
% tptLength=numFiles;
tifFileLst={tifFileLstP4(scCount)};
% Extract the Imaging time stamps from selected tif files
% clear('e','f'); %can't use clear inside a parfor loop. Preallocation
% can be larger than useable .bmp files! Therefore must be small and
% increased during for loop to maintain cell size integrity between e & f
e=cell(1,2); f=cell(1,2); %(tptLength,2); f=cell(tptLength,2);
nndx=0;
for tPt=1:tptLength0 %size(tifFileLst,1) %length(tifFileLst)
tifFileLstP4{scCount}(tPt)
scLst;
scLst(scCount)
char(scLst(scCount))
char(fullfile(projectScansDir,char(scLst(scCount))))
projectScansDir;
swCatch=0;
nndx=nndx+1;
tifFile=char(fullfile(projectScansDir,char(scLst(scCount)), tifFileLstP4{scCount}(tPt)));
try
info=imfinfo(tifFile); % D:\jwrDevel\DevelCurveFittingJWR\ImageScans\Scan2\020hr002.tif
catch ME
% Note: During parallel operation Matlab will not open file (fid)
% etc. Therefore error message text will not be written.The only way
% to get it out would be to pass variable through called function to
% the ..Main8c script outside the parfor loop and print to file from
% there. Consequently for now it only prints error to file when one
% edits p4loop8c.m from 'parfor' to ordinary 'for' loop
fFail=((fullfile(printResultsDir,'ImageFileReadFailure.txt')));
fid=fopen(fFail,'a'); %create,open and append
% fprintf(fid,'%s \n',char(tifFile))
fclose(fid);
nndx=nndx-1;
swCatch=1;
rep=getReport(ME, 'basic');
rep=strcat('Read info failure for-',tifFile,' -', rep);
% fprintf(fid,'%s \n',rep) %See Note:
end
tptLength=nndx;
scTmNumeric=1; %initialize for parfor
if swCatch==0
scTmNumeric(nndx)=datenum(info.FileModDate);
e(nndx,:)={tifFile, scTmNumeric(nndx)};
% newtifFileLst(nndx)=tifFileLst(tPt);
end
end
% Clear tifFileLst;
tifFileLst=cell(nndx,1);
f={sortrows(e,2)};
tifFileLst=f{1,1}(:,1);
areaOfIntensAboveBG=zeros(24,16,length(tifFileLst));
% Calculate Time series for each Plate of Selected Scan
lastPlateOnScan=1; %Ncode
tSeriesv=[]; t0Seriesv=[];
if tptLength>0 % added to jump over and fill data for invalid Sscan(plate runs
scTmNumv=cell2mat(f{1,1}(:,2)); % (:,2))120613 fix for variant length data
prtTmNumv=min(scTmNumv)-.000001;
tSeriesv=((scTmNumv-prtTmNumv)*24);
t0Seriesv=((scTmNumv-scTmNumv(1))*24);
end
% Added to jump over and fill data for invalid Sscan(plate runs
if tptLength>=3
% Create blank scan
ImHeigth=2075;
ImWidth=1400;
Empsc=zeros(ImHeigth,ImWidth); %Ncode
% Start scan loop
lastPlateOnScan=1; %Ncode
disp('Before call to NIscanIntens.....')
% Execute Image conversion into Intensity Data
[Tmpsbdg2, scanIntens, ~, ~, ~, TmpexpScanIntens2, TmpFexpScanSpots2, TmpFexpScanBMtp2, TmpanlZoneRefs2,areaOfIntensAboveBG]= ...
NIscanIntensBGpar4GblFnc(Fflg,tifFileLst, ImParMat, PTmapPos,optCirMask,diaExt,doCircle,cirPixA,numRows,numCols,ImHeigth,ImWidth,cirMask, ...
tptLength,selScan,Empsc,TmpexpScanIntens,TmpFexpScanSpots,TmpFexpScanBMtp,TmpanlZoneRefs,easyResultsDir, Tmpsbdg);
TmpexpScanIntens3=TmpexpScanIntens2;
TmpFexpScanSpots3=TmpFexpScanSpots2;
TmpFexpScanBMtp3=TmpFexpScanBMtp2;
TmpanlZoneRefs3=TmpanlZoneRefs2;
Tmpsbdg3=Tmpsbdg2;
% clear plate
CFscanIntens=zeros(384,1); % zeros(16,24);
plate=[];
plate=zeros(24,16,tptLength);
plate(:,:,:,1)=scanIntens(1:1:24,16:-1:1,:); % TmpexpScanIntens2(1:1:24,16:-1:1,:);%Ncode Dev3Vertical Similar to below
% NIcheck: Check for bad scans at time points (swapped plates etc.)
% Set up cell arrays for storing each plate in each Scan ..(scan,plate)
SWprint=0;
% Construct Legacy ...Intens.txt file
if SWprint==1
filename=fullfile(easyResultsDir,'PrintResults',(strcat('Plate',num2str(selScan),'_Intens.txt')));
fid=fopen(filename,'w');
end
if length(size(plate))==2 % only two dims if only one image
numOfImages=1;
else
numOfImages=size(plate,3);
end
CFscanIntens=zeros(384,numOfImages);
locIndx=0; pl=1;
for n=1:numCols % Ncode changed to 16 for Vert
for m=1:numRows % Ncode change to 24 for Vert
locIndx=locIndx+1;
for k=1:numOfImages
if SWprint==1
if k==1 && numOfImages==1, fprintf(fid,'%.2f\n',plate(m,n,k,pl));end
if k==1 && numOfImages~=1, fprintf(fid,'%.2f',plate(m,n,k,pl));end
if k>1 && k<numOfImages, fprintf(fid,'\t%.2f',plate(m,n,k,pl));end %
if k~=1 && k==numOfImages,fprintf(fid,'\t%.2f\n',plate(m,n,k,pl));end
end
CFscanIntens(locIndx,k)=plate(m,n,k,pl);
end
end
end
if SWprint==1
fclose(fid);
end
% printGrwAreas
% Area as the max number of pixels with intensities greater than the Background
% grArea(row,col,tPt,Plate) Note that images r and c are 90 degrees shifted
% and then mirror imaged. Thus data must be inverted and rotated to get
% for the rows a-p and col 1-24 (and the EMS expected 1-384) orientation
% clear grArea
grArea=ones(24,16,tptLength);
grArea(:,:,:,1)=areaOfIntensAboveBG(1:1:24,16:-1:1,:); %for Ncode dev3vert
% for p=1:lastPlateOnScan
if SWprint==1
if SWgrowthArea==1
filename=fullfile(printResultsDir,(strcat('Plate',num2str(selScan),'_Areas.txt')));
else
filename=fullfile(printResultsDir,(strcat('ALTgrowthA_Scan',num2str(selScan),'_Plate',num2str(1),'_Areas.txt')));
filename=fullfile(printResultsDir,(strcat('ALTgrowthA_Plate',num2str(selScan),'_Plate','_Areas.txt')));
end
fid=fopen(filename,'w');
end
locIndx=0;
Ag=zeros(1,384);
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);
end
locIndx=locIndx+1;
Ag(locIndx)=growthArea;
end
end
if SWprint==1
fclose(fid);
% fclose('all'); % TODO do we need this?
end
% AutoImCF curveFit kickoff setup
autoImCFlag=1;
if autoImCFlag==1, SWgrowthArea=1;end
times=tSeriesv;
scanAreas=Ag; % growthArea;
offsets=0;
suffix=strcat('Scan', num2str(selScan),'_Plate', num2str(1)); % char(QspLst(n));
AUCfinalTime=96;
arrayFormat=384;
% Version compatability fixes
%{
v11a='7.12.0.635 (R2011a)';
v14a='8.3.0.532 (R2014a)';
%v14b='8.4.0.150421 (R2014b)';
v18a='9.4.0.813654 (R2018a)';
v18b='9.5.0.944444 (R2018b)';
% Fourth order derivative of logistic equation
if isequal(v18a,version)||isequal(v18b,version)
syms t K r l;
fd4=diff(K / (1 + exp(-r* (t - l ))),t,4);
else
fd4=diff(sym('K / (1 + exp(-r* (t - l )))'),4);
end
sols=solve(fd4);
if isequal(v11a,version) || isequal(v14a,version)
else
tmpswap=sols(1);
sols(1)=sols(3);
sols(3)=tmpswap;
end
%}
if verLessThan('matlab','8.3') % original work 23_0227 updated 23_0525 (8.4 changed to 8.3)
fd4=diff(sym('K / (1 + exp(-r* (t - l )))'),4);
sols=solve(fd4);
else % accomodate new matlab changes after 2014a fix 2nd update 23_0227
syms t K r l;
fd4=diff(K / (1 + exp(-r* (t - l ))),t,4);
sols=solve(fd4);
tmpswap=sols(1);
sols(1)=sols(3);
sols(3)=tmpswap;
end
% CFscanIntens
% Call CurveFit routine
% NCfitImCF(times, CFscanIntens, offsets, suffix, AUCfinalTime, arrayFormat, scanAreas, printResultsDir, autoImCFlag, selScan,sols) %,scan)%, scPltList) outputDirectory;
% [scanTmp2]=NCfitImCFparforFailGbl(times, CFscanIntens, offsets, suffix, AUCfinalTime, arrayFormat, scanAreas, printResultsDir, autoImCFlag, selScan, sols, scanTmp); %,scan)%, scPltList) outputDirectory;
[par4scanselIntensStd,par4scanselTimesStd,par4scanTimesELr,par4scanIntensELr,par4scanCFparameters,par4scanCFdate,outC2,outCstd2]= ...
NCfitImCFparforFailGbl2(parMat,times, CFscanIntens, offsets, suffix, AUCfinalTime, arrayFormat, scanAreas, printResultsDir, autoImCFlag, selScan, sols); %,scan)%, scPltList) outputDirectory;
else %fill with default values when an invalid plate scan occurs
CFscanIntens=zeros(16,24);
Ag=zeros(1,384);
% Preallocation for parfor loop
times=tSeriesv;
st(1,1:size(times,2))=1111;
resMat(1,1:27)=0;
resMatStd=resMat;
outC2=zeros(384,27);
outCstd2=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);
%{
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);
%}
TmpexpScanIntens3=cell(1); %TmpexpScanIntens2;
TmpFexpScanSpots3=cell(1); %TmpFexpScanSpots2;
TmpFexpScanBMtp3=cell(1); %TmpFexpScanBMtp2;
TmpanlZoneRefs3=cell(1); %TmpanlZoneRefs2;
Tmpsbdg3=cell(1); %Tmpsbdg2;
end %if tptLenth>=3 line19 20_0928
tSeriesv; %debuggin parfor
p4L1{1}=tSeriesv;
p4L1{2}=t0Seriesv;
p4L1{3}=datestr(prtTmNumv,31);
p4L1{4}=CFscanIntens;
locIndx=0;
for n=1:numCols % Ncode changed to 16 for Vert
for m=1:numRows % Ncode change to 24 for Vert
locIndx=locIndx+1;
rc=[n,m];
p4rcTmp(locIndx)={rc};
p4pIndxTmp(locIndx)=locIndx;
end
end
p4L1{5}=p4rcTmp;
p4L1{6}=p4pIndxTmp;
p4L1{7}=Ag;
p4L1{8}=par4scanselIntensStd;
p4L1{9}=par4scanselTimesStd;
p4L1{10}=par4scanTimesELr;
p4L1{11}=par4scanIntensELr;
p4L1{12}=par4scanCFparameters;
p4L1{13}=par4scanCFdate;
p4L1{14}=outC2;
p4L1{15}=outCstd2;
p4L1{16}=selScan;
p4L1{17}=cirPixA;
p4L1{18}=datestr((now),31); % TODO this seems bad
p4L2=p4L1;
end

View File

@@ -0,0 +1,244 @@
global SWgrowthArea
global scLst
global ImParMat
global projectScansDir
global matFile
global fhconsole
global easyResultsDir
global printResultsDir
global pointMapsResultsDir
global fotosResultsDir
global matDir
global ImWidth
global ImHeigth
global numRows
global numCols
global scan
global scanMax
global tptLength
global easyDir
numRows=24; % for Single Vertical
numCols=16; % for Single Vertical
% CIRCLE related
doCircle=1; % use Circle area analysis 14_0807
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
end
% No idea why we're doing this so commenting out
% close
% EASYconsole
if exist(matFile, 'file')
bkUpMatFile=fullfile(matFile, '.bk');
copyfile(matFile,bkUpMatFile);
end
% Reloacated from 'PTmats' to prevent potential overwrite when PTmats is
% copied into new job when the PT template is about the same. We also
% now have a default template if one is not made. i.e., when the images
% from the new experiment are too sketchy to make a good pintool
% template. By moving it to 'Fotos' we avoid possible issues due to
% copying the Nbdg.mat file along with the default template '.mat' files.
% 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.
try
load(fullfile(fotosResultsDir,'Nbdg')); % modified to load from 'Fotos' 20_0819
catch
load(fullfile(pointMapsResultsDir,'Nbdg')); % left in to accomodate loads of work before 20_0819
end
% Load Fotos stored data
fotosToLoad={'Coordinates', 'BGatTpts', 'anlZones', 'NCFparms'};
for i=1:length(fotosToLoad)
try
load(fullfile(fotosResultsDir, fotosToLoad{i}));
catch
load(fullfile(easyDir,'parameters'));
end
end
% Get Print Times
PrintTimes=[];
scLst={};
% Parameter Entry
NImParamRadiusGui(projectScansDir); % Ncode 122111replaced removed ,numOfPrtTimes)
width=24;
widthEx=width-1; % width extention from reference point
dither=ImParMat(6);
radius=ImParMat(10);
NIcircle;
% Load Stuff
lastPlateOnLastScan=1; % Ncode
if size(scLst,1)==1
SWsingleSc=1;
else
SWsingleSc=0;
end
dvec=datevec(datestr(floor(now))); %method to get current offset year '01-Jan-"currentyr"'
dvec(2)=1;
dvec(3)=1;
% yrOffset=datenum('01-Jan-2012');%(dvec); %('01-Jan-2009'); %time num default is currentyear jan1
numScans=size(scLst,1);
if(isequal(SWsingleSc,1))
selScan=str2double(char(scLst(1)));
else
% startScan=1;
end
SWgrowthArea=ImParMat(9);
load(fullfile(pointMapsResultsDir,'NPTmapSearch'));
PTmapPos=detPos;
selScanNumLst=[];
Scanfiles=[];
pathname=[];
for ii=1:length(scLst)
if (SWsingleSc == 1)
% 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;
else
scd=imread(char(Scanfiles(1,1)));
tptLength=length(Scanfiles);
end
ImHeigth=size(scd,1);
ImWidth=size(scd,2);
sc=scd(1:ImHeigth,1:ImWidth);
end
numFiles=size(Scanfiles,2);
% Initialize tifFilesLst for parfor loop
dir(fullfile(projectScansDir, char(scLst(ii)), '*.bmp'));
numFiles=length(tifFileLst4MultiT);
tptLength=numFiles;
tifFileLstP4{ii}={tifFileLst4MultiT.name};
end
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
% 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);
Tmpsbdg00=cell(1);
TmpexpScanIntens4=cell(1,numScans);
TmpFexpScanSpots4=cell(1,numScans);
TmpFexpScanBMtp4=cell(1,numScans);
TmpanlZoneRefs4=cell(1,numScans);
Tmpsbdg4=cell(1,numScans);
TmpexpScanIntens5=cell(1,numScans);
TmpFexpScanSpots5=cell(1,numScans);
TmpFexpScanBMtp5=cell(1,numScans);
TmpanlZoneRefs5=cell(1,numScans);
Tmpsbdg5=cell(1,numScans);
p4L00=cell(18,1);
p4L0=p4L00;
p4L4=cell(18,numScans);
p4L5=p4L4;
Ag=ones(384);
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,easyResultsDir,projectScansDir, 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"
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));
scan(selScan).plate(1).intens=cell2mat(p4L4(4,scanCnt));
scan(selScan).plate(1).rc=p4L4(5,scanCnt);
scan(selScan).plate(1).pIndx=cell2mat(p4L4(6,scanCnt));
scan(selScan).plate(1).Ag=cell2mat(p4L4(7,scanCnt));
scan(selScan).plate(1).selIntens=p4L4(8,scanCnt);
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
CFparm(1:384)=p4L4{12,scanCnt}(1:384);
scan(selScan).plate(1).CFparameters=CFparm;
scan(selScan).plate(1).CFdate=p4L4(13,scanCnt);
scan(selScan).plate(1).CFout=cell2mat(p4L4(14,scanCnt));
scan(selScan).plate(1).CFoutStd=cell2mat(p4L4(15,scanCnt));
scan(selScan).Awindow=cell2mat(p4L4(17,scanCnt));
scan(selScan).Idate=cell2mat(p4L4(18,scanCnt));
expScanIntens(selScan)=TmpexpScanIntens5(scanCnt);
FexpScanSpots(selScan)=TmpFexpScanSpots5(scanCnt);
FexpScanBMtp(selScan)=TmpFexpScanBMtp5(scanCnt);
anlZoneRefs(selScan)=TmpanlZoneRefs5(scanCnt);
if ~isempty(Tmpsbdg5{scanCnt})
sbdg(selScan)=Tmpsbdg5(scanCnt);
else
sbdg{selScan}=uint8(zeros(24,16,4));
end
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(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';
filePrefix='FitResults_';
for scanCnt=1:numScans
selScan=p4L4{16,scanCnt}; % determine the actual scan in the scanCnt parfor distributed "id"
fileSuffix=sprintf('Scan%d_Plate%d', selScan, 1);
fileNamePlate=[filePrefix fileSuffix fileExt];
fileName=fullfile(printResultsDir, 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.
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
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),...
outCprint{14,scanCnt}(n,5),outCprint{14,scanCnt}(n,6),outCprint{14,scanCnt}(n,7),outCprint{14,scanCnt}(n,8),...
outCprint{14,scanCnt}(n,9),outCprint{14,scanCnt}(n,10),outCprint{14,scanCnt}(n,11),outCprint{14,scanCnt}(n,12),...
outCprint{14,scanCnt}(n,13),outCprint{14,scanCnt}(n,14),outCprint{14,scanCnt}(n,15),outCprint{14,scanCnt}(n,16));
end
fclose(fid);
end