% Dave's prgrm: depint - DEP of beads/DNA on INTerdigitated electrodes Fr/17/9/1999 % NOTES: Direction along electrode strips is referred to as LONGITUDINAL; % Direction perpendicular to Longitudinal is referred to as TRANSVERSE clear all; desktop; line1 = 'This is Dave`s "DEPINT" - a program to analyse video frames showing '; line2 = 'DEP collections of beads/DNA on INTerdigitated electrode surfaces '; line3 = '(updated Tu/14/9/1999) Please note MENU BOX on UPPER LEFT of screen '; line4 = ' '; line5 = 'Please ensure youve either RGB or Grayscale frames, or TIFF images '; line6 = 'to analyse &/or display with labels of the form *~**-** for example:'; line7 = 'video 8 ex. 17 Collection @ frequency = 1 MHz is coded as 8#17~1m. '; line8 = 'video 8 ex. 17 Relaxation @ frequency = 1 MHz is coded as 8r17~1m. '; line9 = 'NB1: Word dbitmap files with BOTH # and r images are labelld 8*17~1m'; line10 = 'after 13/9/1999 "-" replaces underscore _ since MATLAB falsprints it'; line11 = 'NB2: Direction ALONG electrode strips is referred to as LONGITUDINAL'; line12 = 'Direction perpendicular to Longitudinal is referred to as TRANSVERSE'; display1 = [line1;line2;line3;line4;line5;line6;line7;line8;line9;line10;... line11;line12]; figure axis off text(0,0.5,display1) fchoice = menu('prgrm choice: ','anlys video & disply','C(y) plts','Plot/Intgrt Cyt & plt C(t)','C time const') if fchoice ~= 4 fproc = menu('DEP process: ','Collections','Relaxations') end close clear display1 switch fchoice case 1 % ---------- analyse video & display --------------- loop = 1 while loop == 1 clear w* g* y* fauto = menu('image process - PRESS','manual &/or setup geometry','automatic processing') switch fauto case 1 ffile = menu('choose image option','RGB - DIB file','RGB - TIF file','grayscale file'); fmpg = 2 ifnum = input('enter 2 digit frame numbr (secs) (eg 04 or 16): ','s') depintl; fcont=menu('Analyse more images?','Yes','No') close loop=fcont case 2 fmpg=menu('enter image option','MPEG file','series of single (tiff, dib, etc') switch fmpg case 1 % ----- process MPEG file ----- expmax= input('please specify no. of EXPERIMENTS to process: ') for expcnt=1:1:expmax % ----- store file information as a matrix ----- sexpcnt=num2str(expcnt) message=['setting up for processing multiple experiments, exp. no: ' sexpcnt] clear message ifvid=input('enter DEP Video No. (eg 8): ') ifvidm(expcnt)=ifvid % store Video number ifexp=input('enter input DEP experiment no. (e.g. 14): ') % Input File DATA ifexpm(expcnt)=ifexp % store Experiment number iffrq=input('enter input FREQUENCY (INTeger) in kHz or MHz range: ') iffrqm(expcnt)=iffrq iffra=input('DEP Frequency range? kiloHz (k) or MegaHz (M): ', 's') affra=double(iffra) affram(expcnt)=affra % store frequency as ASCII %NOTE: tried storing entire filename ASCII but problems w storage cntmax=input('for this EXperiment, specify no. of IMAGES to process: ') cntmaxm(expcnt)=cntmax fframespec=menu('Specify frames numbers:','consequitively - FAST','individually - SLOW') switch fframespec case 1 framestart=input('Consequitive numbering: please state starting NON-zero frame numbr: ') framend=framestart+cntmax-1; message=['for this exp., you will end at frame number ' framend] case 2 end timscale=input('Specify time scale of each frame (eg .5 for .5 secs: ') for cnt=1:1:cntmax switch fframespec case 1 value=framestart + cnt - 1; case 2 value=input('please specify image no: ') end cntvec(cnt)=value; %time=input('please specify time (secs): ') time=value*timscale %timvec(cnt)=time; cntmat(expcnt,cnt)=value; % cntvec(1,cnt) timmat(expcnt,cnt)=time; % timvec(1,cnt) end % end count loop for this experiment end % end experiment loop cntmax=0; for expcnt=1:1:expmax sfvid=num2str(ifvidm(expcnt)); % sfexp=num2str(ifexpm(expcnt)); % affra=affram(expcnt); % retieve file code in ASCII sffra=char(affra); % convert to original string file codename sffrq=num2str(iffrqm(expcnt)); % if fproc==1 ifcode=[sfvid '#' sfexp '~' sffrq sffra]; elseif fproc==2 ifcode=[sfvid 'r' sfexp '~' sffrq sffra]; end cntmax=cntmaxm(expcnt); for cnt=1:1:cntmax cntvec(1,cnt)=cntmat(expcnt,cnt); end ifdata=[ifcode '.dat']; invar=dlmread(ifdata, ';'); sexpcnt=num2str(expcnt) message=['Reading in MPEG file for exp. no: ' sexpcnt] %ifname = [ifcode ifnum] ifdnam = [ifcode '.mpg'] %cntvec for cnt=1:1:cntmax; value=cntmat(expcnt,cnt) time=timmat(expcnt,cnt) clear R; clear B; clear G; clear mpgim; [R, G, B] = mpgread(ifdnam, value); %[m,n]=size(R) message=['finished reading MPEG file, now GRAYSCALEing frame no: ' value] clear message % dummy=menu(' ','Press to continue') mpgim = rgb2gray(R,G,B); % RGB -> intensity gray [m,n]=size(mpgim) cnt %timvec(1,cnt)=timmat(expcnt,cnt) time=timmat(expcnt,cnt) depintl; %dummy=menu(' ','Press to continue') end % end series of images (in each exprment) loop end % end experiment loop % case 2 % ----- process DIB/TIFF etc file ----- ifcode=input('enter input DATA filename WITHOUT "**.dat": ','s') % Input File DATA ifdata=[ifcode '.dat'] invar=dlmread(ifdata, ';') ffile=invar(1) cntmax=input('please specify no. of images to process: ') for cnt=1:1:cntmax time=input('enter time (secs) label on i/p image file: ') timvec(cnt)=time end for cnt=1:1:cntmax time=timvec(cnt) ifnum=num2str(time) depintl; % process image end end % end switch case fmpg loop=2 end % end switch fauto end % end while loop hold off close case 2 % ---------- plot C(y)s --------------- fcol=menu('Choose: ','C(y) plots & store Cyt mtrx','Abov optn & include Time information') loop = 1 c = 0 figure while loop == 1 c = c+1 % counter C counts for images taken at different times ifname=input('enter Cy.dat part-filename WITHOUT Cyt.dat: ','s') ifdnam = [ifname 'Cy.dat'] sumCy = dlmread(ifdnam, ';') % enter data wth ifname of tif image [m,n] = size(sumCy) % m rows and n = 1 columns p = 1:1:m Cyprf(p,c)=sumCy(p,1) % set Cy matrix of PROfles for different times if fcol == 2 time=input('enter time (secs) this image was taken: ') tim(c) = time end lincol=input('enter plotting line color & type e.g. r--: ','s') % linecolor/type string plot(p,sumCy',lincol) % legend(ifname) % unable to accumulate legend details! gtext(ifname) % ,lincol) can't color the gtext! hold on loop=menu('Press to','Plot more DEP profiles','Store image & data Cy(t)/End') end % end while loop print -dbitmap dummy=menu('Cy profiles dbitmapped - please open WORD & Paste','then PRESS to contnu') ofCytn = input('enter Cyt o/p matrix-filnam WITHOUT Cyt.dat (e.g. 8#6-1m): ','s') ofdCyt = [ofCytn 'Cyt.dat'] dlmwrite(ofdCyt,Cyprf, ';') % print/save matrix of Cy profiles for times (t) if fcol == 2 ofdtim = [ofCytn 'tim.dat'] dlmwrite(ofdtim,tim, ';') % print/save vector of times corresponding to Cy % NOTE: Any elements whose value is 0 will be omitted. e.g. [1 0 2] will appear like '1,,2'. end close close case 3 % ------------- Intgrat Cyt & plt Ct s ------------------------ fplotCy=menu('Do you want (re-) plot C(y,t)?','YES - re/plot','NO - not needed') fnewold=menu('Importing DEP profiles & times ...','< Feb 99(separate)','> Feb 99(together)') switch fnewold % --- Import matrix filenameCyt.dat --- case 1 % < Feb 1999 (separate) ifCytn = input('enter Cyt i/p matrix-filnam WITHOUT Cyt.dat (e.g. 8#6~1m, or 8r17~1m): ','s') ifdCyt = [ifCytn, 'Cyt.dat'] Cyprf = dlmread(ifdCyt, ';') % import in stored matrix filenameCyt.dat ifdCytim = [ifCytn, 'tim.dat'] tim = dlmread(ifdCytim, ';') % import in stored matrix filenametim.dat [m,n]=size(Cyprf) % % m rows in each profile (transverse displacement Y) and n column times [u,v]=size(tim) % for debugging - corresponding to time (u=1 row, v columns) p=1:1:m % no. points in each profile q=1:1:n % no. of times timvec(1,q)=tim(1,q) sumCyt(q,p)=Cyprf(p,q)' case 2 % > Feb 1999 (time & profiles combined) ifCytn = input('enter Cyt i/p matrix-filnam WITHOUT Cyt.dat (e.g. 8#6~1m, or 8r17~1m): ','s') ifdCyt = [ifCytn, 'Cyt.dat'] Cytmat = dlmread(ifdCyt, ';') % import in stored matrix filenameCyt.dat [cntmax,n] = size(Cytmat) % cntmax rows (transverse displacement Y) and n column profiles n1=n-1 p = 1:1:n1 pc= 2:1:n % p complemnt cnt=1:1:cntmax timvec(1,cnt)=Cytmat(cnt,1)' sumCyt(cnt,p)=Cytmat(cnt,pc); end % end switch fnewold switch fplotCy case 1 % case1 fplotCy: replot fDimPlot=menu('Type of C(y,t) plot?','Automatic 3-D plot','C(y) fr chosn times') switch fDimPlot case 1 multiplot; case 2 % --- 2-D re-plot & enter Y integration limits --- figure floop = 1 while floop == 1 time=input('Cyt times displyd - enter time (secs) for plotting: ') pointer=find(timvec==time) profplot(1,p)=sumCyt(pointer,p) lincol=input('enter plotting line color & type e.g. r--: ','s') % linecolor/type string plot(p,profplot,lincol) Tlabl1=num2str(time) Tlabl2=[Tlabl1 ' s'] gtext(Tlabl2) hold on floop=menu('More Cy profiles plotted?','YES - re-do','No - show limits & store') end % end while loop for the Cyt matrix imaged & processed, ask for more switch fnewold case 1 case 2 fcont = 2 while fcont == 2 col(1)=input('enter lower limit of pixel integration: ') col(2)=input('enter upper limit of pixel integration: ') %vecmax=max(Cytmat) vecmax=max(sumCyt) Cytmax=max(vecmax) plot(col,Cytmax,'b+') hold on fcont=menu('Happy with entered limits?','Yes, continue','No, re-enter') hold off end % end fcont while loop end % end switch fnewold xlabel('1/2 electrode & gap widths (pixel no.)') ylabel('Fluorescence (a.u.)') if fproc==1; title('DEP (x,t) Collection profiles') elseif fproc==2; title('DEP (x,t) Relaxation profiles') end hold on print -dbitmap dummy=menu('Cy profiles dbitmapped - please open WORD & Paste','then PRESS to contnu') %ylabel('Accumulated Longitudinal Intensity') %xlabel('Half-electrode & half-gap (pixels)') %title('Intensity verses Transverse Displacement (y)') hold off close end % end fDimPlot - end of 3-D or 2-D choice case 2 % fplotCy case 2: re/plot NOT needed col(1)=input('Enter lower limit of pixel integration: ') col(2)=input('Enter upper limit of pixel integration: ') fintgr=menu('Choose intgrtion methd','Simple pixel count','Trapezium rule') fnormal=menu('C(t) plot normlisd (wrto pixel intens)','Normalised','NOT normalised') % --- Integrate Cyt over Y, bounded by upper & lower limits, & normalise to yield Ct --- for c = 1:1:cntmax switch fnormal case 1 % --- Evaluate normalisation constant nrmsum --- nrmsum = 0 switch fintgr case 1 % simple pixel count for k = 1:1:n1; nrmsum = nrmsum + sumCyt(c,k); % pixel sum betw upp/lower limits end case 2 % Trapezium rule k1=1; k2=n1; nrmsum = nrmsum + sumCyt(c,k1) + sumCyt(c,k2); for k = k1+1:1:k2-1; nrmsum = nrmsum + sumCyt(c,k); % pixel sum betw upp/lower limits end end % end switch fintgr case 2 % Otherwise if there's in no normalisation nrmsum = 1 nrmsum = 1 end % end evaluation of normmalisation constant nrmsum % Now evaluate Cyt over Y, bounded by upper & lower limits --- pixsum = 0 switch fintgr case 1 % simple pixel count for k = col(1):1:col(2); pixsum = pixsum + sumCyt(c,k); % pixel sum betw upp/lower limits end case 2 % Trapezium rule k1=col(1); k2=col(2); pixsum = pixsum + sumCyt(c,k1) + sumCyt(c,k2); for k = k1+1:1:k2-1; pixsum = pixsum + sumCyt(c,k); % pixel sum betw upp/lower limits end end % end switch fintgr collect(c)=pixsum/nrmsum % store pixel sum for this profile at frame count c end % end c count % --- Plot Ct or otherwise called C(t) --- fcont = 1; LL=num2str(col(1)); UL=num2str(col(2)); message=['Please place mouse cursor over area for labellings on graph'] % - Setting up labels to be placed on graphs - switch fintgr % Label: integration method & limits case 1 Limlabel=['Simple pixel count (LL=' LL ' UL=' UL ')']; case 2 Limlabel=['Trapezium method (LL=' LL ' UL=' UL ')']; end % end switch Limlabel switch fnormal % Label: NOT/normalised case 1 NL=num2str(n1) Nrmlabel=['Normalised ' ifdCyt 'plot (LL=1 UL=' NL ')']; case 2 Nrmlabel=[ifdCyt '(Not normalised)'] end % end switch Nrmlabel while fcont == 1 % --- plot Ct loop --- figure plot(timvec,collect,timvec,collect,'r+') gtext(Limlabel) gtext(Nrmlabel) hold on fcont=menu('Reposition labels','Yes','No - continue on') end % end while fcont xlabel('Time (seconds)') ylabel('Fluorescence (a.u.)') if fproc==1; title('DEP Collection onto INTdigt`d electrds') elseif fproc==2; title('DEP Relaxation from INTdigt`d electrds') end %title('Fluourscence) print -dbitmap dummy=menu('Ct profiles dbitmapped - please open WORD & Paste','press to continue') hold off close % ofCtn = input('enter Ct o/p matrix-filnam WITHOUT Ct.dat (e.g. 8#6-1m): ','s') ofdCt = [ifCytn 'Ct.dat'] switch fnewold % --- Export matrix filenameCyt.dat --- case 1 % < Feb 1999 (*Cyt & current *tim in separate files) dlmwrite(ofdCt,collect, ';') % print/save matrix of Cy profiles for times (t) case 2 % < Feb 1999 (*Cyt and *tim in combined fileneameCyt.dat) combined(cnt,1)=timvec(1,cnt)' combined(cnt,2)=collect(1,cnt)' dlmwrite(ofdCt,combined, ';') % print/save 2 column matrix of Cy profiles with times (t) end % end switch fnewold - hold off end % end switch fplotCy close close case 4 % --- Fitting to k(1-exp(-gamma*t)) --- ifCtn = input('enter Cyt i/p matrix-filnam WITHOUT Ct.dat (e.g. 8#6~1m): ','s') ifdCt = [ifCtn, 'Ct.dat'] Ctprf = dlmread(ifdCt, ';') % inport in stored matrix filenameCt.dat Ctmax = max(Ctprf) Ctmin = min(Ctprf) Cscale=(Ctmax-Ctmin)/0.99995 ifdCytim = [ifCtn 'tim.dat'] tim = dlmread(ifdCytim, ';') [m,n] = size(tim) % m rows, n columns figure plot(tim,Ctprf,tim,Ctprf,'r+') dummy=menu('Fitting to k(1-exp(-gamma*t)): note Ct max & Ct min','Press to continue - find C^(t)') fcont = 1 while fcont == 1 % fitting k(1-exp(-gamma*t)) curve close c=1:1:n % Ctnew(c)=-log(1-Ctprf(c)/(Ctmin+Cscale)) figure plot(tim,Ctnew,tim,Ctnew,'r+') dummy=menu('Fitting to k(1-exp(-gamma*t)): note slope of points','Press to continue - fit C^(t)') gamma=input('enter best fit slope value :') close Ctexp(c)=Ctmin + Cscale*(1 - exp(-gamma*tim(c)')) figure plot(tim,Ctexp,tim,Ctprf,'r+') fcont=menu('Press to: ','Re-do plot','Store image & end') end % end while fcont (Flag CONTinue) hold on tau=1/gamma taul = num2str(tau); label=['1-1/e time const (secs) = ' taul]; gtext(label); hold on print -dbitmap dummy=menu('Ct profiles dbitmapped - please open WORD & Paste','press to continue') %ofCten = input('enter Ct o/p matrix-filnam WITHOUT Ct.dat (e.g. 8#6-1m): ','s') %ofdCte = [ofCten 'Ct.dat'] %dlmwrite(ofdCte,collect, ';') % print/save matrix of Cy profiles for times (t) hold off close end % end switch case fchoice for depint %h=gcf %[X,map]=capture(h); % capture current figure - COULDN'T GET THIS TO WORK! %ofname=input('Please type desired plot filename.ext (e.g.) .tiff: ','s') %imwrite(X,MAP,ofname); %print ofname-f %print -dmeta