Skip to content

Commit

Permalink
Merge branch 'dev_newInfo' of https://github.com/wiggins-lab/SuperSegger
Browse files Browse the repository at this point in the history
 into dev_newInfo
  • Loading branch information
stellastyl committed Jul 1, 2016
2 parents 18c1e28 + 351a51d commit 43cacd7
Show file tree
Hide file tree
Showing 24 changed files with 1,861 additions and 546 deletions.
2 changes: 2 additions & 0 deletions Internal/ag.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

im = double(im);

im(isinf(im(:))) = nan;

if exist( 'imin', 'var') && ~isempty( imin )
im_min = imin;
else
Expand Down
35 changes: 35 additions & 0 deletions Internal/col.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [ v ] = col( v )
% row : makes v into a col vector.
% INPUT :
% v: array or row vector.
% OUTPUT :
% v: vector converted to row vector.
% Copyright (C) 2016 Wiggins Lab
% Written by Stella Stylianidou, Paul Wiggins.
% University of Washington, 2016
% This file is part of SuperSegger.
%
% SuperSegger is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% SuperSegger is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.

ss = size(v);

if ~any( ss==1 )
v = v(:);
elseif ss(1) == 1
v = v';
end

end


136 changes: 66 additions & 70 deletions batch/BatchSuperSeggerDebug.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SEG,showWarnings)
% BatchSuperSeggerDebug : same as BatchSuperSeggerOpti but without PARFOR making it possible to
% debug the program.
% BatchSuperSeggerOpti runs everything from start to finish,
function BatchSuperSeggerOpti(dirname_,skip,clean_flag,res,startEnd,showWarnings)
% BatchSuperSeggerOpti : runs everything from start to finish,
% including alignment, building the directory structure,
%single image segmentation, error resolution, cell linking,
% fluorescence analysis, and cell files.
Expand Down Expand Up @@ -31,16 +29,16 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
% : new segs if they don't yet exist.
% res : is a string that is passed to loadConstants(Mine).m to load
% : the right constants for processing.
% SEGMENT_FLAG : to segment cells
% ONLY_SEG : if true it does not run trackOpti (does only the segmentation)
% showWarnings : Set to 0 to mute warnings
%
% startEnd : array of two values to indicate where to start and where to
% stop the program. 1, alignment, 2, segmentation, 3, stripping, 4 linking,
% 5, cell marker, 6 : fluor, 7 : foci, 8, cellA structrues, 9, clist, 10 cell files.
%
% Copyright (C) 2016 Wiggins Lab
% Written by Paul Wiggins & Stella Stylianidou.
% University of Washington, 2016
% This file is part of SuperSegger.
%

% SuperSegger is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -74,12 +72,8 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
end


if ~exist( 'SEGMENT_FLAG', 'var' ) || isempty( SEGMENT_FLAG )
SEGMENT_FLAG = 1;
end

if ~exist( 'ONLY_SEG', 'var' ) || isempty( ONLY_SEG )
ONLY_SEG = 0;
if ~exist( 'startEnd', 'var' ) || isempty( startEnd )
startEnd = [1 20];
end

if ~exist( 'showWarnings', 'var' ) || isempty( showWarnings )
Expand All @@ -100,7 +94,7 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
end


if clean_flag && SEGMENT_FLAG && showWarnings
if clean_flag && showWarnings
try
disp ('Clean flag is set to true.')
answer=input('Do you want to continue, Y/N [Y]:','s');
Expand All @@ -114,46 +108,48 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
end

