EZvInitLoad.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. % EZvInitLoad
  2. global Exp
  3. global Expaa
  4. global Expbb
  5. global userPars
  6. global scansDir
  7. global matFile
  8. global zonePB
  9. global mpdmFile
  10. global ghandles
  11. % Initialize some variables from matlab
  12. ezPath=which(mfilename);
  13. [ezDir,ezFileName]=fileparts(ezPath);
  14. ezDir=fullfile(easyDir);
  15. [parentDir, ~]=fileparts(ezDir);
  16. parentDir=fullfile(parentDir);
  17. debug=1;
  18. if debug
  19. disp('Running in debug mode');
  20. disp('Initialized variables:');
  21. whos;
  22. end
  23. fprintf('This script name: %s\n', ezFileName);
  24. % Set scansDir (project scans directory) intelligently
  25. if exist('PROJECT_SCANS_DIR', 'var') && ~isempty(getenv('PROJECT_SCANS_DIR'))
  26. scansDir=fullfile(getenv('PROJECT_SCANS_DIR'));
  27. if exist(scansDir, 'dir')
  28. fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', scansDir);
  29. disp('This usually indicates that we are in module mode');
  30. if ~exist('PROJECT', 'var') || isempty(getenv('PROJECT'))
  31. dirInfo=fileparts(scansDir);
  32. project=dirInfo.name;
  33. end
  34. else
  35. disp('WARNING: PROJECT_SCANS_DIR does not exist');
  36. end
  37. elseif exist('PROJECT', 'var') && ~isempty(getenv('PROJECT')) % for standalone mode
  38. % scansDir=fullfile(parentDir, '..', '..', 'scans', getenv('PROJECT') 'out', 'easy', getenv('PROJECT'));
  39. scansDir=fullfile(parentDir, '..', '..', 'scans', getenv('PROJECT'));
  40. project=getenv('PROJECT');
  41. fprintf('Using project path: %s from environment variable PROJECT\n', scansDir);
  42. disp('This usually indicates that we are in standalone mode');
  43. else
  44. % TODO Lots of this is hardcoded logic, this TODO is just a reminder to change this block
  45. % when changing EASY/EZdir and other variables in the parent script
  46. fprintf('WARNING: Running in standalone mode without PROJECT or PROJECT_SCANS_DIR environment variables (not recommended)\n');
  47. fprintf('Beginning parent scans directory search\n');
  48. dirsToScan={
  49. fullfile(parentDir, '..', '..', 'scans')
  50. fullfile(parentDir, '..', '..', 'ExpJobs')
  51. fullfile('mnt','data','scans')
  52. fullfile('mnt','data', 'ExpJobs')
  53. fullfile(parentDir, '..', '..', 'templates', 'scans-demo')
  54. };
  55. for i=1:length(dirsToScan)
  56. d=dirsToScan(i);
  57. d=char(d);
  58. if exist(d, 'dir')
  59. subDirs=dir(d);
  60. pattern='^\d{6}_.*_.*';
  61. matchedDirs={dirs(regexp(subDirs.name, pattern)).name};
  62. if ~isempty(matchedDirs)
  63. fprintf('Found a non-empty scans directory in our list: %s\n', char(d));
  64. fprintf('Setting scansDir to %s\n', char(d));
  65. scansDir=fullfile(d);
  66. end
  67. fprintf('Scanning inside %s for a project directory\n', char(d));
  68. sortedMatchedDirs=sortrows(matchedDirs);
  69. project=sortedMatchedDirs{1}; % select the latest dir (by date prefix)
  70. fprintf('Selected latest project directory %s\n', char(project));
  71. end
  72. end
  73. end
  74. % User sanity check and warning
  75. if exist('PROJECT_USER', 'var') && ~isempty(getenv('PROJECT_USER'))
  76. if ~equal(getenv('PROJECT_USER'), userName)
  77. disp("WARNING: PROJECT_USER does not match the current namespace");
  78. end
  79. end
  80. % Allow module to override hardcoded default EZview directory
  81. if exist('EZVIEW_DIR','var') && ~isempty(getenv('EZVIEW_DIR'))
  82. EZVIEW_DIR=fullfile(getenv('EZVIEW_DIR'));
  83. if ~strcmp(ezDir, EZVIEW_DIR) % sanity check
  84. disp("WARNING: EZVIEW_DIR does not match this script's hardcoded EZview location");
  85. disp("This is probably OK but if strange beahvior arises, we'll need to fix it in code");
  86. ezDir=EZVIEW_DIR;
  87. end
  88. fprintf('Using EZview script directory: %s from environment variable EZVIEW_DIR\n', ezDir);
  89. else
  90. fprintf('Using EZview script directory: %s from hardcoded default\n', ezDir);
  91. end
  92. % Allow module to override hardcoded default EASY directory
  93. if exist('EASY_DIR','var') && ~isempty(getenv('EASY_DIR'))
  94. EASY_DIR=fullfile(getenv('EASY_DIR'));
  95. if ~strcmp(easyDir, EASY_DIR) % sanity check
  96. disp("WARNING: EASY_DIR does not match this script's hardcoded EASY location");
  97. disp("This is probably OK but if strange beahvior arises, we'll need to fix it in code");
  98. easyDir=EASY_DIR;
  99. end
  100. fprintf('Using EASY script directory: %s from environment variable EASY_DIR\n', easyDir);
  101. else
  102. fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
  103. end
  104. userPars.BPdefault={'on','on','0.3','8','45','1000'};
  105. userPars.boxplotFlg=1;
  106. userPars.BPoutliers='On';
  107. userPars.BPnotch='On';
  108. userPars.BPlblShft=0.3;
  109. userPars.BPfontSz=8;
  110. userPars.BProt=45;
  111. userPars.Trenddefault={'1000'};
  112. userPars.kfiltLim=str2double(userPars.BPdefault(6));
  113. try
  114. % Generate the Exp arrays
  115. numExps=3;
  116. for i=1:numExps
  117. Exp(i).cTraceN=0;
  118. Exp(i).cTraceIndx(1)=1;
  119. end
  120. Exp(1).CompositPlot=0;Exp(2).CompositPlot=0;Exp(3).CompositPlot=0;
  121. for i=1:numExps
  122. Exp(i).DexpType='single';
  123. Exp(i).DexpN=1;
  124. Exp(i).DexpLength=1;
  125. eval(['set(handles.DN' num2str(i) ', ''value'', 1);']); % MATLAB level unlocked
  126. end
  127. set(handles.GeneOrfTog,'value',0)
  128. try
  129. load('EZsgdInfo');
  130. catch
  131. disp('Fail to load EZsgdInfo file from code directory');
  132. end
  133. Exp(numExps+1).SGDnum=SGDnum;
  134. Exp(numExps+1).SGDtext=SGDtext;
  135. Exp(numExps+1).SGDraw=SGDraw;
  136. Exp(numExps+1).interacPBsel=0;
  137. % Big outer loop try catch to ln844 end ln868
  138. % try to use user selected 'ExpJobs' folder otherwise use a default
  139. % directory in the uigetfile to load the experiment .mat file.
  140. try
  141. [matFile,scansDir]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off')
  142. load (fullfile(Exp(1).Dexp(1).ExpFoldr,'MasterPlateFiles','MPDMmat.mat'))
  143. for i=1:numExps
  144. Exp(i).Dexp(1).DM=DM;
  145. Exp(i).Dexp(1).MP=MP;
  146. Exp(i).Dexp(1).scan=scan;
  147. Exp(i).cTraceIndx(1)=1;
  148. end
  149. load(fullfile(resDir,'PTmats','NImParameters'))
  150. Exp(1).Dexp(1).ImParMat=ImParMat;
  151. Exp(2).Dexp(1).ImParMat=ImParMat;
  152. Exp(3).Dexp(1).ImParMat=ImParMat;
  153. try
  154. load(fullfile(resDir,'Fotos','Coordinates'))
  155. load(fullfile(resDir,'Fotos','anlZones'))
  156. load(fullfile(resDir,'Fotos','BGatTpts'))
  157. for i=1:numExps
  158. Exp(i).Dexp(1).FexpScanSpots=FexpScanSpots;
  159. Exp(i).Dexp(1).FexpScanBMtp=FexpScanBMtp;
  160. Exp(i).Dexp(1).anlZoneRefs=anlZoneRefs;
  161. Exp(i).cTraceIndx(1)=1;
  162. end
  163. catch
  164. end
  165. for i=1:numExps
  166. Exp(i).traceN=0; % ZoneRelated
  167. Exp(i).traceN=0;
  168. Exp(i).hOL=[];
  169. Exp(i).hOLb=[];
  170. Exp(i).hOLname={};
  171. Exp(i).hOLexpNm={};
  172. Exp(i).hOLresDir={}
  173. Exp(i).hOLplateNum=[];
  174. Exp(i).hOLresDir={};
  175. Exp(i).RFmd1indx=[];
  176. Exp(i).RFmd1pltN=[];
  177. Exp(i).RFmd2indx=[];
  178. Exp(i).RFmd2pltN=[];
  179. end
  180. % default values for EZvFigPrint that meet JLH preferences
  181. Exp(4).plotPars={'4','36','10','5'};
  182. expN=1;
  183. % Test for Bad MP cell array (usually 384 [NaN}'s)
  184. % replaced length(Exp(expN).Dexp(1).MP) with MPnum
  185. for mx=1:length(Exp(expN).Dexp(1).MP)
  186. try
  187. char((Exp(1).Dexp(1).MP(mx).genename{1}(384)))
  188. MPnum=mx;
  189. catch
  190. break
  191. end
  192. end
  193. % MPnum=length(Exp(expN).Dexp(1).MP);
  194. set(handles.MPsldr1,'min',1,'max',MPnum)
  195. set(handles.MPsldr2,'min',1,'max',MPnum)
  196. set(handles.MPsldr3,'min',1,'max',MPnum)
  197. DMnum=length(Exp(expN).Dexp(1).DM.drug);
  198. set(handles.DMsldr1,'min',1,'max',DMnum) %DMnum,'value',1.01) %100,'value',1.01)
  199. set(handles.DMsldr2,'min',1,'max',DMnum)
  200. set(handles.DMsldr3,'min',1,'max',DMnum)
  201. tPtsSize=size(Exp(expN).Dexp(1).FexpScanBMtp{1,1},(3));
  202. set(handles.Tptsldr1,'min',1,'max',tPtsSize)
  203. set(handles.Tptsldr2,'min',1,'max',tPtsSize)
  204. set(handles.Tptsldr3,'min',1,'max',tPtsSize)
  205. set(handles.MPsldr1,'SliderStep',[1/MPnum 1/MPnum]); %[1/length(MP) 1/length(MP)])
  206. set(handles.DMsldr1,'SliderStep',[1/length(DM.drug) 1/length(DM.drug)]);
  207. set(handles.Tptsldr1,'SliderStep',[1/tPtsSize 1/tPtsSize]);
  208. set(handles.MPsldr2,'SliderStep',[1/MPnum 1/MPnum]);
  209. set(handles.DMsldr2,'SliderStep',[1/length(DM.drug) 1/length(DM.drug)]);
  210. set(handles.Tptsldr2,'SliderStep',[1/tPtsSize 1/tPtsSize]);
  211. set(handles.MPsldr3,'SliderStep',[1/MPnum 1/MPnum]);
  212. set(handles.DMsldr3,'SliderStep',[1/length(DM.drug) 1/length(DM.drug)]);
  213. set(handles.Tptsldr3,'SliderStep',[1/tPtsSize 1/tPtsSize]);
  214. try
  215. xp=char(Exp(expN).Dexp(1).resDir);
  216. if ispc
  217. slashPos=strfind(char(Exp(expN).Dexp(1).resDir),'\');
  218. else
  219. slashPos=strfind(char(Exp(expN).Dexp(1).resDir),'/');
  220. end
  221. startPos=slashPos(length(slashPos)-1) +1;
  222. endPos=slashPos(length(slashPos)) -1;
  223. expStr=xp(startPos:endPos);
  224. set(handles.expName1,'string',expStr);
  225. set(handles.expName2,'string',expStr);
  226. set(handles.expName3,'string',expStr);
  227. catch
  228. cd(w)
  229. end %internal try xp=char(Exp(expN).Dexp(1).resDir); if ispc,...
  230. catch
  231. cd(w)
  232. msg='LOADing or Setup issue'
  233. % if no load, then Message try SelExp PB to reload or try and different experiment
  234. end
  235. try
  236. DNLaxes1=handles.DNLaxes1; DNLaxes2=handles.DNLaxes2; DNLaxes3=handles.DNLaxes3;
  237. zeroCLn=zeros(1,DMnum);
  238. %Exp(expN).expLoadCnt(1)=1; %ZoneRelated
  239. Exp(1).hzeroCLn(1)=plot(DNLaxes1,zeroCLn,1:DMnum,'y'); try set(Exp(1).hzeroCLn,'visible','off'); catch ME, end
  240. Exp(2).hzeroCLn(1)=plot(DNLaxes2,zeroCLn,1:DMnum,'y'); try set(Exp(2).hzeroCLn,'visible','off'); catch ME, end
  241. Exp(3).hzeroCLn(1)=plot(DNLaxes3,zeroCLn,1:DMnum,'y'); try set(Exp(3).hzeroCLn,'visible','off'); catch ME, end
  242. Exp(1).expLoadCnt=1;
  243. Exp(2).expLoadCnt=1;
  244. Exp(3).expLoadCnt=1;
  245. catch ME
  246. ME.message,
  247. end
  248. % Compile GeneList and OrfList
  249. % Sort and add the medians of Ref Plates if RF1,RF2 exist
  250. set(handles.listboxGnOrf,'string',{('Loading')})
  251. lstindx=0;
  252. lstindxOrf=0;
  253. spN=0;
  254. rfcnt=0;
  255. dRF1indx=0;
  256. RF1mp=[];
  257. RF2mp=[];
  258. for mp=1:MPnum %length(Exp(expN).Dexp(1).MP)
  259. RF1fullPlate=0;
  260. try RF1fullPlate=sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}),'RF1'))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
  261. RF2fullPlate=0;
  262. try RF2fullPlate=sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}),'RF2'))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
  263. for ind384=1:384
  264. spN=spN+1;
  265. try % temp find data error
  266. r=ceil(ind384/24);
  267. if rem(ind384,24)==0, c=24; else c=rem(ind384,24); end
  268. % Insert test for numeric in genename and orf if isnumeric
  269. % Correct common EXCEL problem of converting OCT1 into a date numeric
  270. if cell2mat(Exp(expN).Dexp(1).MP(mp).genename{1}(ind384))==38991,
  271. Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)={'OCT1_'};
  272. % genename{1}(ind384) replace numeric with a space ' ' or something
  273. elseif isnumeric(cell2mat(Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)))
  274. Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)={' '};
  275. end
  276. % Check for full(384spot) Reference Plates (RF1 or/and RF2)
  277. RF1fullPlate=0;
  278. try RF1fullPlate=sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}),'RF1'))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
  279. RF2fullPlate=0;
  280. try RF2fullPlate=sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}),'RF2'))==384; catch, mp, msg=strcat(num2str(mp),' genename ERROR'), end
  281. if isempty(regexpi(char((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384))),'blank'))... %,'\<blank\>'
  282. && ~isnumeric(Exp(expN).Dexp(1).MP(mp).orf{1}(ind384))...
  283. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)),' ')...
  284. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)),' ')...
  285. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)),'')...
  286. && ~isempty((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)))...
  287. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)),'RF1')...
  288. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384)),'RF2')...
  289. && iscellstr((Exp(expN).Dexp(1).MP(mp).orf{1}(ind384))) % .genename{1}(ind384)))
  290. lstindxOrf=lstindxOrf+1;
  291. bb(lstindxOrf,1)=(Exp(expN).Dexp(1).MP(mp).orf{1}(ind384));
  292. bb(lstindxOrf,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
  293. bb(lstindxOrf,3)={mp};
  294. bb(lstindxOrf,4)={r};
  295. bb(lstindxOrf,5)={c};
  296. mutorfs(lstindxOrf)=spN; %16_0318 added for Interaction EZinteract
  297. end
  298. if isempty(regexpi(char((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384))),'blank'))... %,'\<blank\>'
  299. && ~isnumeric(Exp(expN).Dexp(1).MP(mp).genename{1}(ind384))...
  300. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),' ')...
  301. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),' ')...
  302. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),'')...
  303. && ~isempty((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)))...
  304. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),'RF1')...
  305. && ~strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),'RF2')...
  306. && iscellstr((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)))
  307. lstindx=lstindx+1;
  308. aa(lstindx,1)=(Exp(expN).Dexp(1).MP(mp).genename{1}(ind384));
  309. aa(lstindx,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
  310. aa(lstindx,3)={mp};
  311. aa(lstindx,4)={r};
  312. aa(lstindx,5)={c};
  313. mutgenes(lstindx)=spN;
  314. % Exp(expN).Dexp(1).mutSpotIndx.woRFs(lstindx)=spN;
  315. elseif (RF1fullPlate==1 ... % sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}),'RF1'))==384 || ...
  316. || (length(unique(Exp(expN).Dexp(1).MP(mp).genename{1}(1:384))))==1 && mp==1 ) ... %(isequal((Exp(expN).Dexp(1).MP(mp).genename{1}(1:384)), (Exp(expN).Dexp(1).MP(mp).genename{1}(384:-1:1)))&& mp==1 )) && ...
  317. && ~exist('RF1scanN','var')
  318. RF1mp=mp
  319. RF1scanN=(mp*DMnum)-(DMnum-1); %mp;
  320. rfcnt=rfcnt+1;
  321. RFs(spN:spN+383)=spN:spN+383;
  322. elseif (RF2fullPlate==1 ... %sum(ismember((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),'RF2'))==384 ||...
  323. || (length(unique(Exp(expN).Dexp(1).MP(mp).genename{1}(1:384))))==1 && mp==MPnum ) && ~exist('RF2scanN','var')
  324. rfcnt=rfcnt+1;
  325. RFs(spN:spN+383)=spN:spN+383;
  326. asdf=sparse(RFs);
  327. asd=find(asdf);
  328. RFs=asd;
  329. RF2mp=mp
  330. RF2scanN=(mp*DMnum)-(DMnum-1); %mp;
  331. elseif strcmpi((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),'RF1') && (RF1fullPlate~=1)
  332. dRF1indx=dRF1indx+1;
  333. Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)=strrep((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384)),':',' ');
  334. drf(dRF1indx,1)=(Exp(expN).Dexp(1).MP(mp).genename{1}(ind384));
  335. drf(dRF1indx,2)={strcat(':',num2str(mp),':',num2str(r),':',num2str(c))};
  336. drf(dRF1indx,3)={mp}; drfMP(dRF1indx,mp)=mp;
  337. drf(dRF1indx,4)={r}; drfr(dRF1indx,mp)=r;
  338. drf(dRF1indx,5)={c}; drfc(dRF1indx,mp)=c;
  339. drf(dRF1indx,6)={ind384}; drfPindx(dRF1indx,mp)=ind384;
  340. end % if isempty(regexpi(char((Exp(expN).Dexp(1).MP(mp).genename{1}(ind384))),'blank'))...
  341. catch
  342. mp
  343. ind384
  344. msgBadGeneName=strcat('check genename at mp=',num2str(mp),' indx=',num2str(ind384))
  345. end
  346. end
  347. mp
  348. end
  349. % Cover case if mutorfs RFs are labeled RF1 or RF2
  350. try
  351. Exp(1).Dexp(1).mutSpotIndx.wRFs=union(RFs, mutorfs);
  352. catch
  353. msg='No RFs Found in Exp! wRFs'
  354. Exp(1).Dexp(1).mutSpotIndx.wRFs=mutorfs;
  355. end
  356. try
  357. Exp(1).Dexp(1).mutSpotIndx.woRFs=setdiff(mutorfs,RFs);
  358. catch
  359. Exp(expN).Dexp(1).mutSpotIndx.woRFs=mutorfs;
  360. msg='No RFs Found in Exp! woRFs'
  361. end
  362. Exp(2).Dexp(1).mutSpotIndx.wRFs=Exp(1).Dexp(1).mutSpotIndx.wRFs;
  363. Exp(2).Dexp(1).mutSpotIndx.woRFs=Exp(1).Dexp(1).mutSpotIndx.woRFs;
  364. Exp(3).Dexp(1).mutSpotIndx.wRFs=Exp(1).Dexp(1).mutSpotIndx.wRFs;
  365. Exp(3).Dexp(1).mutSpotIndx.woRFs=Exp(1).Dexp(1).mutSpotIndx.woRFs;
  366. Exp(1).Dexp(1).RFmd1indx=[]; Exp(2).Dexp(1).RFmd1indx=[]; Exp(3).Dexp(1).RFmd1indx=[];
  367. Exp(1).Dexp(1).RFmd1pltN=[]; Exp(2).Dexp(1).RFmd1pltN=[]; Exp(3).Dexp(1).RFmd1pltN=[];
  368. Exp(1).Dexp(1).RFmean=[]; Exp(2).Dexp(1).RFmean=[]; Exp(3).Dexp(1).RFmean=[];
  369. Exp(1).Dexp(1).RFmeanG=[]; Exp(2).Dexp(1).RFmeanG=[]; Exp(3).Dexp(1).RFmeanG=[];
  370. if exist('RF1scanN','var')
  371. for d=0:(DMnum-1)
  372. medianIndx=[];
  373. nonZeroIndx=[];
  374. medValList=[];
  375. rf1scN=RF1scanN+d;
  376. try %if RF1scanN doesn't exist this addition to list will be skipped
  377. nonZeroIndx=find(Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(1:384,5));
  378. if isempty(nonZeroIndx)
  379. nonZeroCnt=0
  380. medianIndx=nonZeroIndx;
  381. else
  382. nonZeroCnt=length(nonZeroIndx);
  383. end
  384. if ~isempty(nonZeroIndx) && mod(nonZeroCnt,2)==0, medianIndx=nonZeroIndx(1:nonZeroCnt-1); end
  385. if ~isempty(nonZeroIndx) && mod(nonZeroCnt,2)~=0, medianIndx=nonZeroIndx; end
  386. clear medValLst
  387. clear kValLst
  388. clear rValLst
  389. if ~isempty(nonZeroIndx) && length(medianIndx) > (.15*384) % To calc. a median, more than 15% of spots must be nonZero
  390. medValLst=Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(medianIndx,5);
  391. medValList1{d+1}=medValLst;
  392. min1=min(medValLst);
  393. max1=max(medValLst);
  394. std1=std(medValLst);
  395. mean1=mean(medValLst)
  396. kValLst=Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(medianIndx,3); % For Ref Composite 17_1009
  397. rValLst=Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(medianIndx,4); % For Ref Composite 17_1009
  398. mval1=median(medValLst); % (Exp(expN).Dexp(1).scan(RF1scanN).plate(1).CFout(383,5));
  399. RFmd1pos=find(mval1==(Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(1:384,5)))
  400. RFmd1loc(1)=ceil(RFmd1pos/24); %calc r value
  401. RFmd1loc(2)=RFmd1pos - ((RFmd1loc(1)-1)*24); %calc c value
  402. lstindx=lstindx+1;
  403. lstindxOrf=lstindxOrf+1;
  404. aa(lstindx,1)={strcat('RF1md(',num2str(d+1),')')};
  405. aa(lstindx,2)={strcat(':',num2str(RF1mp),':',num2str(RFmd1loc(1)),':',num2str(RFmd1loc(2)))}; %,' std',num2str(std1))};
  406. bb(lstindxOrf,1)={strcat('RF1md(',num2str(d+1),')')};
  407. bb(lstindxOrf,2)={strcat(':',num2str(RF1mp),':',num2str(RFmd1loc(1)),':',num2str(RFmd1loc(2)))}; %,' std',num2str(std1))};
  408. % Composite Reference Amalgum Plot
  409. lstindx=lstindx+1;
  410. lstindxOrf=lstindxOrf+1;
  411. aa(lstindx,1)={strcat('RF1cmp(',num2str(d+1),')')};
  412. aa(lstindx,2)={''};
  413. bb(lstindxOrf,1)={strcat('RF1cmp(',num2str(d+1),')')};
  414. bb(lstindxOrf,2)={''};
  415. Exp(1).Dexp(1).RFmd1LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(2).Dexp(1).RFmd1LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(3).Dexp(1).RFmd1LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2));
  416. Exp(1).Dexp(1).RFmd1indx(d+1)=RFmd1pos; Exp(2).Dexp(1).RFmd1indx(d+1)=RFmd1pos; Exp(3).Dexp(1).RFmd1indx(d+1)=RFmd1pos;
  417. Exp(1).Dexp(1).RFmd1pltN=RF1mp; Exp(2).Dexp(1).RFmd1pltN=RF1mp; Exp(3).Dexp(1).RFmd1pltN=RF1mp;
  418. Exp(1).Dexp(1).RFmd1val(d+1)=mval1; Exp(2).Dexp(1).RFmd1val(d+1)=mval1; Exp(3).Dexp(1).RFmd1val(d+1)=mval1;
  419. Exp(1).Dexp(1).mean1(d+1)=mean1; Exp(2).Dexp(1).mean1(d+1)=mean1; Exp(3).Dexp(1).mean1(d+1)=mean1;
  420. Exp(1).Dexp(1).std1(d+1)=std1; Exp(2).Dexp(1).std1(d+1)=std1; Exp(3).Dexp(1).std1(d+1)=std1;
  421. Exp(1).Dexp(1).min1(d+1)=min1; Exp(2).Dexp(1).min1(d+1)=min1; Exp(3).Dexp(1).min1(d+1)=min1;
  422. Exp(1).Dexp(1).max1(d+1)=max1; Exp(2).Dexp(1).max1(d+1)=max1; Exp(3).Dexp(1).max1(d+1)=max1;
  423. for ic=1:3
  424. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).Lvals=medValLst; %17_1201 TrendOL
  425. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).med=median(medValLst); %For Ref Composite 17_1009
  426. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).mean=mean(medValLst); %For Ref Composite 17_1009
  427. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).std=std(medValLst); %For Ref Composite 17_1009
  428. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).min=min(medValLst); %For Ref Composite 17_1009
  429. Exp(ic).Dexp(1).RFcmpL(1).dm(d+1).max=max(medValLst); %For Ref Composite 17_1009
  430. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).Kvals=kValLst; %17_1201 TrendOL
  431. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).mean=mean(kValLst); %For Ref Composite 17_1009
  432. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).med=median(kValLst); %For Ref Composite 17_1009
  433. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).std=std(kValLst); %For Ref Composite 17_1009
  434. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).min=min(kValLst); %For Ref Composite 17_1009
  435. Exp(ic).Dexp(1).RFcmpK(1).dm(d+1).max=max(kValLst); %For Ref Composite 17_1009
  436. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).rvals=rValLst; %17_1201 TrendOL
  437. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).med=median(rValLst); %For Ref Composite 17_1009
  438. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).mean=mean(rValLst); %For Ref Composite 17_1009
  439. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).std=std(rValLst); %For Ref Composite 17_1009
  440. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).min=min(rValLst); %For Ref Composite 17_1009
  441. Exp(ic).Dexp(1).RFcmpr(1).dm(d+1).mean=max(rValLst); %For Ref Composite 17_1009
  442. end
  443. else
  444. % Pick the first spot with zeros
  445. medianCalcFailed='To Few nonZero spots for valid median RF1 selection'
  446. firstZero=find(((Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(1:384,5))==0),1,'first')
  447. Exp(1).Dexp(1).RFmd1indx(d+1)=firstZero; Exp(2).Dexp(1).RFmd1indx(d+1)=firstZero; Exp(3).Dexp(1).RFmd1indx(d+1)=firstZero;
  448. Exp(1).Dexp(1).RFmd1pltN=RF1mp; Exp(2).Dexp(1).RFmd1pltN=RF1mp; Exp(3).Dexp(1).RFmd1pltN=RF1mp; %EZdestComp uses the masterplate number to get all the destPlates scanNumbers
  449. try, medValList1{d+1}=Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(medianIndx,5); nonZeroCnt; catch end
  450. end
  451. catch
  452. medianCalcTryFailed1='Failed! Failed! But process continued with bogus P1ind384 spot value!'
  453. try
  454. firstZero=find(((Exp(expN).Dexp(1).scan(rf1scN).plate(1).CFout(1:384,5))==0),1,'first')
  455. Exp(1).Dexp(1).RFmd1indx(d+1)=firstZero; Exp(2).Dexp(1).RFmd1indx(d+1)=firstZero; Exp(3).Dexp(1).RFmd1indx(d+1)=firstZero;
  456. catch
  457. Exp(1).Dexp(1).RFmd1indx(d+1)=384; Exp(2).Dexp(1).RFmd1indx(d+1)=384; Exp(3).Dexp(1).RFmd1indx(d+1)=384; %if crapout,Then use spot384 as default to keep going
  458. end
  459. try
  460. Exp(1).Dexp(1).RFmd1pltN=RF1mp; Exp(2).Dexp(1).RFmd1pltN=RF1mp; Exp(3).Dexp(1).RFmd1pltN=RF1mp;
  461. catch
  462. catchissue='Ln334'
  463. Exp(1).Dexp(1).RFmd1pltN=1; Exp(2).Dexp(1).RFmd1pltN=1; Exp(3).Dexp(1).RFmd1pltN=1;
  464. end
  465. end
  466. end
  467. end
  468. Exp(1).Dexp(1).RFmd2indx=[]; Exp(2).Dexp(1).RFmd2indx=[]; Exp(3).Dexp(1).RFmd2indx=[];
  469. Exp(1).Dexp(1).RFmd2pltN=[]; Exp(2).Dexp(1).RFmd2pltN=[]; Exp(3).Dexp(1).RFmd2pltN=[];
  470. if exist('RF2scanN','var')
  471. for d=0:(DMnum-1);
  472. medianIndx2=[];
  473. nonZeroIndx2=[];
  474. medValList2=[];
  475. rf2scN=RF2scanN+d;
  476. try % if RF2scanN doesn't exist this addition to list will be skipped
  477. nonZeroIndx2=find(Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(1:384,5));
  478. if isempty(nonZeroIndx2)
  479. nonZeroCnt2=0
  480. medianIndx2=nonZeroIndx2;
  481. else
  482. nonZeroCnt2=length(nonZeroIndx2);
  483. end
  484. if ~isempty(nonZeroIndx2) && mod(nonZeroCnt2,2)==0, medianIndx2=nonZeroIndx2(1:nonZeroCnt2-1); end
  485. if ~isempty(nonZeroIndx2) && mod(nonZeroCnt2,2)~=0, medianIndx2=nonZeroIndx2; end
  486. clear medValLst2
  487. clear kValLst2
  488. clear rValLst2
  489. if ~isempty(nonZeroIndx2) && length(medianIndx2) > (.15*384) % to calc. a median, more than 15% of spots must be nonZero
  490. medValLst2=Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(medianIndx2,5);
  491. medValList2{d+1}=medValLst2;
  492. min2=min(medValLst2);
  493. max2=max(medValLst2);
  494. std2=std(medValLst2)
  495. mean2=mean(medValLst2);
  496. kValLst2=Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(medianIndx2,3); %For Ref Composite 17_1009
  497. rValLst2=Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(medianIndx2,4); %For Ref Composite 17_1009
  498. mval2=median(medValLst2); %(Exp(expN).Dexp(1).scan(RF2scanN).plate(1).CFout(1:383,5));
  499. RFmd2pos=find(mval2==(Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(1:384,5)));
  500. RFmd2loc(1)=ceil(RFmd2pos/24); %calc r value
  501. RFmd2loc(2)=RFmd2pos - ((RFmd2loc(1)-1)*24); %calc c value
  502. lstindx=lstindx+1;
  503. lstindxOrf=lstindxOrf+1;
  504. aa(lstindx,1)={strcat('RF2md(',num2str(d+1),')')}; %{'RF2md'};
  505. aa(lstindx,2)={strcat(':',num2str(RF2mp),':',num2str(RFmd2loc(1)),':',num2str(RFmd2loc(2)))}; %,' std~',num2str(std2))};
  506. bb(lstindxOrf,1)={strcat('RF2md(',num2str(d+1),')')}; %{'RF2md'};
  507. bb(lstindxOrf,2)={strcat(':',num2str(RF2mp),':',num2str(RFmd2loc(1)),':',num2str(RFmd2loc(2)))}; %,' std~',num2str(std2))};
  508. %Composite Reference Amalgum Plot (CRAP)
  509. lstindx=lstindx+1;
  510. lstindxOrf=lstindxOrf+1;
  511. aa(lstindx,1)={strcat('RF2cmp(',num2str(d+1),')')};
  512. aa(lstindx,2)={''};
  513. bb(lstindxOrf,1)={strcat('RF2cmp(',num2str(d+1),')')};
  514. bb(lstindxOrf,2)={''};
  515. Exp(1).Dexp(1).RFmd2LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(2).Dexp(1).RFmd2LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(3).Dexp(1).RFmd2LB(d+1)=strcat(aa(lstindx,1),aa(lstindx,2));
  516. Exp(1).Dexp(1).RFmd2indx(d+1)=RFmd2pos; Exp(2).Dexp(1).RFmd2indx(d+1)=RFmd2pos; Exp(3).Dexp(1).RFmd2indx(d+1)=RFmd2pos;
  517. Exp(1).Dexp(1).RFmd2pltN=RF2mp; Exp(2).Dexp(1).RFmd2pltN=RF2mp; Exp(3).Dexp(1).RFmd2pltN=RF2mp;
  518. Exp(1).Dexp(1).RFmd2val(d+1)=mval2; Exp(2).Dexp(1).RFmd2val(d+1)=mval2; Exp(3).Dexp(1).RFmd2val(d+1)=mval2;
  519. Exp(1).Dexp(1).mean2(d+1)=mean2; Exp(2).Dexp(1).mean2(d+1)=mean2; Exp(3).Dexp(1).mean2(d+1)=mean2;
  520. Exp(1).Dexp(1).std2(d+1)=std2; Exp(2).Dexp(1).std2(d+1)=std2; Exp(3).Dexp(1).std2(d+1)=std2;
  521. Exp(1).Dexp(1).min2(d+1)=min2; Exp(2).Dexp(1).min2(d+1)=min2; Exp(3).Dexp(1).min2(d+1)=min2;
  522. Exp(1).Dexp(1).max2(d+1)=max2; Exp(2).Dexp(1).max2(d+1)=max2; Exp(3).Dexp(1).max2(d+1)=max2;
  523. for ic=1:3
  524. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).Lvals=medValLst2; %17_1201 TrendOL
  525. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).med=median(medValLst2); %For Ref Composite 17_1009
  526. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).mean=mean(medValLst2); %For Ref Composite 17_1009
  527. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).std=std(medValLst2); %For Ref Composite 17_1009
  528. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).min=min(medValLst2); %For Ref Composite 17_1009
  529. Exp(ic).Dexp(1).RFcmpL(2).dm(d+1).max=max(medValLst2); %For Ref Composite 17_1009
  530. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).Kvals=kValLst2; %17_1201 TrendOL
  531. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).med=median(kValLst2); %For Ref Composite 17_1009
  532. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).mean=mean(kValLst2); %For Ref Composite 17_1009
  533. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).std=std(kValLst2); %For Ref Composite 17_1009
  534. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).min=min(kValLst2); %For Ref Composite 17_1009
  535. Exp(ic).Dexp(1).RFcmpK(2).dm(d+1).max=max(kValLst2); %For Ref Composite 17_1009
  536. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).rvals=rValLst2; %17_1201 TrendOL
  537. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).med=median(rValLst2); %For Ref Composite 17_1009
  538. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).mean=mean(rValLst2); %For Ref Composite 17_1009
  539. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).std=std(rValLst2); %For Ref Composite 17_1009
  540. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).min=min(rValLst2); %For Ref Composite 17_1009
  541. Exp(ic).Dexp(1).RFcmpr(2).dm(d+1).max=max(rValLst); %For Ref Composite 17_1009
  542. end
  543. else
  544. % Pick the first spot with zeros
  545. % Use that position to satisfy and keep process OK
  546. medianCalcFailed2='To Few nonZero spots for valid median RF2 selection'
  547. firstZero2=find(((Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(1:384,5))==0),1,'first')
  548. Exp(1).Dexp(1).RFmd2indx(d+1)=firstZero2; Exp(2).Dexp(1).RFmd2indx(d+1)=firstZero2; Exp(3).Dexp(1).RFmd2indx(d+1)=firstZero2;
  549. Exp(1).Dexp(1).RFmd2pltN=RF2mp; Exp(2).Dexp(1).RFmd2pltN=RF2mp; Exp(3).Dexp(1).RFmd2pltN=RF2mp;
  550. try
  551. medValList2{d+1}=Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(medianIndx2,5);
  552. nonZeroCnt2;
  553. catch
  554. end
  555. end
  556. catch
  557. medianCalcTryFailed2='Failed! Failed! No RF1median But process continued with bogus P1ind384 spot value!'
  558. try
  559. firstZero2=find(((Exp(expN).Dexp(1).scan(rf2scN).plate(1).CFout(1:384,5))==0),1,'first')
  560. Exp(1).Dexp(1).RFmd2indx(d+1)=firstZero2; Exp(2).Dexp(1).RFmd2indx(d+1)=firstZero2; Exp(3).Dexp(1).RFmd2indx(d+1)=firstZero2;
  561. catch
  562. Exp(1).Dexp(1).RFmd2indx(d+1)=384; Exp(2).Dexp(1).RFmd2indx(d+1)=384; Exp(3).Dexp(1).RFmd2indx(d+1)=384; %if crapout,Then use spot384 as default to keep going
  563. end
  564. try
  565. Exp(1).Dexp(1).RFmd2pltN=RF2mp; Exp(2).Dexp(1).RFmd2pltN=RF2mp; Exp(3).Dexp(1).RFmd2pltN=RF2mp;
  566. catch
  567. Exp(1).Dexp(1).RFmd2pltN=1; Exp(2).Dexp(1).RFmd2pltN=1; Exp(3).Dexp(1).RFmd2pltN=1;
  568. end
  569. end % if RF2scanN doesn't exist this addition to list will be skipped
  570. RFcombValList=cat(1,medValList1{d+1},medValList2{d+1});
  571. Exp(1).Dexp(1).RFmean(d+1)=mean(RFcombValList);Exp(2).Dexp(1).RFmean(d+1)=mean(RFcombValList);Exp(3).Dexp(1).RFmean(d+1)=mean(RFcombValList);
  572. Exp(1).Dexp(1).RFstd(d+1)=std(RFcombValList);Exp(2).Dexp(1).RFstd(d+1)=std(RFcombValList);Exp(3).Dexp(1).RFstd(d+1)=std(RFcombValList);
  573. Exp(1).Dexp(1).RFmin(d+1)=min(RFcombValList);Exp(2).Dexp(1).RFmin(d+1)=min(RFcombValList);Exp(3).Dexp(1).RFmin(d+1)=min(RFcombValList);
  574. Exp(1).Dexp(1).RFmax(d+1)=max(RFcombValList);Exp(2).Dexp(1).RFmax(d+1)=max(RFcombValList);Exp(3).Dexp(1).RFmax(d+1)=max(RFcombValList);
  575. % TODO can delete the following redundant line of code
  576. Exp(2).Dexp(1).RFmean(d+1)=Exp(1).Dexp(1).RFmean(d+1); Exp(3).Dexp(1).RFmean(d+1)=Exp(1).Dexp(1).RFmean(d+1);
  577. end
  578. elseif exist('RF1scanN','var')
  579. Exp(1).Dexp(1).RFmean=Exp(1).Dexp(1).mean1; Exp(2).Dexp(1).RFmean=Exp(2).Dexp(1).mean1; Exp(3).Dexp(1).RFmean=Exp(3).Dexp(1).mean1;
  580. Exp(1).Dexp(1).RFstd=Exp(1).Dexp(1).std1; Exp(2).Dexp(1).RFstd=Exp(2).Dexp(1).std1; Exp(3).Dexp(1).RFstd=Exp(3).Dexp(1).std1;
  581. Exp(1).Dexp(1).RFmin=Exp(1).Dexp(1).min1; Exp(2).Dexp(1).RFmin=Exp(2).Dexp(1).min1; Exp(3).Dexp(1).RFmin=Exp(3).Dexp(1).min1;
  582. Exp(1).Dexp(1).RFmax=Exp(1).Dexp(1).max1; Exp(2).Dexp(1).RFmax=Exp(2).Dexp(1).max1; Exp(3).Dexp(1).RFmax=Exp(3).Dexp(1).max1;
  583. end
  584. % DISPERSE REFERENCE PLATES
  585. Exp(expN).Dexp(1).RFmdPindx=[];
  586. Exp(expN).Dexp(1).RFmdPpltN=[];
  587. if exist('drf','var') % ('RF1scanN','var')
  588. % Det. index of change from one MP to the next
  589. i=2;
  590. chgIndx(1)=1;
  591. for j=1:length(drf(:,3))
  592. if j>1
  593. if cell2mat(drf(j,3))~=cell2mat(drf((j-1),3)), chgIndx(i)=j; i=i+1; end
  594. end
  595. end
  596. chgIndx(length(chgIndx)+1)=length(drf)+1;
  597. uu=zeros(size(drf,1),4);
  598. uu(:,1:4)=cell2mat(drf(:,3:6));
  599. vv=zeros(length(drf),DMnum);
  600. dMPs=unique(cell2mat(drf(:,3)));
  601. for mm=1:length(dMPs)
  602. for d=1:(DMnum)
  603. medianIndxDisp=[];
  604. NZrefIndxP=[];
  605. nonZeroValsP=[];
  606. medValLstDisp=[];
  607. rf1scNdisp=((dMPs(mm)-1)*DMnum)+(d);
  608. try % Determine the dispersed RFs median mean and std if such exist
  609. NZrefIndxP=drfPindx((find(drfPindx(:,dMPs(mm)))),dMPs(mm));
  610. vv(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
  611. % For Global Ref Composite 17_1009
  612. vvK(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,3);
  613. vvr(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,4);
  614. nonZeroValsP=nonzeros(Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5));
  615. minDisp=min(nonZeroValsP);
  616. maxDisp=max(nonZeroValsP);
  617. std1Disp=std(nonZeroValsP);
  618. mean1Disp=mean(nonZeroValsP);
  619. drfVals=Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
  620. %MEDIAN Determination for PLATES with Dispersed RFs
  621. if isempty(NZrefIndxP)
  622. nonZeroCntDisp=0
  623. medianIndxDisp=NZrefIndxP;
  624. else
  625. nonZeroCntDisp=length(NZrefIndxP);
  626. end
  627. if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)==0, medianIndxDisp=NZrefIndxP(1:nonZeroCntDisp-1); end
  628. if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)~=0, medianIndxDisp=NZrefIndxP; end
  629. if ~isempty(NZrefIndxP) && length(medianIndxDisp) > 3 %(.15*384) %To calc. a median, more than 15% of spots must be nonZero
  630. medValLstDisp=Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(medianIndxDisp,5);
  631. mval1Disp=median(medValLstDisp);
  632. nonZeroMedPosIndx=find(mval1Disp==nonZeroValsP);
  633. RFmd1posD=NZrefIndxP(nonZeroMedPosIndx);
  634. RFmd1locD(1)=ceil(RFmd1posD/24); %calc r value
  635. RFmd1locD(2)=RFmd1posD - ((RFmd1locD(1)-1)*24); %calc c value
  636. lstindx=lstindx+1;
  637. lstindxOrf=lstindxOrf+1;
  638. aa(lstindx,1)={strcat('RF1mdP(',num2str(d),')')}; %{'RF1md'};
  639. aa(lstindx,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))}; %,'std_',num2str(std1))};
  640. bb(lstindxOrf,1)={strcat('RF1mdP(',num2str(d),')')}; %{'RF1md'};
  641. bb(lstindxOrf,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))}; %,'std_',num2str(std1))};
  642. Exp(1).Dexp(1).RFmdPLB(d,dMPs(mm))=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(2).Dexp(1).RFmdPLB(d,dMPs(mm))=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(3).Dexp(1).RFmdPLB(d,dMPs(mm))=strcat(aa(lstindx,1),aa(lstindx,2));
  643. Exp(1).Dexp(1).RFmdPindx(d,dMPs(mm))=RFmd1posD; Exp(2).Dexp(1).RFmdPindx(d,dMPs(mm))=RFmd1posD; Exp(3).Dexp(1).RFmdPindx(d,dMPs(mm))=RFmd1posD;
  644. Exp(1).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm); Exp(2).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm); Exp(3).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
  645. Exp(1).Dexp(1).RFmedianP(d,dMPs(mm))=mval1Disp; Exp(2).Dexp(1).RFmedianP(d,dMPs(mm))=mval1Disp; Exp(3).Dexp(1).RFmedianP(d,dMPs(mm))=mval1Disp;
  646. Exp(1).Dexp(1).meanP(d,dMPs(mm))=mean1Disp; Exp(2).Dexp(1).meanP(d,dMPs(mm))=mean1Disp; Exp(3).Dexp(1).meanP(d,dMPs(mm))=mean1Disp;
  647. Exp(1).Dexp(1).stdP(d,dMPs(mm))=std1Disp; Exp(2).Dexp(1).stdP(d,dMPs(mm))=std1Disp; Exp(3).Dexp(1).stdP(d,dMPs(mm))=std1Disp;
  648. Exp(1).Dexp(1).minP(d,dMPs(mm))=minDisp; Exp(2).Dexp(1).minP(d,dMPs(mm))=minDisp; Exp(3).Dexp(1).minP(d,dMPs(mm))=minDisp;
  649. Exp(1).Dexp(1).maxP(d,dMPs(mm))=maxDisp; Exp(2).Dexp(1).maxP(d,dMPs(mm))=maxDisp; Exp(3).Dexp(1).maxP(d,dMPs(mm))=maxDisp;
  650. else
  651. % Need to set L r K values to zeros or pick the first spot with zeros
  652. % Spot 1 could be other than zero as the median isn't calculated if fewer than some percent are nonzero
  653. medianCalcFailedD='To Few nonZero spots for valid median RF1 selection'
  654. firstZeroDindx=find(((Exp(expN).Dexp(1).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5))==0),1,'first');
  655. firstZeroD=drfPindx((firstZeroDindx),dMPs(mm));
  656. Exp(expN).Dexp(1).RFmdPindx(d,dMPs(mm))=firstZeroD;
  657. Exp(expN).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm); %RF1mp; %Is this supposed to be the MP number or the ScanPlate number???
  658. end
  659. catch
  660. medianCalcTryFailed1D='Failed! Failed! Ln565 {Dispersed RF1s} "try" But process continued with bogus Plate spot value!'
  661. try
  662. firstZeroindxD=find(vv((chgIndx(d):chgIndx(d+1)-1),5)==0,1,'first')
  663. firstZeroPindx=uu(firstZeroindxD,4);
  664. Exp(expN).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
  665. Exp(expN).Dexp(1).RFmdPindx(d,dMPs(mm))=firstZeroPindx;
  666. catch
  667. catchissue='try at Ln565'
  668. Exp(expN).Dexp(1).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
  669. Exp(expN).Dexp(1).RFmdPindx(d,dMPs(mm))=384; % if crapout,Then use spot384 as default to keep going
  670. end
  671. try
  672. Exp(expN).Dexp(1).RFmdPpltN=dMPs(mm);
  673. catch
  674. catchissue='Ln'
  675. Exp(expN).Dexp(1).RFmdPpltN=1; %This might keep from breaking BUT ???
  676. end
  677. end
  678. end
  679. end
  680. % Calc. Global Mean, Std, And Median For Distributed References
  681. uu=horzcat(uu,vv);
  682. for d=1:DMnum
  683. medianIndxD=[];
  684. NZrfIndxG=[];
  685. minG=min(nonzeros(vv(:,d)));
  686. maxG=max(nonzeros(vv(:,d)));
  687. RFmeanG=mean(nonzeros(vv(:,d)));
  688. RFstdG=std(nonzeros(vv(:,d)));
  689. NZrfIndxG=find(vv(:,d)); % find(nonzeros(vv(:,d))); WWRONG FOR A WHILE! find(nonzeros(vv(:,d)));
  690. if isempty(RFmeanG)
  691. nonZeroCntD=0;
  692. else
  693. nonZeroCntD=length(nonzeros(vv(:,d)));
  694. end
  695. % Calc. of median requires an odd number of indx items
  696. if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)==0, medianIndxD=NZrfIndxG(1:(size(NZrfIndxG,1)-1)); end
  697. if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)~=0, medianIndxD=NZrfIndxG(:); end
  698. if ~isempty(NZrfIndxG) && length(medianIndxD) > (.15*size(drf,1)) % To calc. a median, more than 15% of spots must be nonZero
  699. mvalsDG=median(vv(medianIndxD,d)); % (nonzeros(vv(:,d)));
  700. nzPosIndxDG=find(mvalsDG==vv(:,d));
  701. RFmdDGloc(d,1)=uu(nzPosIndxDG,1); % MP of distributedGlobal Median value
  702. RFmdDGloc(d,2)=uu(nzPosIndxDG,2); % calc r value
  703. RFmdDGloc(d,3)=uu(nzPosIndxDG,3); % calc c value
  704. lstindx=lstindx+1;
  705. lstindxOrf=lstindxOrf+1;
  706. aa(lstindx,1)={strcat('RF1mdG(',num2str(d),')')};
  707. aa(lstindx,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
  708. bb(lstindxOrf,1)={strcat('RF1mdG(',num2str(d),')')};
  709. bb(lstindxOrf,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
  710. % Composite Reference Amalgum Plot
  711. lstindx=lstindx+1;
  712. lstindxOrf=lstindxOrf+1;
  713. aa(lstindx,1)={strcat('RFcmpG(',num2str(d),')')};
  714. aa(lstindx,2)={''};
  715. bb(lstindxOrf,1)={strcat('RFcmpG(',num2str(d),')')};
  716. bb(lstindxOrf,2)={''};
  717. Exp(1).Dexp(1).RFmdGLB(d)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(2).Dexp(1).RFmdGLB(d)=strcat(aa(lstindx,1),aa(lstindx,2)); Exp(3).Dexp(1).RFmdGLB(d)=strcat(aa(lstindx,1),aa(lstindx,2));
  718. Exp(1).Dexp(1).RFmdGindx(d)=nzPosIndxDG; Exp(2).Dexp(1).RFmdGindx(d)=nzPosIndxDG; Exp(3).Dexp(1).RFmdGindx(d)=nzPosIndxDG;
  719. Exp(1).Dexp(1).RFmdGpltN(d)=RFmdDGloc(d,1); Exp(2).Dexp(1).RFmdGpltN(d)=RFmdDGloc(d,1); Exp(3).Dexp(1).RFmdGpltN(d)=RFmdDGloc(d,1);
  720. Exp(1).Dexp(1).RFmdGscanN(d)=uu(nzPosIndxDG,4); Exp(2).Dexp(1).RFmdGscanN(d)=uu(nzPosIndxDG,4); Exp(3).Dexp(1).RFmdGscanN(d)=uu(nzPosIndxDG,4);
  721. Exp(1).Dexp(1).RFmedianG(d)=mvalsDG; Exp(2).Dexp(1).RFmedianG(d)=mvalsDG; Exp(3).Dexp(1).RFmedianG(d)=mvalsDG;
  722. Exp(1).Dexp(1).RFmeanG(d)=RFmeanG; Exp(2).Dexp(1).RFmeanG(d)=RFmeanG; Exp(3).Dexp(1).RFmeanG(d)=RFmeanG;
  723. Exp(1).Dexp(1).RFstdG(d)=RFstdG; Exp(2).Dexp(1).RFstdG(d)=RFstdG; Exp(3).Dexp(1).RFstdG(d)=RFstdG;
  724. Exp(1).Dexp(1).RFminG(d)=minG; Exp(2).Dexp(1).RFminG(d)=minG; Exp(3).Dexp(1).RFminG(d)=minG;
  725. Exp(1).Dexp(1).RFmaxG(d)=maxG; Exp(2).Dexp(1).RFmaxG(d)=maxG; Exp(3).Dexp(1).RFmaxG(d)=maxG;
  726. for ic=1:3
  727. Exp(ic).Dexp(1).RFcmpGL.dm(d).Lvals=vv(medianIndxD,d); %17_1201 TrendOL
  728. Exp(ic).Dexp(1).RFcmpGL.dm(d).med=median(vv(medianIndxD,d)); %For Ref Composite 17_1009
  729. Exp(ic).Dexp(1).RFcmpGL.dm(d).mean=mean(vv(medianIndxD,d)); %For Ref Composite 17_1009
  730. Exp(ic).Dexp(1).RFcmpGL.dm(d).std=std(vv(medianIndxD,d)); %For Ref Composite 17_1009
  731. Exp(ic).Dexp(1).RFcmpGL.dm(d).min=min(vv(medianIndxD,d)); %For Ref Composite 17_1009
  732. Exp(ic).Dexp(1).RFcmpGL.dm(d).max=max(vv(medianIndxD,d)); %For Ref Composite 17_1009
  733. Exp(ic).Dexp(1).RFcmpGK.dm(d).Kvals=vvK(medianIndxD,d); %17_1201 TrendOL
  734. Exp(ic).Dexp(1).RFcmpGK.dm(d).med=median(vvK(medianIndxD,d)); %For Ref Composite 17_1009
  735. Exp(ic).Dexp(1).RFcmpGK.dm(d).mean=mean(vvK(medianIndxD,d)); %For Ref Composite 17_1009
  736. Exp(ic).Dexp(1).RFcmpGK.dm(d).std=std(vvK(medianIndxD,d)); %For Ref Composite 17_1009
  737. Exp(ic).Dexp(1).RFcmpGK.dm(d).min=min(vvK(medianIndxD,d)); %For Ref Composite 17_1009
  738. Exp(ic).Dexp(1).RFcmpGK.dm(d).max=max(vvK(medianIndxD,d)); %For Ref Composite 17_1009
  739. Exp(ic).Dexp(1).RFcmpGr.dm(d).rvals=vvr(medianIndxD,d); %17_1201 TrendOL
  740. Exp(ic).Dexp(1).RFcmpGr.dm(d).med=median(vvr(medianIndxD,d)); %For Ref Composite 17_1009
  741. Exp(ic).Dexp(1).RFcmpGr.dm(d).mean=mean(vvr(medianIndxD,d)); %For Ref Composite 17_1009
  742. Exp(ic).Dexp(1).RFcmpGr.dm(d).std=std(vvr(medianIndxD,d)); %For Ref Composite 17_1009
  743. Exp(ic).Dexp(1).RFcmpGr.dm(d).min=min(vvr(medianIndxD,d)); %For Ref Composite 17_1009
  744. Exp(ic).Dexp(1).RFcmpGr.dm(d).max=max(vvr(medianIndxD,d)); %For Ref Composite 17_1009
  745. end
  746. end
  747. end
  748. end
  749. % End Of Disperse Reference Plataes Calculations And List Additions
  750. % Sort And Build Genelist
  751. Exp(1).Dexp(1).srtGnLst={('CheckMP/MPDMfile')};
  752. gnLstRaw=strcat(aa(:,1),aa(:,2));
  753. Exp(1).Dexp(1).srtGnLst=sort(gnLstRaw);
  754. Exp(2).Dexp(1).srtGnLst=Exp(1).Dexp(1).srtGnLst;
  755. Exp(3).Dexp(1).srtGnLst=Exp(1).Dexp(1).srtGnLst;
  756. orfLstRaw=strcat(bb(:,1),bb(:,2));
  757. Exp(1).Dexp(1).srtOrfLst=sort(orfLstRaw);
  758. Exp(2).Dexp(1).srtOrfLst=Exp(1).Dexp(1).srtOrfLst;
  759. Exp(3).Dexp(1).srtOrfLst=Exp(1).Dexp(1).srtOrfLst;
  760. set(handles.listboxGnOrf,'string',Exp(1).Dexp(1).srtGnLst)
  761. catch ME %Outer loop try around entire code subroutine
  762. cd(w)
  763. set(handles.listboxGnOrf,'string',cellstr([{'Failed To Load'}; {'Check MPDMmat file'};{'Check .xls files'};{'Check \Fotos .mat files'};{'Check \matResults file'}]))
  764. %Exp(expN).Dexp(1).srtGnLst={('Failed To Load')};
  765. Exp(1).Dexp(1).srtGnLst=cellstr([{'Failed To Load'}; {' '}]);
  766. Exp(2).Dexp(1).srtGnLst=cellstr([{'Failed To Load'}; {' '}]);
  767. Exp(3).Dexp(1).srtGnLst=cellstr([{'Failed To Load'}; {' '}]);
  768. %Exp(expN).srtOrfLst={('Failed To Load')};
  769. Exp(1).Dexp(1).srtOrfLst=cellstr([{'Failed To Load'}; {' '}]);
  770. Exp(2).Dexp(1).srtOrfLst=cellstr([{'Failed To Load'}; {' '}]);
  771. Exp(3).Dexp(1).srtOrfLst=cellstr([{'Failed To Load'}; {' '}]);
  772. if ~contains(matFile,'.mat')
  773. ExpOutImFile=fullfile(matFile);
  774. EZvImagesOnly
  775. end
  776. end
  777. expN=1; % Fix 170424
  778. DexpN=1;
  779. EZdiagRFsSheet
  780. Exp(1).Dexp(1).RFrnames=rnames; Exp(2).Dexp(1).RFrnames=rnames; Exp(3).Dexp(1).RFrnames=rnames;
  781. Exp(1).Dexp(1).RFdata=data; Exp(2).Dexp(1).RFdata=data; Exp(3).Dexp(1).RFdata=data;
  782. RFconfig=0;
  783. if sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmean')) ...
  784. && ~isempty(Exp(expN).Dexp(1).RFmean) ...
  785. && sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmeanG')) ...
  786. && isempty(Exp(expN).Dexp(1).RFmeanG)
  787. RFconfig=1;
  788. end
  789. if sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmean'))==0 ...
  790. || isempty(Exp(expN).Dexp(1).RFmean) ...
  791. && sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmeanG')) ...
  792. && ~isempty(Exp(expN).Dexp(1).RFmeanG)
  793. RFconfig=2;
  794. end
  795. if sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmean')) ...
  796. && ~isempty(Exp(expN).Dexp(1).RFmean) ...
  797. && sum(ismember(fieldnames(Exp(expN).Dexp(1)),'RFmeanG')) ...
  798. && ~isempty(Exp(expN).Dexp(1).RFmeanG)
  799. RFconfig=3;
  800. end
  801. Exp(1).RFconfig=RFconfig; Exp(2).RFconfig=RFconfig; Exp(3).RFconfig=RFconfig; % ZoneRelated
  802. try
  803. msgBadGeneName
  804. catch
  805. end
  806. try
  807. Exp(1).Dexp(1).resetHtmpTg=3; Exp(2).Dexp(1).resetHtmpTg=3; Exp(3).Dexp(1).resetHtmpTg=3; % ZoneRelated
  808. if RFconfig==0
  809. RFconfigMsg='No RF1 references in this Experiment Job'
  810. Exp(1).resetHtmpTg=3; Exp(2).resetHtmpTg=3; Exp(3).resetHtmpTg=3; % ZoneRelated
  811. end
  812. catch
  813. end
  814. prntHt=0;
  815. % HtMapTog 'string', 'Current user HL/HN' selection'
  816. try
  817. Exp(1).htmapPBsel=0;
  818. set(handles.HtMapTog1,'string','L')
  819. Exp(2).htmapPBsel=0; %ZoneRelated
  820. set(handles.HtMapTog2,'string','L')
  821. Exp(3).htmapPBsel=0;
  822. set(handles.HtMapTog3,'string','L')
  823. catch
  824. % expN=1;
  825. end
  826. for ic=1:3
  827. Expaa{ic,1}=aa;
  828. Expbb{ic,1}=bb;
  829. end
  830. htMapTogPBfg=0;
  831. Exp(1).htmapRFanswer={'G','L'}; % ZoneRelated
  832. Exp(2).htmapRFanswer={'G','L'};
  833. Exp(3).htmapRFanswer={'G','L'};
  834. zonePB=expN; % added 230828 to fix migration
  835. ghandles=handles;
  836. ghandles.guiFig=gcf;
  837. Exp(4).guiFig=gcf;