EZusrSelRefx.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. %EZusrSelRef
  2. % User Select Reference Diaglog Box
  3. try
  4. if n==1 && ~exist('RF1scanN','var') && ~exist('RF2scanN','var') %change || &&
  5. %{
  6. prompt={'Enter Masterplate Number(s) of Your Reference GeneName spots:',...
  7. 'Enter GeneName of Your Reference:'};
  8. rfMPstr=cell2mat(answer(1));
  9. rfMPcomas=strfind((cell2mat(answer(1))),',');
  10. n=0;
  11. if isempty(rfMPcomas)|| max(rfMPcomas)==length(rfMPstr)
  12. usrMPs=rfMPstr
  13. else
  14. for i=rfMPcomas,
  15. n=n+1
  16. usrMPs(n)=str2double(rfMPstr(i-1:i))
  17. if i==max(rfMPcomas)
  18. usrMPs(n+1)=str2double(rfMPstr(i:end))
  19. end
  20. end
  21. end
  22. usrMPs=answer(1);
  23. refGene=answer(2);
  24. %}
  25. prompt={'Enter GeneName to use as Reference:',...
  26. 'Enter Specifics Term if used to futher specify Reference '}
  27. dlg_title='User Reference Input';
  28. num_lines=1;
  29. def={'None','Specifics Term'};
  30. answer=inputdlg(prompt,dlg_title,num_lines,def);
  31. rfGenestr=cell2mat(answer(1));
  32. rfSpec=cell2mat(answer(2));
  33. end
  34. %try
  35. for mp=1:length(Exp(expN).Dexp(DexpN).MP)
  36. for ind384=1:384
  37. spN=spN+1;
  38. end
  39. %catch
  40. %end %try for user selected Reference routine
  41. end
  42. % Disperse Reference Plates
  43. Exp(expN).Dexp(DexpN).RFmdPindx=[];
  44. Exp(expN).Dexp(DexpN).RFmdPpltN=[];
  45. if exist('drf','var') % ('RF1scanN','var')
  46. %Det. index of change from one MP to the next
  47. i=2;
  48. chgIndx(1)=1;
  49. for j=1:length(drf(:,3))
  50. if j>1
  51. if cell2mat(drf(j,3))~=cell2mat(drf((j-1),3)), chgIndx(i)=j; i=i+1; end
  52. end
  53. end
  54. chgIndx(length(chgIndx)+1)=length(drf)+1;
  55. uu=zeros(size(drf,1),4);
  56. uu(:,1:4)=cell2mat(drf(:,3:6))
  57. vv=zeros(length(drf),DMnum);
  58. dMPs=unique(cell2mat(drf(:,3)));
  59. %{
  60. for mm=1:MPnum
  61. nonZrfIndx.mp{mm,:}=drfPindx((find(drfPindx(:,mm))),mm);
  62. end
  63. %}
  64. % nzValsG=zeros(DMnum,size(drf,1));
  65. % nzValsAcc=zeros(DMnum,384);
  66. for mm=1:length(dMPs) % length(chgIndx)
  67. for d=1:(DMnum)
  68. medianIndxDisp=[];
  69. NZrefIndxP=[];
  70. nonZeroValsP=[];
  71. medValLstDisp=[];
  72. rf1scNdisp=((dMPs(mm)-1)*DMnum)+(d);
  73. try % Determine the dispersed RFs median mean and std if such exist
  74. NZrefIndxP=drfPindx((find(drfPindx(:,dMPs(mm)))),dMPs(mm)); %find(Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(drf(chgIndx(cI):chgIndx(cI+1)),5));
  75. % vv=Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
  76. vv(chgIndx(mm):(chgIndx(mm+1)-1),d)=Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
  77. nonZeroValsP=nonzeros(Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5));
  78. std1Disp=std(nonZeroValsP);
  79. mean1Disp=mean(nonZeroValsP);
  80. minDisp=min(nonZeroValsP);
  81. maxDisp=max(nonZeroValsP);
  82. drfVals=Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5);
  83. %nzValsAcc(mm).DM(d,:)=nonZeroValsP;
  84. %MEDIAN Determination for PLATES with Dispersed RFs
  85. %NZrefIndxP=NZrefIndxP %find(Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5));
  86. if isempty(NZrefIndxP)
  87. nonZeroCntDisp=0
  88. medianIndxDisp=NZrefIndxP;
  89. else
  90. nonZeroCntDisp=length(NZrefIndxP);
  91. end
  92. if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)==0, medianIndxDisp=NZrefIndxP(1:nonZeroCntDisp-1); end
  93. if ~isempty(NZrefIndxP) && mod(nonZeroCntDisp,2)~=0, medianIndxDisp=NZrefIndxP; end
  94. if ~isempty(NZrefIndxP) && length(medianIndxDisp) > 3 %(.15*384) %To calc. a median, more than 15% of spots must be nonZero
  95. medValLstDisp=Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(medianIndxDisp,5);
  96. %medValList1Disp{d}=medValLstDisp;
  97. mval1Disp=median(medValLstDisp); %mval1=median(Exp(expN).Dexp(DexpN).scan(RF1mps).plate(1).CFout(1:384,5)); %CFout(1:383,5));
  98. nonZeroMedPosIndx=find(mval1Disp==nonZeroValsP); %(Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5))); %(nonZeroIndxDisp,5))); %((nonZrfIndx.mp{dMPs(mm),:}),5)));
  99. RFmd1posD=NZrefIndxP(nonZeroMedPosIndx); %drfPindx((RFmd1posIndx),dMPs(mm));
  100. RFmd1locD(1)=ceil(RFmd1posD/24); %calc r value
  101. RFmd1locD(2)=RFmd1posD - ((RFmd1locD(1)-1)*24); %calc c value
  102. lstindx=lstindx+1;
  103. lstindxOrf=lstindxOrf+1;
  104. aa(lstindx,1)={strcat('RF1mdP(',num2str(d),')')};
  105. aa(lstindx,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))};
  106. bb(lstindxOrf,1)={strcat('RF1mdP(',num2str(d),')')};
  107. bb(lstindxOrf,2)={strcat(':',num2str(dMPs(mm)),':',num2str(RFmd1locD(1)),':',num2str(RFmd1locD(2)))};
  108. Exp(expN).Dexp(DexpN).RFmdPLB(d,dMPs(mm))=strcat(aa(lstindx,1),aa(lstindx,2));
  109. Exp(expN).Dexp(DexpN).RFmdPindx(d,dMPs(mm))=RFmd1posD;
  110. Exp(expN).Dexp(DexpN).RFmdPpltN(d,dMPs(mm))=dMPs(mm); %This is a storage of the MasterPlate used NOT the ScanPlate? WeMight wish to store the ScanPlateNumber also???
  111. Exp(expN).Dexp(DexpN).RFmdPscanN(d,dMPs(mm))=rf1scNdisp;
  112. Exp(expN).Dexp(DexpN).RFmedianP(d,dMPs(mm))=mval1Disp;
  113. Exp(expN).Dexp(DexpN).stdP(d,dMPs(mm))=std1Disp;
  114. Exp(expN).Dexp(DexpN).meanP(d,dMPs(mm))=mean1Disp;
  115. Exp(expN).Dexp(DexpN).minP(d,dMPs(mm))=minDisp;
  116. Exp(expN).Dexp(DexpN).maxP(d,dMPs(mm))=maxDisp;
  117. else
  118. % Need to set L r K values to zeros or pick the first spot with zeros
  119. % Spot 1 could be other than zero as the median isn't calculated if fewer than some percent are nonzero
  120. medianCalcFailedD='To Few nonZero spots for valid median RF1 selection'
  121. firstZeroDindx=find(((Exp(expN).Dexp(DexpN).scan(rf1scNdisp).plate(1).CFout(NZrefIndxP,5))==0),1,'first');
  122. firstZeroD=drfPindx((firstZeroDindx),dMPs(mm));
  123. Exp(expN).Dexp(DexpN).RFmdPindx(d,dMPs(mm))=firstZeroD;
  124. Exp(expN).Dexp(DexpN).RFmdPpltN(d,dMPs(mm))=dMPs(mm); %RF1mp; %Is this supposed to be the MP number or the ScanPlate number???
  125. end
  126. catch
  127. medianCalcTryFailed1D='Failed! Failed! Ln565 {Dispersed RF1s} "try" But process continued with bogus Plate spot value!'
  128. try
  129. firstZeroindxD=find(vv((chgIndx(d):chgIndx(d+1)-1),5)==0,1,'first');
  130. firstZeroPindx=uu(firstZeroindxD,4);
  131. Exp(expN).Dexp(DexpN).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
  132. Exp(expN).Dexp(DexpN).RFmdPindx(d,dMPs(mm))=firstZeroPindx;
  133. catch
  134. Exp(expN).Dexp(DexpN).RFmdPpltN(d,dMPs(mm))=dMPs(mm);
  135. Exp(expN).Dexp(DexpN).RFmdPindx(d,dMPs(mm))=384; %if crapout,Then use spot384 as default to keep going
  136. end
  137. try
  138. Exp(expN).Dexp(DexpN).RFmdPpltN=dMPs(mm);
  139. catch
  140. Exp(expN).Dexp(DexpN).RFmdPpltN=1; %This might keep from breaking BUT ???
  141. end
  142. end
  143. end % for d=0:DMnum
  144. end % for mm=1:length(dMPs)
  145. % Calc. Global Mean, Std, And Median For Distributed References
  146. uu=horzcat(uu,vv);
  147. for d=1:DMnum
  148. medianIndxG=[];
  149. NZrfIndxG=[];
  150. minG=min(nonzeros(vv(:,d)));
  151. maxG=max(nonzeros(vv(:,d)));
  152. RFmeanG=mean(nonzeros(vv(:,d)));
  153. RFstdG=std(nonzeros(vv(:,d)));
  154. NZrfIndxG=find(nonzeros(vv(:,d)));
  155. if isempty(RFmeanG)
  156. nonZeroCntD=0
  157. % medianIndxDisp=RFmeanG(d);
  158. else
  159. nonZeroCntD=length(nonzeros(vv(:,d)));
  160. end
  161. % Calc. of median requires an odd number of indx items
  162. if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)==0, medianIndxD=NZrfIndxG(1:(size(NZrfIndxG,1)-1)); end
  163. if ~isempty(NZrfIndxG) && mod(nonZeroCntD,2)~=0, medianIndxD=NZrfIndxG(:); end
  164. if ~isempty(NZrfIndxG) && length(medianIndxD) > (.15*size(drf,1)) % To calc. a median, more than 15% of spots must be nonZero
  165. mvalsDG=median(vv(medianIndxD,d)); % (nonzeros(vv(:,d)));
  166. nzPosIndxDG=find(mvalsDG==vv(:,d));
  167. RFmdDGloc(d,1)=uu(nzPosIndxDG,1); % MP of distributedGlobal Median value
  168. RFmdDGloc(d,2)=uu(nzPosIndxDG,2); % calc r value
  169. RFmdDGloc(d,3)=uu(nzPosIndxDG,3); % calc c value
  170. lstindx=lstindx+1;
  171. lstindxOrf=lstindxOrf+1;
  172. aa(lstindx,1)={strcat('RF1mdG(',num2str(d),')')};
  173. aa(lstindx,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
  174. bb(lstindxOrf,1)={strcat('RF1mdG(',num2str(d),')')};
  175. bb(lstindxOrf,2)={strcat(':',num2str(RFmdDGloc(d,1)),':',num2str(RFmdDGloc(d,2)),':',num2str(RFmdDGloc(d,3)))}; %,'std_',num2str(std2))};
  176. Exp(expN).Dexp(DexpN).RFmdGLB(d)=strcat(aa(lstindx,1),aa(lstindx,2));
  177. Exp(expN).Dexp(DexpN).RFmdGindx(d)=nzPosIndxDG;
  178. Exp(expN).Dexp(DexpN).RFmdGpltN(d)=RFmdDGloc(d,1);
  179. Exp(expN).Dexp(DexpN).RFmdGscanN(d)=uu(nzPosIndxDG,4);
  180. Exp(expN).Dexp(DexpN).RFmedianG(d)=mvalsDG;
  181. Exp(expN).Dexp(DexpN).RFminG(d)=minG;
  182. Exp(expN).Dexp(DexpN).RFmaxG(d)=maxG;
  183. Exp(expN).Dexp(DexpN).RFstdG(d)=RFstdG;
  184. Exp(expN).Dexp(DexpN).RFmeanG(d)=RFmeanG;
  185. end
  186. end
  187. end
  188. catch
  189. msg='Failed attempt to apply User Selected Reference'
  190. end