% align frames
if exist( dirname_, 'dir' )
if exist( [dirname_,filesep,'raw_im'] ,'dir') && ...
(numel(dir ([dirname_,filesep,'raw_im',filesep,'*.tif'])) || ...
exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file'))
disp('BatchSuperSeggerOpti : images already aligned');
if exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file')
tmp = load( [dirname_,filesep,'raw_im',filesep,'cropbox.mat'] );
crop_box_array = tmp.crop_box_array;
else
crop_box_array = cell(1,10000);
end
elseif numel(dir ([dirname_,filesep,'*.tif']))
% check naming convention
if ~isRightNameFormat(dirname_)
disp('Images in incorrect naming format. Using convertImageNames to convert names.')
convertImageNames(dirname_)
end

mkdir( [dirname_,filesep,'raw_im'] );
if CONST.align.ALIGN_FLAG
crop_box_array = trackOptiAlignPad( dirname_,...
CONST.parallel.parallel_pool_num, CONST);
movefile( [dirname_,filesep,'*.tif'], [dirname_,filesep,'raw_im'] ) % moves images to raw_im
movefile( [dirname_,'align',filesep,'*.tif'], [dirname_,filesep]); % moves aligned back to main folder
rmdir( [dirname_,'align'] ); % removes _align directory
else
crop_box_array = cell(1,10000);
end
if exist( dirname_, 'dir' )

if startEnd(1) >1 || exist( [dirname_,filesep,'raw_im'] ,'dir') && ...
(numel(dir ([dirname_,filesep,'raw_im',filesep,'*.tif'])) || ...
exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file'))
disp('BatchSuperSeggerOpti : images already aligned');
if exist([dirname_,filesep,'raw_im',filesep,'cropbox.mat'],'file')
tmp = load( [dirname_,filesep,'raw_im',filesep,'cropbox.mat'] );
crop_box_array = tmp.crop_box_array;
else
crop_box_array = cell(1,10000);
end
elseif numel(dir ([dirname_,filesep,'*.tif']))
% check naming convention
if ~isRightNameFormat(dirname_)
disp('Images in incorrect naming format. Using convertImageNames to convert names.')
convertImageNames(dirname_)
end

mkdir( [dirname_,filesep,'raw_im'] );
if CONST.align.ALIGN_FLAG
crop_box_array = trackOptiAlignPad( dirname_,...
CONST.parallel.parallel_pool_num, CONST);
movefile( [dirname_,filesep,'*.tif'], [dirname_,filesep,'raw_im'] ) % moves images to raw_im
movefile( [dirname_,'align',filesep,'*.tif'], [dirname_,filesep]); % moves aligned back to main folder
rmdir( [dirname_,'align'] ); % removes _align directory
else
crop_box_array = cell(1,10000);
end
else
error('No images found');
end

else
error(['BatchSuperSeggerOpti : Can''t find directory ''',dirname_,'''. Exiting.'] );
end


% setups the dir structure for analysis.
trackOptiPD(dirname_, CONST);
save([dirname_,'CONST.mat'],'-STRUCT', 'CONST' ); % Saves CONST set you used.
save([dirname_,'raw_im',filesep,'cropbox.mat'], 'crop_box_array' );
save( [dirname_,'CONST.mat'],'-STRUCT', 'CONST' ); % Saves CONST set you used.
save( [dirname_,'raw_im',filesep,'cropbox.mat'], 'crop_box_array' );

% Loop through xy directories
% Reset n values in case directories have already been made.
Expand Down Expand Up @@ -202,22 +198,25 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
h = [];
else
h = waitbar( 0, ['Data segmentation xy: 0/',num2str(num_xy)] );
cleanup = onCleanup( @()( delete( h ) ) );
end

for j = 1:num_xy
% parfor(j = 1:num_xy,workers)
for j = 1:num_xy

dirname_xy = dirname_list{j};
intProcessXY( dirname_xy, skip, nc, num_c, clean_flag, ...
CONST, SEGMENT_FLAG, crop_box_array{j}, ONLY_SEG)
CONST, startEnd, crop_box_array{j})

if workers || ~CONST.parallel.show_status
disp( ['BatchSuperSeggerOpti: No status bar. xy ',num2str(j), ...
' of ', num2str(num_xy),'.']);
else
waitbar( j/num_xy,h,...
['Data segmentation xy: ',num2str(j),...
'/',num2str(num_xy)]);
if isvalid(h)
waitbar( j/num_xy,h,...
['Data segmentation xy: ',num2str(j),...
'/',num2str(num_xy)]);
end
end
end

Expand All @@ -237,10 +236,10 @@ function BatchSuperSeggerDebug(dirname_,skip,clean_flag,res,SEGMENT_FLAG,ONLY_SE
end

function intProcessXY( dirname_xy, skip, nc, num_c, clean_flag, ...
CONST, SEGMENT_FLAG, crop_box, ONLY_SEG)
CONST, startEnd, crop_box)
% intProcessXY : the details of running the code in parallel.
% Essentially for parallel processing to work, you have to hand each
% processor all the information it needs to process the images..
% processor all the information it needs to process the images.

% Initialization
file_filter = '*.tif';
Expand Down Expand Up @@ -289,22 +288,23 @@ function intProcessXY( dirname_xy, skip, nc, num_c, clean_flag, ...
end

if ~CONST.parallel.show_status
h_frame = [];
h = [];
else
h_frame = waitbar( 0, ['BatchSuperSeggerOpti : Frame 0/',num2str(num_t)] );
h = waitbar( 0, ['BatchSuperSeggerOpti : Frame 0/',num2str(num_t)] );
cleanup = onCleanup( @()( delete( h ) ) );
end

stamp_name = [dirname_xy,'seg',filesep,'.doSegFull'];

if clean_flag && exist(stamp_name,'file')
delete(stamp_name)
if clean_flag
cleanSuperSegger (dirname_xy, startEnd, skip)
end


% does the segmentations for all the frames in parallel
if SEGMENT_FLAG && ~exist( stamp_name, 'file' )
if startEnd(1) <= 2 && startEnd(2) >=2 && ~exist( stamp_name, 'file' )
%parfor(i=1:num_t,workers) % through all frames
for i = 1:num_t
for i = 1:num_t

if isempty( crop_box )
crop_box_tmp = [];
Expand All @@ -313,34 +313,30 @@ function intProcessXY( dirname_xy, skip, nc, num_c, clean_flag, ...
end

doSeg(i, nameInfo, nc, nz, nt, num_z, num_c, dirname_xy, ...
clean_flag, skip, CONST, [header,'t',num2str(i),': '], crop_box_tmp);
skip, CONST, [header,'t',num2str(i),': '], crop_box_tmp);

if ~CONST.parallel.show_status
if verbose
disp( [header, 'BatchSuperSeggerOpti : Segment. Frame ',num2str(i), ...
' of ', num2str(num_t),'.']);
end
else
if isvalid(h_frame)
set(0, 'CurrentFigure', h_frame);
waitbar( i/num_t, h_frame,['Data segmentation t: ',num2str(i),'/',num2str(num_t)]);
end
waitbar( i/num_t, h,...
['Data segmentation t: ',num2str(i),'/',num2str(num_t)]);
end
end
time_stamp = clock; %#ok saved below
save( stamp_name, 'time_stamp'); % saves that xydir was full segmented
end
if CONST.parallel.show_status
if isvalid(h_frame)
close(h_frame);
if isvalid(h)
close(h);
end
end

% trackOpti has all the rest of things : Linking, Cell files, Fluorescence calculation etc
if ~ONLY_SEG
trackOpti(dirname_xy,skip,CONST, clean_flag, header);
else
disp ('Only segmentation was set to true - Linking and cell files were not made');
if startEnd(2) >2
trackOpti(dirname_xy,skip,CONST, header, startEnd);
end
end

Loading

0 comments on commit 43cacd7

Please sign in to comment.