par4Gbl_Main8c.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. global SWgrowthArea
  2. global scLst
  3. global ImParMat
  4. global projectScansDir
  5. global matFile
  6. global fhconsole
  7. global easyResultsDir
  8. global printResultsDir
  9. global pointMapsResultsDir
  10. global fotosResultsDir
  11. global matDir
  12. global ImWidth
  13. global ImHeigth
  14. global numRows
  15. global numCols
  16. global scan
  17. global scanMax
  18. global tptLength
  19. global easyDir
  20. numRows=24; % for Single Vertical
  21. numCols=16; % for Single Vertical
  22. % CIRCLE related
  23. doCircle=1; % use Circle area analysis 14_0807
  24. radius=14;
  25. ImParMat(10)=radius;
  26. ImParMat(11)=doCircle;
  27. % TODO what is this for?
  28. Fflg=1;
  29. % Don't think we need this
  30. % fclose('all'); % close all open files
  31. % Unset some vars just in case they are already set
  32. clear('scanIntens','Scanfiles','pathname','tifFileLstP4');
  33. try
  34. clf(fhconsole,'reset');
  35. catch
  36. end
  37. % No idea why we're doing this so commenting out
  38. % close
  39. % EASYconsole
  40. if exist(matFile, 'file')
  41. bkUpMatFile=fullfile(matFile, '.bk');
  42. copyfile(matFile,bkUpMatFile);
  43. end
  44. % Reloacated from 'PTmats' to prevent potential overwrite when PTmats is
  45. % copied into new job when the PT template is about the same. We also
  46. % now have a default template if one is not made. i.e., when the images
  47. % from the new experiment are too sketchy to make a good pintool
  48. % template. By moving it to 'Fotos' we avoid possible issues due to
  49. % copying the Nbdg.mat file along with the default template '.mat' files.
  50. % A copy of Ndbg.mat is placed also saved to the 'PTmats' directory
  51. % after each run to allow previous version of EASY to access data made
  52. % by EASY versions after 20_0819.
  53. try
  54. load(fullfile(fotosResultsDir,'Nbdg')); % modified to load from 'Fotos' 20_0819
  55. catch
  56. load(fullfile(pointMapsResultsDir,'Nbdg')); % left in to accomodate loads of work before 20_0819
  57. end
  58. % Load Fotos stored data
  59. fotosToLoad={'Coordinates', 'BGatTpts', 'anlZones', 'NCFparms'};
  60. for i=1:length(fotosToLoad)
  61. try
  62. load(fullfile(fotosResultsDir, fotosToLoad{i}));
  63. catch
  64. load(fullfile(easyDir,'parameters'));
  65. end
  66. end
  67. % Get Print Times
  68. PrintTimes=[];
  69. scLst={};
  70. % Parameter Entry
  71. NImParamRadiusGui(projectScansDir); % Ncode 122111replaced removed ,numOfPrtTimes)
  72. width=24;
  73. widthEx=width-1; % width extention from reference point
  74. dither=ImParMat(6);
  75. radius=ImParMat(10);
  76. NIcircle;
  77. % Load Stuff
  78. lastPlateOnLastScan=1; % Ncode
  79. if size(scLst,1)==1
  80. SWsingleSc=1;
  81. else
  82. SWsingleSc=0;
  83. end
  84. dvec=datevec(datestr(floor(now))); %method to get current offset year '01-Jan-"currentyr"'
  85. dvec(2)=1;
  86. dvec(3)=1;
  87. % yrOffset=datenum('01-Jan-2012');%(dvec); %('01-Jan-2009'); %time num default is currentyear jan1
  88. numScans=size(scLst,1);
  89. if(isequal(SWsingleSc,1))
  90. selScan=str2double(char(scLst(1)));
  91. else
  92. % startScan=1;
  93. end
  94. SWgrowthArea=ImParMat(9);
  95. load(fullfile(pointMapsResultsDir,'NPTmapSearch'));
  96. PTmapPos=detPos;
  97. selScanNumLst=[];
  98. Scanfiles=[];
  99. pathname=[];
  100. for ii=1:length(scLst)
  101. if (SWsingleSc == 1)
  102. % TODO proably need to make this more explicit with paths
  103. [Scanfiles, pathname]=uigetfile('*.bmp', 'Select files','MultiSelect','on'); % change '*hr*.bmp' 12/20/2011
  104. if ischar(Scanfiles)
  105. scd=imread(char(Scanfiles));
  106. tptLength=1;
  107. else
  108. scd=imread(char(Scanfiles(1,1)));
  109. tptLength=length(Scanfiles);
  110. end
  111. ImHeigth=size(scd,1);
  112. ImWidth=size(scd,2);
  113. sc=scd(1:ImHeigth,1:ImWidth);
  114. end
  115. numFiles=size(Scanfiles,2);
  116. % Initialize tifFilesLst for parfor loop
  117. dir(fullfile(projectScansDir, char(scLst(ii)), '*.bmp'));
  118. numFiles=length(tifFileLst4MultiT);
  119. tptLength=numFiles;
  120. tifFileLstP4{ii}={tifFileLst4MultiT.name};
  121. end
  122. for jj=1:numScans % startScan:numScans
  123. selScan=str2double(char(scLst(jj)));
  124. selScanNumLst(jj)=selScan;
  125. end
  126. selScanNumLst2=selScanNumLst; % function passthrough, passback to par4gbl_Main 20_0205
  127. % Preallocation
  128. scCount=[];
  129. TmpexpScanIntens00=cell(1); % cell(1,scanMax);
  130. TmpFexpScanSpots00=cell(1); % cell(1,scanMax);
  131. TmpFexpScanBMtp00=cell(1); % cell(1,scanMax);
  132. TmpanlZoneRefs00=cell(1); % cell(1,scanMax);
  133. Tmpsbdg00=cell(1);
  134. TmpexpScanIntens4=cell(1,numScans);
  135. TmpFexpScanSpots4=cell(1,numScans);
  136. TmpFexpScanBMtp4=cell(1,numScans);
  137. TmpanlZoneRefs4=cell(1,numScans);
  138. Tmpsbdg4=cell(1,numScans);
  139. TmpexpScanIntens5=cell(1,numScans);
  140. TmpFexpScanSpots5=cell(1,numScans);
  141. TmpFexpScanBMtp5=cell(1,numScans);
  142. TmpanlZoneRefs5=cell(1,numScans);
  143. Tmpsbdg5=cell(1,numScans);
  144. p4L00=cell(18,1);
  145. p4L0=p4L00;
  146. p4L4=cell(18,numScans);
  147. p4L5=p4L4;
  148. Ag=ones(384);
  149. CFscanIntens=zeros(16,24);
  150. [p4L4,TmpexpScanIntens5,TmpFexpScanSpots5,TmpFexpScanBMtp5,TmpanlZoneRefs5,Tmpsbdg5]= ...
  151. p4loop8c(parMat,tptLength,numScans,selScanNumLst,SWsingleSc,Fflg,PTmapPos,optCirMask,diaExt,doCircle,cirPixA,cirMask,width, ...
  152. TmpexpScanIntens00,TmpFexpScanSpots00,TmpFexpScanBMtp00,TmpanlZoneRefs00,scCount,tifFileLstP4,pathname,ImParMat, ...
  153. numRows,numCols,scLst,easyResultsDir,projectScansDir, p4L00,TmpexpScanIntens4,TmpFexpScanSpots4,TmpFexpScanBMtp4,TmpanlZoneRefs4, ...
  154. Tmpsbdg00,Tmpsbdg4);
  155. for scanCnt=1:numScans
  156. selScan=p4L4{16,scanCnt}; % determine the actual scan in the scanCnt parfor distributed "id"
  157. scan(selScan).plate(1).tSeries=cell2mat(p4L4(1,scanCnt));
  158. scan(selScan).plate(1).t0Series=cell2mat(p4L4(2,scanCnt));
  159. scan(selScan).plate(1).printTm=cell2mat(p4L4(3,scanCnt));
  160. scan(selScan).plate(1).intens=cell2mat(p4L4(4,scanCnt));
  161. scan(selScan).plate(1).rc=p4L4(5,scanCnt);
  162. scan(selScan).plate(1).pIndx=cell2mat(p4L4(6,scanCnt));
  163. scan(selScan).plate(1).Ag=cell2mat(p4L4(7,scanCnt));
  164. scan(selScan).plate(1).selIntens=p4L4(8,scanCnt);
  165. scan(selScan).plate(1).selTimes=p4L4(9,scanCnt);
  166. scan(selScan).plate(1).filterTimes=p4L4(10,scanCnt);
  167. scan(selScan).plate(1).normIntens=p4L4(11,scanCnt);
  168. % scan(selScan).plate(1).CFparameters=p4L4(12,scanCnt); %Need to convert to a matrix form like Old versions
  169. CFparm(1:384)=p4L4{12,scanCnt}(1:384);
  170. scan(selScan).plate(1).CFparameters=CFparm;
  171. scan(selScan).plate(1).CFdate=p4L4(13,scanCnt);
  172. scan(selScan).plate(1).CFout=cell2mat(p4L4(14,scanCnt));
  173. scan(selScan).plate(1).CFoutStd=cell2mat(p4L4(15,scanCnt));
  174. scan(selScan).Awindow=cell2mat(p4L4(17,scanCnt));
  175. scan(selScan).Idate=cell2mat(p4L4(18,scanCnt));
  176. expScanIntens(selScan)=TmpexpScanIntens5(scanCnt);
  177. FexpScanSpots(selScan)=TmpFexpScanSpots5(scanCnt);
  178. FexpScanBMtp(selScan)=TmpFexpScanBMtp5(scanCnt);
  179. anlZoneRefs(selScan)=TmpanlZoneRefs5(scanCnt);
  180. if ~isempty(Tmpsbdg5{scanCnt})
  181. sbdg(selScan)=Tmpsbdg5(scanCnt);
  182. else
  183. sbdg{selScan}=uint8(zeros(24,16,4));
  184. end
  185. end
  186. % Save data in .mat files
  187. save(matFile,'scan');
  188. % save((fullfile(easyResultsDir,'PTmats','Nbdg')), 'sbdg'); % legacy location can probably get rid of in time
  189. save((fullfile(fotosResultsDir,'Nbdg')), 'sbdg');
  190. save((fullfile(fotosResultsDir,'Coordinates')),'FexpScanSpots') % saves frames at each tPt
  191. save((fullfile(fotosResultsDir,'BGatTpts')),'FexpScanBMtp')
  192. save((fullfile(fotosResultsDir,'anlZones')),'anlZoneRefs') % saves anl Positions at each tPt
  193. % Print FitResults
  194. fileExt='.txt';
  195. filePrefix='FitResults_';
  196. for scanCnt=1:numScans
  197. selScan=p4L4{16,scanCnt}; % determine the actual scan in the scanCnt parfor distributed "id"
  198. fileSuffix=sprintf('Scan%d_Plate%d', selScan, 1);
  199. fileNamePlate=[filePrefix fileSuffix fileExt];
  200. fileName=fullfile(printResultsDir, fileNamePlate); % [outputDirectory fileNamePlate];
  201. % This,fprint for loop,is an very old legacy feature which slows processing. Could be
  202. % removed but allows easy observation of how a run is progressing and can be
  203. % used as a diagnostic tool.
  204. outCprint=p4L4;
  205. fid=fopen(fileName,'w');
  206. 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');
  207. for n=1:384 % startCount:numCultures
  208. fprintf(fid,'%d\t',n);
  209. 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',...
  210. outCprint{14,scanCnt}(n,1),outCprint{14,scanCnt}(n,2),outCprint{14,scanCnt}(n,3),outCprint{14,scanCnt}(n,4),...
  211. outCprint{14,scanCnt}(n,5),outCprint{14,scanCnt}(n,6),outCprint{14,scanCnt}(n,7),outCprint{14,scanCnt}(n,8),...
  212. outCprint{14,scanCnt}(n,9),outCprint{14,scanCnt}(n,10),outCprint{14,scanCnt}(n,11),outCprint{14,scanCnt}(n,12),...
  213. outCprint{14,scanCnt}(n,13),outCprint{14,scanCnt}(n,14),outCprint{14,scanCnt}(n,15),outCprint{14,scanCnt}(n,16));
  214. end
  215. fclose(fid);
  216. end