diff --git a/Cytoo/colonyColorPointPlot.m b/Cytoo/colonyColorPointPlot.m index 5897a72..0ac31b8 100644 --- a/Cytoo/colonyColorPointPlot.m +++ b/Cytoo/colonyColorPointPlot.m @@ -1,4 +1,4 @@ -function colonyColorPointPlot(col,dcols,ps,climits,newfig,rescale_fac,centerpos) +function colonyColorPointPlot(col,dcols,ps,climits,newfig,rescale_fac,centerpos,dofilter) %function colonyColorPointPlot(col,dcols) %--------------------------------------- %Colony scatter plot with points colored by data @@ -7,6 +7,7 @@ function colonyColorPointPlot(col,dcols,ps,climits,newfig,rescale_fac,centerpos) % if length==2, use 2nd one for norm %ps = pointsize (default 12); + xdat=col.data(:,1); ydat=col.data(:,2); @@ -37,8 +38,12 @@ function colonyColorPointPlot(col,dcols,ps,climits,newfig,rescale_fac,centerpos) centerpos=1; end +if ~exist('dofilter','var') + dofilter=1; +end + if newfig -figure; + figure; end if centerpos @@ -46,12 +51,16 @@ function colonyColorPointPlot(col,dcols,ps,climits,newfig,rescale_fac,centerpos) ydat=bsxfun(@minus,ydat,mean(ydat)); end -includeinds=sqrt(xdat.*xdat+ydat.*ydat) < 30*50+5; +if dofilter + includeinds=sqrt(xdat.*xdat+ydat.*ydat) < 30*50+5; +else + includeinds=1:length(xdat); +end xdat=xdat(includeinds); ydat=ydat(includeinds); coldat=coldat(includeinds); colormap('jet'); -scatter(rescale_fac*xdat,rescale_fac*ydat,ps,coldat); +scatter(rescale_fac*xdat,rescale_fac*ydat,ps,coldat,'filled'); minx=min(xdat); maxx=max(xdat); miny=min(ydat); maxy=max(ydat); diff --git a/Cytoo/getDimsFromLogFile.m b/Cytoo/getDimsFromLogFile.m new file mode 100644 index 0000000..cd9b2c6 --- /dev/null +++ b/Cytoo/getDimsFromLogFile.m @@ -0,0 +1,82 @@ +function [dims, wavenames]=getDimsFromLogFile(direc) +%[dims wavenames]=getDimsFromLogFile(direc) +%----------------------------------------------- +%Function to find dimensions of the tiling and +%the names of the wavelengths from the .dv.log file outputted by +%deltavision +%direc = output directory containing the .dv.log file +% assumes only one .dv.log file in that directory. +%dims = 2 component vector containing dimension +%wavenames = cell array containing wavelength names + +verbose = 0; + +fnames=dir([direc filesep '*log']); +scanfile=[direc filesep fnames(1).name]; +ff=fopen(scanfile); + +strtofind1='DO '; +strtofind2='CHANNEL'; +strtofind3='Stage coordinates:'; +strtofind4='Image '; + +tline=fgetl(ff); +q=1; +Y=1; + +while ischar(tline) + + k1=strfind(tline,strtofind1); + k2=strfind(tline,strtofind2); + k4=strfind(tline,strtofind3); + n=strfind(tline,strtofind4); + + if k1 + if verbose + disp(tline); + end + panels=str2double(tline(k1+3:end)); + end + + if k2 + if verbose + disp(tline); + end + + k3=strfind(tline,','); + wavenames{q}=tline(k3(1)+1:k3(2)-1); + q=q+1; + end + + if n + n1=strfind(tline,'.'); + imageNum=str2double(tline(n+6:n1-1)); + end + + if k4 + if verbose + disp(tline); + end + + k5=strfind(tline,','); + y=str2double(tline(k5(1)+1:k5(2)-1)); + + if Y==1 + y1=y; + Y=2; + end + + if Y==2 && y~=y1 + cols = (imageNum-1)./length(wavenames); + Y=3; + end + + end + + tline=fgetl(ff); + +end + +rows = floor(panels./cols); + +dims = [rows,cols]; diff --git a/Cytoo/mkFullCytooPlotPeaks.m b/Cytoo/mkFullCytooPlotPeaks.m index 49d49ff..7b2bc5d 100644 --- a/Cytoo/mkFullCytooPlotPeaks.m +++ b/Cytoo/mkFullCytooPlotPeaks.m @@ -13,25 +13,41 @@ pp=load(matfile); peaks=pp.peaks; ac=pp.acoords; +col=pp.plate1.colonies; + +totcells = 0; +for ii=1:length(peaks) + totcells=totcells+size(peaks{ii},1); +end + +ncolumn=size(col(1).data,2); +alldat=zeros(totcells,ncolumn); + + cc=colorcube(19); figure; hold on; +q=1; + for ii=1:length(peaks) if ~isempty(peaks{ii}) - toadd=[ac(ii).absinds(2) ac(ii).absinds(1)]; - %toadd=[0 0]; - dtoplot=bsxfun(@plus,peaks{ii}(:,1:2),toadd); - if returndat - alldat(q:(q+col(ii).ncells-1),:)=[dtoplot col(ii).data(:,3:end)]; - q=q+col(ii).ncells; - end - plot(dtoplot(:,2),dtoplot(:,1),'.','Color',cc(mod(ii,19)+1,:)); -% txtcolor=cc(mod(ii+10,19)+1,:); -% cen=[col(ii).center(2)+toadd(2) col(ii).center(1)+toadd(1)]; -% if printnum && col(ii).ncells > 200 -% text(cen(1),cen(2),int2str(ii),'Color','m'); -% end - %disp(int2str(ii)); + toadd=[ac(ii).absinds(2) ac(ii).absinds(1)]; + %toadd=[0 0]; + dtoplot=bsxfun(@plus,peaks{ii}(:,1:2),toadd); + if returndat + alldat(q:(q+size(peaks{ii},1)-1),:)=[dtoplot peaks{ii}(:,3:end)]; + q=q+size(peaks{ii},1); + + end + + text(mean(dtoplot(:,2)),mean(dtoplot(:,1)),int2str(ii),'Color','k'); + plot(dtoplot(:,2),dtoplot(:,1),'.','Color',cc(mod(ii,19)+1,:)); + % txtcolor=cc(mod(ii+10,19)+1,:); + % cen=[col(ii).center(2)+toadd(2) col(ii).center(1)+toadd(1)]; + % if printnum && col(ii).ncells > 200 + % text(cen(1),cen(2),int2str(ii),'Color','m'); + % end + %disp(int2str(ii)); end end diff --git a/Cytoo/peaksToColonies.m b/Cytoo/peaksToColonies.m index 4320c35..1f42996 100644 --- a/Cytoo/peaksToColonies.m +++ b/Cytoo/peaksToColonies.m @@ -1,9 +1,10 @@ -function [colonies peaks]=peaksToColonies(matfile) +function [colonies, peaks]=peaksToColonies(matfile) -pp=load(matfile,'peaks','acoords','imgfiles','dims'); +pp=load(matfile,'peaks','acoords','imgfiles','dims','si'); peaks=pp.peaks; ac=pp.acoords; dims=pp.dims; +si=pp.si; peaks=removeDuplicateCells(peaks,ac); @@ -40,7 +41,7 @@ %Make colony structure for ii=1:length(groups) cellstouse=allinds==ii; - colonies(ii)=colony(alldat(cellstouse,:),ac,dims,[],pp.imgfiles); + colonies(ii)=colony(alldat(cellstouse,:),ac,dims,si,pp.imgfiles); end %put data back into peaks diff --git a/runFiles/runDeltaVisionTile.m b/runFiles/runDeltaVisionTile.m new file mode 100644 index 0000000..5981e48 --- /dev/null +++ b/runFiles/runDeltaVisionTile.m @@ -0,0 +1,136 @@ +function runDeltaVisionTile(direc,outfile,paramfile,step,tiffs,prefix) +%runDeltaVisionTile(direc,outfile,paramfile,step,tiffs,prefix) +%--------------------- +%Version of runFullTile for DeltaVision (.dv) files +%Requries MATLAB Bio-Formats files +%Run from directory containing .dv.log file +%For a set of tiled images, runs segmentCells (uses parfor for this), runs +%alignment program for images, outputs in matfile -- peaks -- cell by cells +%list by image, colonies -- colonies data structure +%direc -- image directory +%prefix -- prefix for TIFF images +%outfile -- matfile for output +%step = step to begin at. See code. allows for skipping finding cells etc. +%tiffs = 1 (0) means extract tiff images and save to direc (0 to skip, +%default = 1) + +if ~exist('tiffs','var') + tiffs = 1; +end + +if ~exist('step','var') + step=1; +end + +if ~exist('paramfile','var') + paramfile='setUserParamSC20xIFEDS'; +end + +reader=bfGetReader('path/to/data/file'); +omeMeta=reader.getMetadataStore(); +numChans=omeMeta.getChannelCount(0); +[dims, wavenames]=getDimsFromLogFile('.'); + +for ii = 1:numChans + chanstemp{ii}=['w' char(omeMeta.getChannelEmissionWavelength(0,ii-1))]; +end + +if tiffs == 1 + dvToTiffs(direc,prefix,chanstemp,reader,dims) +end + +chans=orderchans(chanstemp,wavenames); + +ff=folderFilesFromKeyword(direc,chans{1}); +maxims=ff(end-1); + +nloop=12; +imgsperprocessor=ceil(maxims/12); +%generate background image for each channel +if step < 2 + for ii=1:length(chans) + [minI meanI]=mkBackgroundImage(direc,chans{ii},min(500,maxims)); + bIms{ii}=uint16(2^16*minI); + normIm=(meanI-minI); + normIm=normIm.^-1; + normIm=normIm/min(min(normIm)); + nIms{ii}=normIm; + end + + si=size(bIms{1}); + save([direc filesep outfile],'bIms','nIms','dims','si'); +end +%runTileLoop--runs segmentCells in parfor loop, +%send imgsperprocessor to each, nloop = total number necessary +%Assemble Mat Files--puts together matfiles, all data stored as peaks in +%outfile +if step < 3 + load([direc filesep outfile],'bIms','nIms'); + runTileLoop(direc,chans,imgsperprocessor,nloop,maxims,bIms,nIms,paramfile); +end + +%performs a series of pairwise alignments, +%each img is aligned img on top and to the left, pixel overlap +%stored in accords, can also return fully aligned image, but not +%recommended for large numbers of files. +if step < 4 + [acoords]=alignManyPanels(direc,chans{1},1,4,dims,85:150,maxims); + save([direc filesep outfile],'acoords','-append'); +end + +if step < 5 + assembleMatFiles(direc,imgsperprocessor,nloop,outfile); +end +%peaksToColonies generates the colony structure from peaks and accords +%computes alpha volume and then finds all connected components. +if step < 6 + load([direc filesep outfile],'bIms','nIms'); + [colonies, peaks]=peaksToColonies([direc filesep outfile]); + plate1=plate(colonies,dims,direc,chans,bIms,nIms); + save([direc filesep outfile],'plate1','peaks','-append'); +end + +function chans=orderchans(chanstemp,wavenames,nucname) + +if ~exist('nucname','var') + nucname='DAPI'; +end + +kk=strfind(wavenames,nucname); +ii=~cellfun(@isempty,kk); +nuc_ind=find(ii); + +allchans=1:length(wavenames); +nonnucchans=setdiff(allchans,nuc_ind); +chans{1}=chanstemp{nuc_ind}; +for jj=1:length(nonnucchans) + chans{jj+1}=chanstemp{nonnucchans(jj)}; +end + +function dvToTiffs(direc,prefix,chans,reader,dims) + +if ~exist(direc,'file') + mkdir(direc); +end + +for kk=1:length(chans) + for ii=1:dims(1) + for jj=1:dims(2) + if ~mod(ii,2) %even + oldnum=(ii-1)*dims(2)+dims(2)-jj+1; + else + oldnum=(ii-1)*dims(2)+jj; + end + + newnum=(jj-1)*dims(1)+ii; + + reader.setSeries(oldnum-1); + + series_plane = bfGetPlane(reader, kk); + + %t1=imread(fnames(rr==oldnum).name); + newname= [direc filesep prefix '_' chans{kk} '_s' int2str(newnum) '_t1.TIF']; + imwrite(series_plane,newname); + end + end +end diff --git a/runFiles/runFullTile.m b/runFiles/runFullTile.m index 1f0d0ea..2dcde4e 100644 --- a/runFiles/runFullTile.m +++ b/runFiles/runFullTile.m @@ -34,7 +34,8 @@ function runFullTile(direc,outfile,paramfile,step) normIm=normIm/min(min(normIm)); nIms{ii}=normIm; end - save([direc filesep outfile],'bIms','nIms','dims'); + si=size(bIms{1}); + save([direc filesep outfile],'bIms','nIms','dims','si'); end %runTileLoop--runs segmentCells in parfor loop, %send imgsperprocessor to each, nloop = total number necessary