function int_track %========================================================= % November 4, 2015 % This code is for finding trajectories of background level from %multiple region of interests. By looking at when the background level %increases by a very low concentration of dye, you can identify BsSMC %arrival time. % This code assumes that the signal is moving in the y-direction % How to use it? %(1) Open the raw movie file using ImageJ. %(2) "Analyze" tab -> "Set Measurements" -> Select "Bounding rectangle" %(3) Designate region of interest (ROI) by dragging the mouse over it. %(4) Ctrl + t %(5) Repeat until regions of all of the events were selected. %(6) In the "ROI Manager" window of ImageJ, click "Measure". This will % give you x- and y-coordinates, width, height of each ROI. %(7) Save it as "(File name).txt" %(8) Now we need to find out background intensity level right next to % each ROI. You can do it by "Ctrl + t" %(9) Save it (only for background ROI - NOT including signal ROI) as % "(Another file name).txt" %(10) Let's say we have 10 DNAs. Then, "(File name).txt" contains % coordinate information for 10 signals, and "(Another file name).txt" % contains those for 10 background levels. %(11) Save averaged image. This can be done by "Image" tab -> "Stacks" -> % "Z Project". The averaged image must be saved under the name "AVG_ % (File name).tif" %(12) Save the raw data movie file as Image sequence. For example, if your % movie file consists of 100 frames, save individual frame as a seperate % TIFF file (= 100 files) %(13) Now Open this "int_track.m" Matlab file, and run it. % Details on the code is commented throughout this code. %========================================================= clear all close all % User Inputs % select directory with images to be analyzed filepath=uigetdir('','select directory that has images to be analyzed'); % change matlab "Current Folder" to the selected directory cd(filepath) % load only tif image files D=dir([filepath,filesep,'*.tif']); % get image file prefix % Assume that my image files are named as "abc100mM-0001.tif" % "abc100mM-0002.tif",..., and so on. If your file names are named % differently, simply change below two lines accordingly. fname=D(1).name(1:regexp(D(1).name,'mM-')+2); % beginning frame frame_min=input('starting frame = '); % ending frame frame_max=input(['ending frame (',num2str(sum(strncmp(fname,{D.name},length(fname)))),... ' images available) = ']); % frame increment step=input('frame increment = '); % ccd integration time in secs int_time=input('time per frame (seconds) = '); % select ROI text file to be analyzed roi_file=uigetfile('*.txt','select DNA ROI.txt'); % select DNA background ROI text file bgr_roi_file=uigetfile('*.txt','select DNA background ROI.txt (or click ''cancel'')'); % directory to save analyzed data and figures outdir=uigetdir('','select directory to save output'); outfname=input('name output (e.g. ''kymo1''): '); % read ROI data ROIs=dlmread(roi_file,'\t',1,0); if bgr_roi_file~=0 bgrROI=dlmread(bgr_roi_file,'\t',1,0); % Change index of ROIs that marked in ImageJ to matlab format bgrxmin=bgrROI(2)+1; %minimum x pixel number bgrymin=bgrROI(3)+1; %minimum y pixel number bgrwidth=bgrROI(4); %change in x (pixels) bgrheight=bgrROI(5); %change in y (pixels) bgrxmax=bgrxmin+bgrwidth-1; %maximum x pixel number bgrymax=bgrymin+bgrheight-1; %maximum y pixel number end for ii=1:size(ROIs,1) % Change index of ROIs that marked in ImageJ to matlab format xmin=ROIs(ii,2)+1; %minimum x pixel number ymin=ROIs(ii,3)+1; %minimum y pixel number width=ROIs(ii,4); %change in x (pixels) height=ROIs(ii,5); %change in y (pixels) xmax=xmin+width-1; %maximum x pixel number ymax=ymin+height-1; %maximum y pixel number for i=frame_min:step:frame_max % 2012-07-27 LS: modified name for HK's images %Constructs file name --> meta vue default if i<10 name=[fname '000' int2str(i)]; else if i>9 & i<100 name=[fname '00' int2str(i)]; else if i> 99 & i<1000 name=[fname '0' int2str(i)]; else name=[fname int2str(i)]; end end end % loads image data=imread(name,'tiff'); % clips image using user defined rectangle: x=col, y=row data_crop=data(ymin:ymax,xmin:xmax); % calculates integrated intensity int((i - frame_min)/step+1)=sum(sum(data_crop)); % calculates dark background using the given ROI if bgr_roi_file~=0 back=mean(mean(data(bgrymin:bgrymax,bgrxmin:bgrxmax))); % subtracts background data2=imsubtract(data,back); data2_crop=data2(ymin:ymax,xmin:xmax); int_noback((i - frame_min)/step+1)=sum(sum(data2_crop)); end end % constructs time axis t=int_time*(frame_min-1:step:frame_max-1); % save intensity trajectory and time data %save([outdir '\' outfname '_int_traj_ROI-' int2str(ii) '.txt'],'int','-ascii') %save([outdir '\' outfname '_time_traj_ROI-' int2str(ii) '.txt'],'t','-ascii') save([outdir '\' outfname '_int-' int2str(ii) '.txt'],'int','-ascii') save([outdir '\' outfname '_time-' int2str(ii) '.txt'],'t','-ascii') if bgr_roi_file~=0 save([outdir '\' outfname '_int_noback_traj-' int2str(ii) '.txt'],'int_noback','-ascii') end % plot intensity trajectory over time figure(ii),plot(t,int,'b.','MarkerSize',16) if bgr_roi_file~=0 hold on % plot background subtracted intensity trajectory over time plot(t,int_noback,'r.','MarkerSize',16) legend('Raw','NoBack','Location','NorthWest') end xlabel('Time [s]') ylabel('Integrated Intensity [A.U.]') % save intensity trajectory plot %saveas(gca, [outdir '\' outfname '_int_traj_ROI-' int2str(ii) '_fig.tif'], 'tif') %saveas(gca, [outdir '\' outfname '_int_traj_ROI-' int2str(ii) '_fig.fig'], 'fig') saveas(gca, [outdir '\' outfname '_int-' int2str(ii) '_fig.tif'], 'tif') saveas(gca, [outdir '\' outfname '_int-' int2str(ii) '_fig.fig'], 'fig') t_HJ=t'; int_HJ=int'; Background_Intensity_Traj(:, 1) = t_HJ; Background_Intensity_Traj(:, 2) = int_HJ; % save time versus x trajectory %save([outdir '\' outfname '_Background_time_versus_intensity-' int2str(ii) '.txt'],'Background_Intensity_Traj','-ascii') save([outdir '\' outfname '_BG_t_vs_I-' int2str(ii) '.txt'],'Background_Intensity_Traj','-ascii') close all end