DgenResults.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. global projectScansDir
  2. global projectName
  3. global matFile
  4. global defImParMat
  5. global printResultsDir
  6. global fotosResultsDir
  7. global pointMapsFile
  8. global pointMapsResultsDir
  9. ln=1;
  10. % Version compatability fixes
  11. if verLessThan('matlab','8.3')
  12. fd4=diff(sym('K / (1 + exp(-r* (t - l )))'),4);
  13. sols=solve(fd4);
  14. else % accomodate new matlab changes after 2014a
  15. syms t K r l;
  16. fd4=diff(K / (1 + exp(-r* (t - l ))),t,4);
  17. sols=solve(fd4);
  18. tmpswap=sols(1);
  19. sols(1)=sols(3);
  20. sols(3)=tmpswap;
  21. end
  22. % MPnum=ImParMat(1);
  23. % opt=questdlg('Print Results Only (RES), DB Only (DB), or Both','Results Printout Options','Res','DB','Both','Both');
  24. opt='Res';
  25. if ~exist('defImParMat','var') || isempty(defImParMat) % TODO needs explanation
  26. load(pointMapsFile);
  27. end
  28. destPerMP=ImParMat(2); % TODO this is weird, needs explanation
  29. load(matFile);
  30. load(mpdmFile)
  31. numOfDrgs=length(DM.drug);
  32. numOfMeds=length(DM.media);
  33. destPerMP=numOfDrgs;
  34. % TODO this should be rewritten or is unnecessary, what is this for
  35. % Determine the longest set of intensity(tPts) for the Experiment Data Set
  36. maxNumIntens=0;
  37. for n=1:size(scan,2)
  38. for m=1:size(scan(n).plate,2)
  39. maxNumIntens=max(maxNumIntens,size(scan(n).plate(m).intens,2));
  40. end
  41. end
  42. % if length(projectScansDir) == max(strfind(projectScansDir,'\'))
  43. % localprojectScansDir=projectScansDir(1:end-1);
  44. % else
  45. % localprojectScansDir=projectScansDir;
  46. % end
  47. % DBupload=fullfile(drive,'EZdbFiles','DBupLOADfiles');
  48. resultsFilename=fullfile(printResultsDir, 'results_elr.txt');
  49. DBfilename=fullfile(printResultsDir, 'DbaseELr.txt');
  50. if isequal(opt,'Res')||isequal(opt,'Both'),fid=fopen(resultsFilename,'w');end
  51. if isequal(opt,'DB')||isequal(opt,'Both'),fid2=fopen(DBfilename,'w');end
  52. if isequal(opt,'Res')||isequal(opt,'Both')
  53. fprintf(fid,'%d\t',ln); % Results header
  54. fprintf(fid,'%s\t\n',projectScansDir);
  55. ln=ln+1;
  56. fprintf(fid,'%d\t',ln);
  57. end
  58. mpCnt=0;
  59. totPlCnt=0;
  60. drgCnt=0;
  61. medCnt=0;
  62. try
  63. load(fullfile(fotosResultsDir,'Nbdg')) % Convolute scan array data into plates
  64. catch
  65. load(fullfile(pointMapsResultsDir,'Nbdg')) % Convolute scan array data into plates
  66. end
  67. for s=1:size(scan,2)
  68. % Convolute scan array data into plates DconB for DBcombo
  69. clear Diag
  70. try
  71. Diag(:,:,:,1)=sbdg{s}(1:1:24,16:-1:1,:);
  72. catch
  73. sbdg{s};
  74. end
  75. for p=1:size((scan(s).plate),2)
  76. totPlCnt=totPlCnt+1;
  77. if destPerMP>1 && rem(totPlCnt,destPerMP)==1
  78. mpCnt=mpCnt+1;
  79. end
  80. if destPerMP==1
  81. mpCnt=mpCnt+1;
  82. end
  83. pertCnt=rem(totPlCnt,destPerMP);
  84. if pertCnt==0
  85. pertCnt=destPerMP;
  86. end
  87. pert=strcat('Perturb_',num2str(pertCnt));
  88. s % TODO seems wrong
  89. p % TODO seems wrong
  90. clear outCmat
  91. outCmat=scan(s).plate(p).CFout;
  92. % Print Time Point HEADER for each plate for newly added intensity data
  93. if isequal(opt,'Res')||isequal(opt,'Both')
  94. fprintf(fid, '\n');
  95. ln=ln+1;
  96. fprintf(fid,'%d\t',ln);
  97. fprintf(fid,'Scan\tPlate\tRow\tCol\t');
  98. try
  99. asd=cell2mat(scan(s).plate(1).CFparameters(1));
  100. aucEndPt=strcat('AUC',num2str(asd(9)));
  101. catch
  102. asd=cell2mat(scan(s).plate(1).CFparameters{1,1}(1,384));
  103. aucEndPt=strcat('AUC',num2str(asd(9)));
  104. end
  105. fprintf(fid, 'Num.\tDiagnostics\tDrug\tConc\tMedia\tModifier1\tConc1\tModifier2\tConc2\tORF\tGene');
  106. fprintf(fid, '\t %s',aucEndPt);
  107. 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');
  108. if size(outCmat,2)==27
  109. fprintf(fid, '\ttc11Cut\ttc12Cut\ttc21Cut\ttc22Cut'); % '\tEarly1\tEarly2\tLate1\tLate2'); 17_0629 MinBaseIntens update for MedianBase label
  110. end
  111. fprintf(fid, '\tTotFitPts\tPostThreshFitPts\t1stBackgrd\tLstBackgrd\t1stMeanTotBackgrd\tLstMeanTotBackgrd');
  112. end
  113. clear outTseries
  114. outTseries=[];
  115. outTseries=scan(s).plate(p).tSeries;
  116. TseriesSize=size(outTseries,1);
  117. clear outIntens
  118. outIntens=[];
  119. RawIntens=[];
  120. RawIntens=scan(s).plate(p).intens;
  121. RawIntensSize=size(RawIntens,2)
  122. clear Ag; %Ag is Growth Area
  123. Ag=scan(s).plate(p).Ag;
  124. AgSize=size(Ag);
  125. dataLength=min(TseriesSize,RawIntensSize);
  126. if isequal(opt,'Res')||isequal(opt,'Both')
  127. for j=1:dataLength
  128. fprintf(fid, '\t%.5f', outTseries(j));
  129. end
  130. end
  131. numBlkCol=(maxNumIntens - dataLength); % size(outTseries,1));
  132. if isequal(opt,'Res')||isequal(opt,'Both')
  133. for nn=1:numBlkCol % extend to col beyond longest rawDataSet
  134. fprintf(fid, '\t');
  135. end
  136. fprintf(fid,'\tOrfRep');
  137. fprintf(fid,'\tSpecifics');
  138. fprintf(fid,'\tStrainBkGrd');
  139. fprintf(fid, '\n');
  140. ln=ln+1;
  141. fprintf(fid,'%d\t',ln);
  142. end
  143. % Data
  144. n=0;
  145. for r=1:16
  146. for c=1:24
  147. n=n+1;
  148. clear selcode;
  149. Kval=outCmat(n,3);
  150. rSq=outCmat(n,6);
  151. lval=outCmat(n,5);
  152. if Kval>160, selcode='K_Hi'; else selcode=' ';end
  153. if Kval<40, selcode=strcat(selcode,' K_Lo');end
  154. if rSq<.97 && rSq>0, selcode=strcat(selcode,' rSqLo');end
  155. if lval>(0.85*(max(outTseries))), selcode=strcat(selcode,' late');end
  156. if isnan(outCmat(n,7))||isnan(outCmat(n,8))||isnan(outCmat(n,9))...
  157. || isnan(outCmat(n,10))||isnan(outCmat(n,11))...
  158. || isnan(outCmat(n,12)), selcode=strcat(selcode,' NaN');
  159. end
  160. % RiseTime Calculation
  161. K=(outCmat(n,3));
  162. R=(outCmat(n,4));
  163. L=(outCmat(n,5));
  164. if R>0 && L>0 && K>0
  165. rr=R; ll=L;
  166. tc1=eval(sols(2));
  167. tc2=eval(sols(3));
  168. LL=eval(sols(1));
  169. riseTm=LL-tc1;
  170. else
  171. riseTm=0;
  172. end
  173. if Ag(n)< .30*(scan(s).Awindow),selcode=strcat(selcode,' smArea'); end
  174. if outCmat(n,3)==0,selcode=strcat('0 ',selcode);end
  175. orf=cell2mat(MP(mpCnt).orf{1}(n));
  176. gene=cell2mat(MP(mpCnt).genename{1}(n));
  177. orfRep=cell2mat(MP(mpCnt).orfRep{1}(n));
  178. specifics=cell2mat(MP(mpCnt).specifics{1}(n));
  179. strain=cell2mat(MP(mpCnt).strain{1}(n));
  180. drug=char(DM.drug{pertCnt});
  181. conc=char(DM.conc{pertCnt});
  182. media=char(DM.media{pertCnt});
  183. try
  184. mod1=char(DM.mod1{pertCnt});
  185. conc1=char(DM.conc1{pertCnt});
  186. catch
  187. mod1=' ';
  188. conc1=' ';
  189. end
  190. try
  191. mod2=char(DM.mod2{pertCnt});
  192. conc2=char(DM.conc2{pertCnt});
  193. catch
  194. mod2=' ';
  195. conc2=' ';
  196. end
  197. if ~isempty(outCmat)
  198. if isequal(opt,'Res')||isequal(opt,'Both')
  199. 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);
  200. 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',...
  201. outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
  202. outCmat(n,5),outCmat(n,6),outCmat(n,7),outCmat(n,8),...
  203. outCmat(n,9),outCmat(n,10),outCmat(n,11),outCmat(n,12),...
  204. outCmat(n,13),outCmat(n,14),outCmat(n,15),outCmat(n,16));
  205. fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f',...
  206. outCmat(n,17),outCmat(n,18),outCmat(n,19),...
  207. outCmat(n,20),outCmat(n,21));
  208. % Added for data cut times used in 'r'optomized method 06/14/2018
  209. if (size(outCmat,2) == 27)
  210. fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f',...
  211. outCmat(n,24),outCmat(n,25),outCmat(n,26),outCmat(n,27));
  212. end
  213. fprintf(fid, '\t%d\t%d\t%d\t%d\t%d\t%d',...
  214. 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));
  215. end
  216. % DBfile
  217. if isequal(opt,'DB')||isequal(opt,'Both')
  218. dbRsq=0;dbKup=0; dbKlo=0; dbrup=0; dbrlo=0; dbLlo=0; dbLup=0;
  219. if isnumeric(outCmat(n,6)), dbRsq=outCmat(n,6);end
  220. if isnumeric(outCmat(n,7)), dbKup=outCmat(n,7);end
  221. if isnumeric(outCmat(n,8)), dbKlo=outCmat(n,8);end
  222. if isnumeric(outCmat(n,9)), dbrup=outCmat(n,9);end
  223. if isnumeric(outCmat(n,10)), dbrlo=outCmat(n,10);end
  224. if isnumeric(outCmat(n,11)), dbLlo=outCmat(n,11);end
  225. if isnumeric(outCmat(n,12)), dbLup=outCmat(n,12);end
  226. end
  227. if isequal(opt,'DB')||isequal(opt,'Both')
  228. 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);
  229. 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',...
  230. outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
  231. outCmat(n,5),dbRsq,dbKup,dbKlo,dbrup,dbrlo,dbLlo,dbLup); %\t%.5f\t%.5f\t%.5f\t%.5f
  232. end
  233. % Add Intensities series to end of curve fit data
  234. outIntens=[];
  235. outIntens=zeros(384,dataLength);
  236. intensBlob='';
  237. tmBlob='';
  238. for j=1:dataLength %size(RawIntens,2) %size(outTseries,1)
  239. if Ag(n)==0,Ag(n)=scan(s).Awindow;end
  240. outIntens(n,j)=RawIntens(n,j)/Ag(n);
  241. if isequal(opt,'Res')||isequal(opt,'Both')
  242. fprintf(fid, '\t%.5f', outIntens(n,j)); % Results print Intens
  243. end
  244. if isequal(opt,'DB')||isequal(opt,'Both')
  245. if j<dataLength
  246. intensBlob=strcat(intensBlob,num2str(outIntens(n,j)),';');
  247. else
  248. intensBlob=strcat(intensBlob,num2str(outIntens(n,j)));
  249. end
  250. if outTseries(j)<.0001,outTseries(j)=0;end
  251. if j<dataLength
  252. tmBlob=strcat(tmBlob,num2str(outTseries(j)),';');
  253. else
  254. tmBlob=strcat(tmBlob,num2str(outTseries(j)));
  255. end
  256. end
  257. end
  258. % Results
  259. if isequal(opt,'Res')||isequal(opt,'Both')
  260. for nn=1:numBlkCol %extend to col beyond longest rawDataSet
  261. fprintf(fid, '\t');
  262. end
  263. % Masterplate sheet
  264. if ~isnan(orfRep)
  265. fprintf(fid, '\t%s', orfRep); %print OrfRep
  266. else
  267. fprintf(fid, '\t%s', ' ');
  268. end
  269. if ~isnan(specifics)
  270. fprintf(fid, '\t%s', specifics);
  271. else
  272. fprintf(fid, '\t%s', ' ');
  273. end
  274. if ~isnan(strain)
  275. fprintf(fid, '\t%s', strain);
  276. else
  277. fprintf(fid, '\t%s', ' ');
  278. end
  279. fprintf(fid, '\n');
  280. ln=ln+1;
  281. fprintf(fid,'%d\t',ln);
  282. end
  283. % DB Raw Intensities and Timepoints
  284. if isequal(opt,'DB')||isequal(opt,'Both')
  285. fprintf(fid2, '\t%s\t%s',intensBlob,tmBlob );
  286. % Masterplate sheet
  287. if ~isnan(orfRep)
  288. fprintf(fid2, '\t%s',orfRep );
  289. else
  290. fprintf(fid2, '\t%s', ' ');
  291. end
  292. if ~isnan(specifics)
  293. fprintf(fid2, '\t%s',specifics );
  294. else
  295. fprintf(fid2, '\t%s', ' ');
  296. end
  297. if ~isnan(strain)
  298. fprintf(fid2, '\t%s',strain );
  299. else
  300. fprintf(fid2, '\t%s', ' ');
  301. end
  302. fprintf(fid2, '\n');
  303. end
  304. end
  305. end
  306. end
  307. end
  308. end
  309. if isequal(opt,'Res')||isequal(opt,'Both')
  310. fclose(fid);
  311. end
  312. % if isequal(opt,'DB')||isequal(opt,'Both')
  313. % fclose(fid2);
  314. % try
  315. % copyfile(DBfilename,DBupload)
  316. % catch ME
  317. % fprintf('DB upload failed with error: %s\n', getReport(ME, 'basic'));
  318. % rep=sprintf('Failed copyfile to %s - %s', DBupload, rep);
  319. % errordlg(rep);
  320. % end
  321. % end
  322. % Print results using the standard method
  323. try
  324. scan(1).plate(1).CFoutStd(1,1) %Test for 2018 r_refined version
  325. ln=1;
  326. resultsFilename=fullfile(printResultsDir, 'results_std.txt');
  327. DBfilename=fullfile(printResultsDir, 'DbaseStd.txt');
  328. if isequal(opt,'Res')||isequal(opt,'Both'),fid=fopen(resultsFilename,'w');end
  329. if isequal(opt,'DB')||isequal(opt,'Both'),fid2=fopen(DBfilename,'w');end %121012 Combo
  330. if isequal(opt,'Res')||isequal(opt,'Both') %print Results
  331. fprintf(fid,'%d\t',ln); %Results header
  332. fprintf(fid,'%s\t\n',projectScansDir);
  333. ln=ln+1;
  334. fprintf(fid,'%d\t',ln);
  335. end
  336. mpCnt=0;
  337. totPlCnt=0;
  338. drgCnt=0;
  339. medCnt=0;
  340. for s=1:size(scan,2)
  341. %Convolute scan array data into plates DconB for DBcombo
  342. clear Diag
  343. try
  344. Diag(:,:,:,1)= sbdg{s}(1:1:24,16:-1:1,:);
  345. catch
  346. sbdg{s};
  347. end
  348. for p=1:size((scan(s).plate),2)
  349. totPlCnt=totPlCnt+1;
  350. if destPerMP>1 &&rem(totPlCnt,destPerMP)==1, mpCnt=mpCnt+1; end
  351. if destPerMP==1,mpCnt=mpCnt+1; end
  352. pertCnt=rem(totPlCnt,destPerMP);
  353. if pertCnt==0, pertCnt= destPerMP;end
  354. pert=strcat('Perturb_',num2str(pertCnt));
  355. s % BCR seems wrong
  356. %Print Time Point HEADER for each plate for newly added intensity data
  357. if isequal(opt,'Res')||isequal(opt,'Both')
  358. fprintf(fid, '\n');
  359. ln=ln+1;
  360. fprintf(fid,'%d\t',ln);
  361. fprintf(fid,'Scan\tPlate\tRow\tCol\t');
  362. try
  363. asd=cell2mat(scan(s).plate(1).CFparameters(1));
  364. aucEndPt=strcat('AUC',num2str(asd(9)));
  365. catch
  366. asd=cell2mat(scan(s).plate(1).CFparameters{1,1}(1,384));
  367. aucEndPt=strcat('AUC',num2str(asd(9)));
  368. end
  369. fprintf(fid, 'Num.\tDiagnostics\tDrug\tConc\tMedia\tModifier1\tConc1\tModifier2\tConc2\tORF\tGene');
  370. fprintf(fid, '\t %s',aucEndPt);
  371. 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
  372. end
  373. clear outTseries
  374. outTseries=[];
  375. outTseries=scan(s).plate(p).tSeries;
  376. TseriesSize= size(outTseries,1);
  377. clear outCmat
  378. outCmat=scan(s).plate(p).CFoutStd;
  379. clear outIntens
  380. outIntens=[];
  381. RawIntens=[];
  382. RawIntens=scan(s).plate(p).intens;
  383. RawIntensSize=size(RawIntens,2);
  384. clear Ag; %Ag is Growth Area
  385. Ag=scan(s).plate(p).Ag;
  386. AgSize= size(Ag);
  387. dataLength= min(TseriesSize,RawIntensSize);
  388. if isequal(opt,'Res')||isequal(opt,'Both')
  389. for j=1:dataLength
  390. fprintf(fid, '\t%.5f', outTseries(j));
  391. end
  392. end
  393. numBlkCol=(maxNumIntens - dataLength); %size(outTseries,1));
  394. if isequal(opt,'Res')||isequal(opt,'Both')
  395. for nn=1:numBlkCol %extend to col beyond longest rawDataSet
  396. fprintf(fid, '\t');
  397. end
  398. fprintf(fid,'\tOrfRep');
  399. fprintf(fid,'\tSpecifics');
  400. fprintf(fid,'\tStrainBkGrd');
  401. fprintf(fid, '\n');
  402. ln=ln+1;
  403. fprintf(fid,'%d\t',ln);
  404. end
  405. % Data
  406. n=0;
  407. for r=1:16
  408. for c=1:24
  409. n=n+1;
  410. clear selcode;
  411. Kval=outCmat(n,3);
  412. rSq=outCmat(n,6);
  413. lval=outCmat(n,5);
  414. if Kval>160, selcode='K_Hi'; else selcode=' ';end
  415. if Kval<40, selcode=strcat(selcode,' K_Lo');end % TODO sprintf if you want a space
  416. if rSq<.97 && rSq>0, selcode=strcat(selcode,' rSqLo');end
  417. if lval>(0.85*(max(outTseries))), selcode=strcat(selcode,' late');end
  418. if isnan(outCmat(n,7))||isnan(outCmat(n,8))||isnan(outCmat(n,9))...
  419. ||isnan(outCmat(n,10))||isnan(outCmat(n,11))...
  420. ||isnan(outCmat(n,12)), selcode=strcat(selcode,' NaN');
  421. end
  422. % RiseTime Calculation
  423. K=(outCmat(n,3));
  424. R=(outCmat(n,4));
  425. L=(outCmat(n,5));
  426. if R>0 && L>0 && K>0
  427. rr=R; ll=L;
  428. tc1=eval(sols(2));
  429. tc2=eval(sols(3));
  430. LL=eval(sols(1));
  431. riseTm= LL-tc1;
  432. else
  433. riseTm=0;
  434. end
  435. if Ag(n)< .30*(scan(s).Awindow),selcode=strcat(selcode,' smArea'); end % same, need sprintf for space
  436. if outCmat(n,3)==0,selcode=strcat('0 ',selcode); end
  437. orf=cell2mat(MP(mpCnt).orf{1}(n));
  438. gene=cell2mat(MP(mpCnt).genename{1}(n));
  439. orfRep=cell2mat(MP(mpCnt).orfRep{1}(n));
  440. specifics=cell2mat(MP(mpCnt).specifics{1}(n));
  441. strain=cell2mat(MP(mpCnt).strain{1}(n));
  442. drug=char(DM.drug{pertCnt});
  443. conc=char(DM.conc{pertCnt});
  444. media=char(DM.media{pertCnt});
  445. try
  446. mod1=char(DM.mod1{pertCnt});
  447. conc1=char(DM.conc1{pertCnt});
  448. catch
  449. mod1=' ';
  450. conc1=' ';
  451. end
  452. try
  453. mod2=char(DM.mod2{pertCnt});
  454. conc2=char(DM.conc2{pertCnt});
  455. catch
  456. mod2=' ';
  457. conc2=' ';
  458. end
  459. if ~isempty(outCmat)
  460. if isequal(opt,'Res')||isequal(opt,'Both')
  461. 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);
  462. 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',...
  463. outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
  464. outCmat(n,5),outCmat(n,6),outCmat(n,7),outCmat(n,8),...
  465. outCmat(n,9),outCmat(n,10),outCmat(n,11),outCmat(n,12),...
  466. outCmat(n,13),outCmat(n,14),outCmat(n,15),outCmat(n,16));
  467. fprintf(fid, '\t%.5f\t%.5f\t%.5f\t%.5f\t%.5f\t%d\t%d',...
  468. outCmat(n,17),outCmat(n,18),outCmat(n,19),...
  469. outCmat(n,20),outCmat(n,21),outCmat(n,22),outCmat(n,23));
  470. fprintf(fid, '\t%d\t%d\t%d\t%d',...
  471. 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));
  472. end
  473. % DBFile
  474. % RiseTime calculation
  475. if isequal(opt,'DB')||isequal(opt,'Both')
  476. dbRsq= 0;dbKup= 0; dbKlo= 0; dbrup= 0; dbrlo= 0; dbLlo= 0; dbLup= 0;
  477. if isnumeric(outCmat(n,6)), dbRsq= outCmat(n,6);end
  478. if isnumeric(outCmat(n,7)), dbKup= outCmat(n,7);end
  479. if isnumeric(outCmat(n,8)), dbKlo= outCmat(n,8);end
  480. if isnumeric(outCmat(n,9)), dbrup= outCmat(n,9);end
  481. if isnumeric(outCmat(n,10)), dbrlo= outCmat(n,10);end
  482. if isnumeric(outCmat(n,11)), dbLlo= outCmat(n,11);end
  483. if isnumeric(outCmat(n,12)), dbLup= outCmat(n,12);end
  484. end
  485. if isequal(opt,'DB')||isequal(opt,'Both')
  486. 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);
  487. 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',...
  488. outCmat(n,1),riseTm,outCmat(n,3),outCmat(n,4),...
  489. outCmat(n,5),dbRsq,dbKup,dbKlo,...
  490. dbrup,dbrlo,dbLlo,dbLup);
  491. end
  492. % DB Analysis
  493. % Add Intensities series to end of curve fit data
  494. outIntens=[];
  495. outIntens=zeros(384,dataLength);
  496. intensBlob='';
  497. tmBlob='';
  498. for j=1:dataLength %size(RawIntens,2) %size(outTseries,1)
  499. if Ag(n)==0,Ag(n)=scan(s).Awindow;end
  500. outIntens(n,j)= RawIntens(n,j)/Ag(n);
  501. if isequal(opt,'Res')||isequal(opt,'Both')
  502. fprintf(fid, '\t%.5f', outIntens(n,j)); % Results print Intens
  503. end
  504. if isequal(opt,'DB')||isequal(opt,'Both')
  505. if j<dataLength
  506. intensBlob=strcat(intensBlob,num2str(outIntens(n,j)),';');
  507. else
  508. intensBlob=strcat(intensBlob,num2str(outIntens(n,j)));
  509. end
  510. if outTseries(j)<.0001,outTseries(j)=0;end
  511. if j<dataLength
  512. tmBlob=strcat(tmBlob,num2str(outTseries(j)),';');
  513. else
  514. tmBlob=strcat(tmBlob,num2str(outTseries(j)));
  515. end
  516. end
  517. end
  518. % Results fprint
  519. if isequal(opt,'Res')||isequal(opt,'Both')
  520. for nn=1:numBlkCol %extend to col beyond longest rawDataSet
  521. fprintf(fid, '\t');
  522. end
  523. % Masterplate sheet
  524. if ~isnan(orfRep)
  525. fprintf(fid, '\t%s', orfRep); %print OrfRep
  526. else
  527. fprintf(fid, '\t%s', ' ');
  528. end
  529. if ~isnan(specifics)
  530. fprintf(fid, '\t%s', specifics);
  531. else
  532. fprintf(fid, '\t%s', ' ');
  533. end
  534. if ~isnan(strain)
  535. fprintf(fid, '\t%s', strain);
  536. else
  537. fprintf(fid, '\t%s', ' ');
  538. end
  539. fprintf(fid, '\n');
  540. ln=ln+1;
  541. fprintf(fid,'%d\t',ln);
  542. end
  543. % Raw Intensities and Timepoints
  544. if isequal(opt,'DB')||isequal(opt,'Both')
  545. fprintf(fid2, '\t%s\t%s',intensBlob,tmBlob );
  546. % Masterplate sheet
  547. if ~isnan(orfRep)
  548. fprintf(fid2, '\t%s',orfRep );
  549. else
  550. fprintf(fid2, '\t%s', ' ');
  551. end
  552. if ~isnan(specifics)
  553. fprintf(fid2, '\t%s',specifics );
  554. else
  555. fprintf(fid2, '\t%s', ' ');
  556. end
  557. if ~isnan(strain)
  558. fprintf(fid2, '\t%s',strain );
  559. else
  560. fprintf(fid2, '\t%s', ' ');
  561. end
  562. fprintf(fid2, '\n');
  563. end %DB print
  564. end %if ~isempty(outCmat)
  565. end %c
  566. end %r
  567. end %p
  568. end %s
  569. if isequal(opt,'Res')||isequal(opt,'Both')
  570. fclose(fid);
  571. end
  572. % if isequal(opt,'DB')||isequal(opt,'Both')
  573. % fclose(fid2);
  574. % try
  575. % copyfile(DBfilename,DBupload)
  576. % catch ME
  577. % fsprintf('DB upload failed with error: %s\n', getReport(ME, 'basic'));
  578. % rep=sprintf('Failed copyfile to %s - %s\n', DBupload, rep);
  579. % errordlg(rep)
  580. % end
  581. % end
  582. msgbox([sprintf('Printing script complete. Check results sheets in %s for results.', printResultsDir)])
  583. catch ME
  584. fprintf('Printing script failed with error: %s\n', getReport(ME, 'basic'));
  585. end