Home > SuperSegger > viz > superSeggerViewerGui.m

superSeggerViewerGui

PURPOSE ^

superSeggerViewerGui : gui used to visualize the results of segmentation

SYNOPSIS ^

function varargout = superSeggerViewerGui(varargin)

DESCRIPTION ^

 superSeggerViewerGui : gui used to visualize the results of segmentation
 and use the superSegger analysis tools.

 Copyright (C) 2016 Wiggins Lab
 Written by Silas Boye Nissen, Connor Brennan, 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
 (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/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = superSeggerViewerGui(varargin)
0002 % superSeggerViewerGui : gui used to visualize the results of segmentation
0003 % and use the superSegger analysis tools.
0004 %
0005 % Copyright (C) 2016 Wiggins Lab
0006 % Written by Silas Boye Nissen, Connor Brennan, Stella Stylianidou.
0007 % University of Washington, 2016
0008 % This file is part of SuperSegger.
0009 %
0010 % SuperSegger is free software: you can redistribute it and/or modify
0011 % it under the terms of the GNU General Public License as published by
0012 % the Free Software Foundation, either version 3 of the License, or
0013 % (at your option) any later version.
0014 %
0015 % SuperSegger is distributed in the hope that it will be useful,
0016 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018 % GNU General Public License for more details.
0019 %
0020 % You should have received a copy of the GNU General Public License
0021 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0022 
0023 gui_Singleton = 1;
0024 gui_State = struct('gui_Name',       mfilename, ...
0025     'gui_Singleton',  gui_Singleton, ...
0026     'gui_OpeningFcn', @superSeggerViewerGui_OpeningFcn, ...
0027     'gui_OutputFcn',  @superSeggerViewerGui_OutputFcn, ...
0028     'gui_LayoutFcn',  [] , ...
0029     'gui_Callback',   []);
0030 if nargin && ischar(varargin{1})
0031     gui_State.gui_Callback = str2func(varargin{1});
0032 end
0033 if nargout
0034     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0035 else
0036     
0037     gui_mainfcn(gui_State, varargin{:});
0038 end
0039 
0040 function disable_all_panels (hObject,handles)
0041 set(findall(handles.gate_options_text, '-property', 'enable'), 'enable', 'off')
0042 set(findall(handles.output_options_text, '-property', 'enable'), 'enable', 'off')
0043 set(findall(handles.display_options_text, '-property', 'enable'), 'enable', 'off')
0044 set(findall(handles.link_options_text, '-property', 'enable'), 'enable', 'off')
0045 
0046 handles.go_to_frame_no.Enable = 'off';
0047 handles.previous.Enable = 'off';
0048 handles.next.Enable = 'off';
0049 handles.switch_xy_directory.Enable = 'off';
0050 handles.max_cell_no.Enable = 'off';
0051 handles.edit_segments.Enable = 'off';
0052 
0053 function enable_all_panels (hObject,handles)
0054 set(findall(handles.gate_options_text, '-property', 'enable'), 'enable', 'on')
0055 set(findall(handles.output_options_text, '-property', 'enable'), 'enable', 'on')
0056 set(findall(handles.display_options_text, '-property', 'enable'), 'enable', 'on')
0057 set(findall(handles.link_options_text, '-property', 'enable'), 'enable', 'on')
0058 
0059 handles.go_to_frame_no.Enable = 'on';
0060 handles.previous.Enable = 'on';
0061 handles.next.Enable = 'on';
0062 handles.switch_xy_directory.Enable = 'on';
0063 handles.max_cell_no.Enable = 'on';
0064 handles.edit_segments.Enable = 'on';
0065 
0066 
0067 function update_clist_panel(hObject, handles)
0068 if isempty(handles.clist)
0069     set(findall(handles.gate_options_text, '-property', 'enable'), 'enable', 'off')
0070     handles.clist_text.String = 'No clist loaded, these commands will not work';
0071     
0072 else
0073     handles.clist_text.String = ['Clist: ' handles.contents_xy(handles.dirnum).name,filesep,'clist.mat'];
0074     set(findall(handles.gate_options_text, '-property', 'enable'), 'enable', 'on')
0075     handles.make_gate.String = handles.clist.def';
0076     handles.histogram_clist.String = handles.clist.def';
0077     if isfield(handles.clist,'def3d')
0078         handles.time_clist.String = handles.clist.def3d';
0079     end
0080      if isfield(handles.clist,'def3D')
0081         handles.time_clist.String = handles.clist.def3D';
0082     end
0083     if isfield(handles.clist,'idExclude')
0084         handles.exclude_ids.String = num2str(handles.clist.idExclude);
0085     else
0086         handles.exclude_ids.String = '';
0087     end
0088     if isfield(handles.clist,'idInclude')
0089         handles.include_ids.String = num2str(handles.clist.idInclude);
0090     else
0091         handles.include_ids.String = '';
0092     end
0093 end
0094 guidata(hObject, handles);
0095 
0096 function handles = updateOutputPanel (handles)
0097 
0098 output_options = list_output_strings ();
0099 names = output_options(:,1);
0100 needCellFiles = find([output_options{:,2}]);
0101 needClist = find([output_options{:,3}]);
0102 cellFilesFound = areCellsLoaded(handles);
0103 stringList = [];
0104 counter = 0;
0105 for i = 1 : numel(names)
0106     if any(needClist == i) && isempty(handles.clist)
0107         % skip
0108     elseif any(needCellFiles == i) && ~cellFilesFound
0109         % skip
0110     else
0111         counter = counter + 1;
0112         stringList {counter} = names{i};
0113     end
0114 end
0115 handles.output_list.String = stringList;
0116 handles.output_list.Value = 1;
0117 
0118 
0119 function initImage(hObject, handles) % Not updated
0120 global dataImArray;
0121 % initialize
0122 guidata(hObject, handles);
0123 enable_all_panels(hObject,handles)
0124 handles.FLAGS = [];
0125 handles.dirnum = [];
0126 handles.dirSave = [];
0127 handles.dirname0 = [];
0128 handles.contents_xy = [];
0129 handles.clist = [];
0130 handles.num_xy = 0;
0131 handles.num_errs = 0;
0132 handles.canUseErr = 0;
0133 
0134 
0135 if (nargin<1 || isempty(handles.image_directory.String))
0136     handles.image_directory.String = pwd;
0137 end
0138 dirname = handles.image_directory.String;
0139 
0140 % Ends in xy directory
0141 index = regexp(dirname, [filesep, 'xy.[', filesep, ']*$']);
0142 if index > 0
0143     dirname = dirname(1:index - 1);
0144 end
0145 
0146 handles.image_directory.String = dirname;
0147 
0148 file_filter = '';
0149 CONST = [];
0150 axis tight
0151 cla;
0152 
0153 dirname = fixDir(dirname);
0154 dirname0 = dirname;
0155 dirSave = [dirname, 'superSeggerViewer', filesep];
0156 
0157 % flags
0158 filename_flags = [dirname0,'.superSeggerViewer.mat'];
0159 FLAGS = [];
0160 if exist( filename_flags, 'file' )
0161     load(filename_flags);
0162     FLAGS = fixFlags(FLAGS);
0163 else
0164     FLAGS = fixFlags(FLAGS);
0165     dirnum = 1;
0166 end
0167 
0168 contents_xy = dir([dirname, 'xy*']);
0169 handles.num_xy = numel(contents_xy);
0170 direct_contents_seg = dir([dirname, '*seg.mat']);
0171 direct_contents_err = dir([dirname, '*err.mat']);
0172 
0173 if dirnum > handles.num_xy
0174     dirnum = 1;
0175 end
0176 
0177 if handles.num_xy~=0
0178     if isdir([dirname0,contents_xy(dirnum).name,filesep,'seg_full'])
0179         handles.dirname_seg = [dirname0,contents_xy(dirnum).name,filesep,'seg_full',filesep];
0180     else
0181         handles.dirname_seg = [dirname0,contents_xy(dirnum).name,filesep,'seg',filesep];
0182     end
0183     handles.dirname_cell = [dirname0, contents_xy(dirnum).name, filesep, 'cell', filesep];
0184     clist_name = [dirname0, contents_xy(dirnum).name, filesep, 'clist.mat'];
0185     if exist( clist_name, 'file' )
0186         handles.clist = load([dirname0,contents_xy(dirnum).name,filesep,'clist.mat']);
0187     else
0188         handles.clist = [];
0189     end
0190 else
0191     
0192     
0193     if numel(direct_contents_err) == 0 &&  numel(direct_contents_seg) == 0   % no images found abort.
0194         cla(handles.axes1)
0195         
0196         if numel(dir([dirname, '*.tif'])) > 0
0197             handles.message.String = ['Directory does not contain segmented data. Please use superSeggerGui to segment your data.'];
0198         else
0199             handles.message.String = ['There are no xy dirs. Choose a different directory.'];
0200         end
0201         disable_all_panels(hObject,handles);
0202         
0203         return;
0204     else % loading from the seg directory directly
0205         handles.dirname_cell = dirname;
0206         handles.dirname_seg  = dirname;
0207         dirnum = 1;
0208         if numel(direct_contents_err) == 0
0209             handles.use_seg_files.Value = 1;
0210         end
0211     end
0212 end
0213 
0214 if nargin<2 || isempty(file_filter);
0215     if numel(dir([handles.dirname_seg,filesep,'*err.mat']))~=0
0216         file_filter = '*err.mat';
0217     else
0218         file_filter = '*seg.mat';
0219     end
0220 end
0221 
0222 if ~exist(dirSave, 'dir')
0223     try
0224         mkdir(dirSave);
0225     catch
0226     end
0227 else
0228     if exist([dirSave, 'dataImArray.mat'], 'file')
0229         load([dirSave, 'dataImArray'],'dataImArray');
0230         
0231     end
0232 end
0233 
0234 
0235 % flags and checkboxes are initialized here
0236 FLAGS.cell_flag = 1; %This is handled by useSegs now
0237 handles.channel.String = num2str(FLAGS.f_flag);
0238 handles.cell_numbers.Value = FLAGS.ID_flag;
0239 handles.cell_poles.Value = FLAGS.p_flag;
0240 handles.legend_box.Value = FLAGS.legend;
0241 handles.outline_cells.Value = FLAGS.Outline_flag;
0242 handles.fluor_foci_scores.Value = FLAGS.s_flag;
0243 handles.filtered_fluorescence.Value = FLAGS.filt;
0244 handles.region_outlines.Value = FLAGS.P_flag;
0245 handles.region_scores.Value = FLAGS.regionScores;
0246 handles.use_seg_files.Value = FLAGS.useSegs;
0247 handles.show_daughters.Value = FLAGS.showDaughters;
0248 handles.show_mothers.Value = FLAGS.showMothers;
0249 handles.show_linking.Value = FLAGS.showLinks;
0250 handles.phase_flag.Value = FLAGS.phase_flag;
0251 handles.phase_level_txt.String = num2str(FLAGS.phase_level);
0252 handles.composite.Value = FLAGS.composite;
0253 if exist('nn','var');
0254     handles.go_to_frame_no.String = num2str(nn);
0255 else
0256     handles.go_to_frame_no.String = '1';
0257 end
0258 
0259 handles.kymograph_cell_no.String = '';
0260 handles.movie_cell_no.String = '';
0261 handles.cell_no.String = '';
0262 handles.max_cell_no.String = '';
0263 handles.find_cell_no.String = '';
0264 
0265 handles.contents = dir([handles.dirname_seg, file_filter]);
0266 handles.contents_seg = dir([handles.dirname_seg, '*seg.mat']);
0267 handles.num_seg = length(handles.contents_seg);
0268 handles.num_err = length(handles.contents);
0269 if handles.num_seg >= handles.num_err
0270     handles.num_im  = handles.num_seg;
0271 else
0272     handles.num_im  = handles.num_err;
0273 end
0274 
0275 
0276 handles.use_seg_files.Value = FLAGS.useSegs;
0277 
0278 if exist([dirname0, 'CONST.mat'], 'file')
0279     CONST = load([dirname0, 'CONST.mat']);
0280     if isfield(CONST, 'CONST')
0281         CONST = CONST.CONST;
0282     end
0283 end
0284 handles.CONST = CONST;
0285 handles.FLAGS = FLAGS;
0286 handles.dirnum = dirnum;
0287 handles.dirSave = dirSave;
0288 handles.dirname0 = dirname0;
0289 handles.contents_xy = contents_xy;
0290 handles.filename_flags = filename_flags;
0291 handles.FLAGS.f_flag = 0;
0292 handles.channel.String = 0;
0293 handles.go_to_frame_no_text.String = ['Go to frame # (max ' num2str(handles.num_im) ')'];
0294 update_clist_panel(hObject, handles)
0295 handles = updateOutputPanel (handles);
0296 handles = updateImage(hObject, handles);
0297 guidata(hObject, handles);
0298 
0299 function handles = updateImage(hObject, handles)
0300 delete(get(handles.axes1, 'Children'))
0301 handles.previous.Enable = 'off';
0302 handles.next.Enable = 'off';
0303 if handles.num_im == 0
0304     cla(handles.axes1)
0305     handles.message.String = ['No images/seg/err files found in xy1.'];
0306     disable_all_panels(hObject,handles);
0307     handles.switch_xy_directory.Enable = 'on';
0308 else
0309     if ~isempty(handles.FLAGS)
0310         FLAGS = handles.FLAGS;
0311         dirnum = handles.dirnum;
0312         handles.message.String = '';
0313         nn = str2double(handles.go_to_frame_no.String);
0314         if nn > 1
0315             handles.previous.Enable = 'on';
0316         end
0317         if nn < handles.num_im
0318             handles.next.Enable = 'on';
0319         end
0320         if  ~isempty(handles.clist) && ~isempty(handles.clist.gate)
0321             handles.gate_text.String = 'Gates:';
0322             num_cell_gates = numel(handles.clist.gate);
0323             for i=1:num_cell_gates
0324                 handles.gate_text.String = strcat(handles.gate_text.String, '[',[num2str(handles.clist.gate(i).ind) ']']);
0325             end
0326         else
0327             handles.gate_text.String = '';
0328         end
0329         handles.err_seg.String = ['No. of err. files: ' num2str(length(dir([handles.dirname_seg, '*err.mat']))) char(10) 'No. of seg. files: ' num2str(length(dir([handles.dirname_seg, '*seg.mat'])))];
0330         handles.num_errs = length(dir([handles.dirname_seg, '*err.mat']));
0331         %Use region IDs if cells IDs unavailable
0332         if nn > handles.num_errs || FLAGS.useSegs
0333             handles.canUseErr = 0;
0334             handles.contents=dir([handles.dirname_seg, '*seg.mat']);
0335         else
0336             handles.canUseErr = 1;
0337             handles.contents=dir([handles.dirname_seg, '*err.mat']);
0338         end
0339         %Force flags to required values when data is unavailable
0340         forcedFlags = FLAGS;
0341         forcedFlags.cell_flag = forcedFlags.cell_flag & shouldUseErrorFiles(FLAGS, handles.canUseErr);
0342         %Force cell flag to 0 when err files not present
0343         delete(findall(findall(gcf, 'Type', 'axe'), 'Type', 'text'))
0344         [handles.data_r, handles.data_c, handles.data_f] = intLoadDataViewer(handles.dirname_seg, handles.contents, ...
0345             nn, handles.num_im, handles.clist, forcedFlags);
0346         showSeggerImage(handles.data_c, handles.data_r, handles.data_f, forcedFlags, handles.clist, handles.CONST, handles.axes1);
0347         try
0348             save(handles.filename_flags, 'FLAGS', 'nn', 'dirnum' );
0349         catch
0350         end
0351         
0352     end
0353     
0354     if handles.num_errs == 0
0355         handles.use_seg_files.Value = 1;
0356         makeInactive(handles.use_seg_files);
0357     else
0358         makeActive(handles.use_seg_files);
0359     end
0360     
0361     if handles.num_seg  == 0
0362         handles.use_seg_files.Enable = 'off';
0363     end
0364     
0365     handles.switch_xy_directory_text.String = ['Switch xy (', num2str(handles.num_xy), ')'];
0366     f = 0;
0367     while true
0368         if isfield(handles,'data_c') && isfield(handles.data_c, ['fluor' num2str(f+1)] )
0369             f = f+1;
0370         else
0371             break
0372         end
0373     end
0374     handles.channel_text.String = ['Channel (', num2str(f), ')'];
0375     if handles.FLAGS.f_flag >= 1 && ~handles.FLAGS.composite% Fluorescence
0376         makeActive(handles.log_view);
0377         makeActive(handles.false_color);
0378         if shouldUseErrorFiles(handles.FLAGS, handles.canUseErr)
0379             makeActive(handles.fluor_foci_scores);
0380             makeActive(handles.filtered_fluorescence);
0381         else
0382             makeInactive(handles.fluor_foci_scores);
0383             makeInactive(handles.filtered_fluorescence);
0384         end
0385     else
0386         makeInactive(handles.log_view);
0387         makeInactive(handles.fluor_foci_scores);
0388         makeInactive(handles.filtered_fluorescence);
0389         makeInactive(handles.false_color);
0390     end
0391     if shouldUseErrorFiles(handles.FLAGS, handles.canUseErr)
0392         makeActive(handles.cell_poles);
0393         makeActive(handles.complete_cell_cycles);
0394         if handles.FLAGS.showLinks
0395             makeActive(handles.show_daughters);
0396             makeActive(handles.show_mothers);
0397         else
0398             makeInactive(handles.show_daughters);
0399             makeInactive(handles.show_mothers);
0400         end
0401         makeActive(handles.show_linking);
0402     else
0403         makeInactive(handles.cell_poles);
0404         makeInactive(handles.complete_cell_cycles);
0405         makeInactive(handles.show_daughters);
0406         makeInactive(handles.show_mothers);
0407         makeInactive(handles.show_linking);
0408     end
0409     if handles.FLAGS.ID_flag
0410         handles.region_ids.Enable = 'on';
0411     else
0412         handles.region_ids.Enable = 'off';
0413     end
0414 end
0415 guidata(hObject, handles);
0416 
0417 function save_figure_ClickedCallback(hObject, eventdata, handles)
0418 [filename, pathName] = uiputfile('image.fig', 'Save current image', handles.dirSave);
0419 if ~isempty(strfind(filename, '.'))
0420     filename = filename(1:(max(strfind(filename, '.')) - 1));
0421 end
0422 if filename ~= 0
0423     fh = figure('visible', 'off');
0424     copyobj(handles.axes1, fh);
0425     savename = sprintf('%s/%s',pathName,filename);
0426     print(fh,'-depsc',[(savename),'.eps'])
0427     saveas(fh,[(savename),'.png'],'png');
0428     handles.message.String = ['Figure is saved in eps and png format at ',savename];
0429     close(fh);
0430 end
0431 
0432 
0433 function select_image_directory_ClickedCallback(hObject, eventdata, handles)
0434 folderName = uigetdir;
0435 if folderName ~= 0
0436     handles.image_directory.String = folderName;
0437     initImage(hObject, handles);
0438     
0439 end
0440 
0441 function varargout = superSeggerViewerGui_OutputFcn(hObject, eventdata, handles)
0442 
0443 function superSeggerViewerGui_OpeningFcn(hObject, eventdata, handles, varargin)
0444 if getappdata(0, 'dirname')
0445     handles.image_directory.String = getappdata(0, 'dirname');
0446     rmappdata(0,'dirname')
0447 else
0448     handles.image_directory.String = pwd;
0449 end
0450 set(handles.figure1, 'units', 'normalized', 'position', [0 0 1 1])
0451 initImage(hObject, handles);
0452 
0453 % Main menu
0454 
0455 function image_directory_Callback(hObject, eventdata, handles)
0456 initImage(hObject, handles);
0457 
0458 
0459 function image_directory_CreateFcn(hObject, eventdata, handles)
0460 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0461     set(hObject,'BackgroundColor','white');
0462 end
0463 
0464 function go_to_frame_no_Callback(hObject, eventdata, handles)
0465 if ~isempty(handles.FLAGS)
0466     c = round(str2double(handles.go_to_frame_no.String));
0467     if c > handles.num_im
0468         handles.go_to_frame_no.String = num2str(handles.num_im);
0469     elseif isnan(c) || c < 1;
0470         handles.go_to_frame_no.String = '1';
0471     else
0472         handles.go_to_frame_no.String = num2str(c);
0473     end
0474     updateImage(hObject, handles);
0475 end
0476 
0477 function go_to_frame_no_CreateFcn(hObject, eventdata, handles)
0478 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0479     set(hObject,'BackgroundColor','white');
0480 end
0481 
0482 function next_Callback(hObject, eventdata, handles)
0483 if ~isempty(handles.FLAGS)
0484     handles.go_to_frame_no.String = num2str(str2double(handles.go_to_frame_no.String)+1);
0485     go_to_frame_no_Callback(hObject, eventdata, handles);
0486 end
0487 
0488 function figure1_KeyPressFcn(hObject, eventdata, handles)
0489 if strcmpi(eventdata.Key,'leftarrow')
0490     previous_Callback(hObject, eventdata, handles);
0491 end
0492 if strcmpi(eventdata.Key,'rightarrow')
0493     next_Callback(hObject, eventdata, handles);
0494 end
0495 if strcmpi(eventdata.Key,'e')
0496     intDispError(handles.data_c, handles.FLAGS, handles.canUseErr);
0497 end
0498 
0499 function previous_Callback(hObject, eventdata, handles)
0500 if ~isempty(handles.FLAGS)
0501     handles.go_to_frame_no.String = num2str(str2double(handles.go_to_frame_no.String)-1);
0502     go_to_frame_no_Callback(hObject, eventdata, handles);
0503 end
0504 
0505 function max_cell_no_Callback(hObject, eventdata, handles)
0506 handles.CONST.view.maxNumCell = round(str2double(handles.max_cell_no.String));
0507 handles.max_cell_no.String = num2str(round(str2double(handles.max_cell_no.String)));
0508 updateImage(hObject, handles);
0509 
0510 function max_cell_no_CreateFcn(hObject, eventdata, handles)
0511 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0512     set(hObject,'BackgroundColor','white');
0513 end
0514 
0515 function switch_xy_directory_Callback(hObject, eventdata, handles)
0516 if ~isempty(handles.FLAGS)
0517     ll_ = round(str2double(handles.switch_xy_directory.String));
0518     dirname0 = handles.dirname0;
0519     if isnumeric(ll_)
0520         handles.switch_xy_directory.String = num2str(ll_);
0521         if ~isempty(ll_) && (ll_ >= 1) && (ll_ <= handles.num_xy)
0522             try
0523                 clist = handles.clist;
0524                 if ~isempty(clist)
0525                     save( [dirname0,handles.contents_xy(handles.dirnum).name,filesep,'clist.mat'],'-STRUCT','clist');
0526                 end
0527             catch ME
0528                 printError(ME);
0529                 handles.message.String = 'Error writing clist file';
0530             end
0531             handles.dirnum = ll_;
0532             handles.dirname_seg = [dirname0,handles.contents_xy(ll_).name,filesep,'seg',filesep];
0533             handles.dirname_cell = [dirname0,handles.contents_xy(ll_).name,filesep,'cell',filesep];
0534             handles.dirname_xy = [dirname0,handles.contents_xy(ll_).name,filesep];
0535             ixy = sscanf( handles.contents_xy(handles.dirnum).name, 'xy%d' );
0536             handles.header = ['xy',num2str(ixy),': '];
0537             handles.contents = dir([handles.dirname_seg, '*seg.mat']);
0538             handles.num_im = numel(handles.contents);
0539             enable_all_panels(hObject,handles)
0540             if exist([dirname0,handles.contents_xy(ll_).name,filesep,'clist.mat'])
0541                 handles.clist = load([dirname0,handles.contents_xy(ll_).name,filesep,'clist.mat']);
0542                 update_clist_panel(hObject, handles)
0543             else
0544                 handles.clist = []
0545                 update_clist_panel(hObject, handles)
0546             end
0547             updateImage(hObject, handles);
0548         else
0549             handles.message.String = 'Incorrect number for xy position';
0550         end
0551     else
0552         handles.message.String = 'Number of xy position missing';
0553     end
0554 end
0555 guidata(hObject, handles);
0556 
0557 function switch_xy_directory_CreateFcn(hObject, eventdata, handles)
0558 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0559     set(hObject,'BackgroundColor','white');
0560 end
0561 
0562 % Display options
0563 
0564 function channel_Callback(hObject, eventdata, handles)
0565 if ~isempty(handles.FLAGS)
0566     f = 0;
0567     while true
0568         if isfield(handles,'data_c') && isfield(handles.data_c, ['fluor' num2str(f+1)] )
0569             f = f+1;
0570         else
0571             break
0572         end
0573     end
0574     c = round(str2double(handles.channel.String));
0575     if isnan(c) || c < 0 || c > f
0576         handles.channel.String = '0';
0577     else
0578         handles.channel.String = num2str(c);
0579     end
0580     handles.FLAGS.f_flag = c;
0581     updateImage(hObject, handles);
0582 end
0583 
0584 function channel_CreateFcn(hObject, eventdata, handles)
0585 if ispc && isequal(get(hObject, 'BackgroundColor'), get(0, 'defaultUicontrolBackgroundColor'))
0586     set(hObject,'BackgroundColor','white');
0587 end
0588 
0589 function find_cell_no_Callback(hObject, eventdata, handles)
0590 if ~isempty(handles.FLAGS)
0591     updateImage(hObject, handles);
0592     find_cell_no(handles);
0593 end
0594 
0595 function find_cell_no(handles)
0596 if ~isempty(handles.FLAGS)
0597     c = round(str2double(handles.find_cell_no.String));
0598     maxIndex = handles.data_c.regs.num_regs;
0599     if areCellsLoaded(handles)
0600         maxIndex = max(handles.data_c.regs.ID);
0601     end
0602     if isnan(c) || c < 1 || c >= maxIndex
0603         handles.find_cell_no.String = '';
0604     else
0605         handles.find_cell_no.String = num2str(c);
0606         if handles.FLAGS.cell_flag && shouldUseErrorFiles(handles.FLAGS, handles.canUseErr)
0607             regnum = find(handles.data_c.regs.ID == c);
0608             if ~isempty(regnum)
0609                 plot(handles.data_c.regs.props(regnum).Centroid(1),...
0610                     handles.data_c.regs.props(regnum).Centroid(2),'yx','MarkerSize',50);
0611             else
0612                 handles.message.String = 'Couldn''t find that cell number';
0613             end
0614         else
0615             if c <= handles.data_c.regs.num_regs
0616                 plot(handles.data_c.regs.props(c).Centroid(1),...
0617                     handles.data_c.regs.props(c).Centroid(2),'yx','MarkerSize',50);
0618             end
0619         end
0620     end
0621 end
0622 
0623 function find_cell_no_CreateFcn(hObject, eventdata, handles)
0624 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0625     set(hObject,'BackgroundColor','white');
0626 end
0627 
0628 function cell_numbers_Callback(hObject, eventdata, handles)
0629 if ~isempty(handles.FLAGS)
0630     handles.FLAGS.ID_flag = handles.cell_numbers.Value;
0631     if handles.FLAGS.ID_flag
0632         handles.FLAGS.regionScores = 0;
0633         handles.region_scores.Value = 0;
0634     end
0635     updateImage(hObject, handles);
0636 end
0637 
0638 function cell_poles_Callback(hObject, eventdata, handles)
0639 if ~isempty(handles.FLAGS)
0640     handles.FLAGS.p_flag = handles.cell_poles.Value;
0641     updateImage(hObject, handles);
0642 end
0643 
0644 function complete_cell_cycles_Callback(hObject, eventdata, handles)
0645 if ~isempty(handles.FLAGS)
0646     handles.CONST.view.showFullCellCycleOnly = handles.complete_cell_cycles.Value;
0647     if handles.CONST.view.showFullCellCycleOnly
0648         figure(2);
0649         if isfield(handles,'clist') && ~isempty(handles.clist)
0650             % gate of stat0 2
0651             handles.clist = gateMake( handles.clist, 9, [1.9 inf] );
0652         end
0653         close(2);
0654         handles.message.String = 'Only showing complete Cell Cycles';
0655     else
0656         if isfield(handles,'clist') && ~isempty(handles.clist)
0657             handles.clist = gateStrip ( handles.clist, 9 );
0658         end
0659         
0660         handles.message.String = 'Showing incomplete Cell Cycles';
0661     end
0662     updateImage(hObject, handles);
0663 end
0664 
0665 function false_color_Callback(hObject, eventdata, handles)
0666 if ~isempty(handles.FLAGS)
0667     if ~isfield( handles.CONST,'view') || ~isfield( handles.CONST.view,'falseColorFlag') || isempty( handles.CONST.view.falseColorFlag )
0668         handles.CONST.view.falseColorFlag = true;
0669     else
0670         handles.CONST.view.falseColorFlag = handles.false_color.Value;
0671     end
0672     updateImage(hObject, handles);
0673 end
0674 
0675 function filtered_fluorescence_Callback(hObject, eventdata, handles)
0676 if ~isempty(handles.FLAGS)
0677     handles.FLAGS.filt = handles.filtered_fluorescence.Value;
0678     handles.CONST.view.filtered = handles.filtered_fluorescence.Value;
0679     updateImage(hObject, handles);
0680 end
0681 
0682 function fluor_foci_scores_Callback(hObject, eventdata, handles)
0683 if ~isempty(handles.FLAGS)
0684     handles.FLAGS.s_flag = handles.fluor_foci_scores.Value;
0685     updateImage(hObject, handles);
0686 end
0687 
0688 function log_view_Callback(hObject, eventdata, handles)
0689 if ~isempty(handles.FLAGS)
0690     if ~isfield( handles.CONST, 'view' ) || ~isfield( handles.CONST.view, 'LogView' ) || isempty( handles.CONST.view.LogView )
0691         handles.CONST.view.LogView = true;
0692     else
0693         handles.CONST.view.LogView = handles.log_view.Value;
0694     end
0695     updateImage(hObject, handles);
0696 end
0697 
0698 function outline_cells_Callback(hObject, eventdata, handles)
0699 if ~isempty(handles.FLAGS)
0700     handles.FLAGS.Outline_flag = handles.outline_cells.Value;
0701     if handles.FLAGS.Outline_flag
0702         handles.FLAGS.P_flag = 0;
0703         handles.region_outlines.Value = 0;
0704     end
0705     updateImage(hObject, handles);
0706 end
0707 
0708 function region_outlines_Callback(hObject, eventdata, handles)
0709 if ~isempty(handles.FLAGS)
0710     handles.FLAGS.P_flag = handles.region_outlines.Value;
0711     if handles.FLAGS.P_flag
0712         handles.FLAGS.Outline_flag = 0;
0713         handles.outline_cells.Value = 0;
0714     end
0715     updateImage(hObject, handles);
0716 end
0717 
0718 function region_scores_Callback(hObject, eventdata, handles)
0719 if ~isempty(handles.FLAGS)
0720     handles.FLAGS.regionScores = handles.region_scores.Value;
0721     if handles.FLAGS.regionScores
0722         handles.FLAGS.ID_flag = 0;
0723         handles.cell_numbers.Value = 0;
0724     end
0725     updateImage(hObject, handles);
0726 end
0727 
0728 function use_seg_files_Callback(hObject, eventdata, handles)
0729 if ~isempty(handles.FLAGS)
0730     if handles.num_errs > 0
0731         handles.FLAGS.useSegs = handles.use_seg_files.Value;
0732         updateImage(hObject, handles);
0733     else
0734         handles.use_seg_files.Value = 1;
0735     end
0736 end
0737 
0738 % Gate options
0739 
0740 function clear_gates_Callback(hObject, eventdata, handles)
0741 if ~isempty(handles.FLAGS)
0742     handles.clist.gate = [];
0743     updateImage(hObject, handles);
0744 end
0745 
0746 function create_clist_Callback(hObject, eventdata, handles)
0747 if ~isempty(handles.FLAGS)
0748     if ~isfield( handles.clist, 'gate' )
0749         handles.clist.gate = [];
0750     end
0751     for ll_ = 1:handles.num_xy
0752         filename = [handles.dirname0,handles.contents_xy(ll_).name,filesep,'clist.mat'];
0753         clist_tmp = gate(load(filename ));
0754         if  ll_ == 1
0755             clist_comp = clist_tmp;
0756         else
0757             clist_comp.data = [clist_comp.data; clist_tmp.data];
0758             if isfield(clist_tmp,'data3D')
0759                 clist_comp.data3D = [clist_comp.data3D; clist_tmp.data3D];
0760             end
0761         end
0762     end
0763     save( [handles.dirname0,'clist_comp.mat'], '-STRUCT', 'clist_comp' );
0764 end
0765 
0766 function histogram_clist_Callback(hObject, eventdata, handles)
0767 if ~isempty(handles.FLAGS)
0768     figure(2);
0769     clf;
0770     gateHist(handles.clist, handles.histogram_clist.Value);
0771 end
0772 
0773 function histogram_clist_CreateFcn(hObject, eventdata, handles)
0774 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0775     set(hObject,'BackgroundColor','white');
0776 end
0777 
0778 function make_gate_Callback(hObject, eventdata, handles)
0779 if ~isempty(handles.FLAGS)
0780     figure(2);
0781     handles.clist = gateMake(handles.clist, handles.make_gate.Value);
0782     updateImage(hObject, handles);
0783 end
0784 
0785 function make_gate_CreateFcn(hObject, eventdata, handles)
0786 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0787     set(hObject,'BackgroundColor','white');
0788 end
0789 
0790 function move_gates_Callback(hObject, eventdata, handles)
0791 if ~isempty(handles.FLAGS)
0792     trackOptiGateCellFiles(handles.dirname_cell, handles.clist);
0793 end
0794 
0795 function plot_two_clists_Callback(hObject, eventdata, handles)
0796 if ~isempty(handles.FLAGS)
0797     setappdata(0, 'clist', handles.clist);
0798     [handles.clist] = plot2ClistsGui();
0799     updateImage(hObject, handles);
0800 end
0801 
0802 % Link options
0803 
0804 function show_daughters_Callback(hObject, eventdata, handles)
0805 if ~isempty(handles.FLAGS)
0806     handles.FLAGS.showDaughters = handles.show_daughters.Value;
0807     updateImage(hObject, handles);
0808 end
0809 
0810 function show_mothers_Callback(hObject, eventdata, handles)
0811 if ~isempty(handles.FLAGS)
0812     handles.FLAGS.showMothers = handles.show_mothers.Value;
0813     updateImage(hObject, handles);
0814 end
0815 
0816 function show_linking_Callback(hObject, eventdata, handles)
0817 if ~isempty(handles.FLAGS)
0818     handles.FLAGS.showLinks = handles.show_linking.Value;
0819     updateImage(hObject, handles);
0820 end
0821 
0822 
0823 function stop_tool_ClickedCallback(hObject, eventdata, handles)
0824 % button on toolstrip to debug
0825 keyboard;
0826 
0827 
0828 function value = shouldUseErrorFiles(FLAGS, canUseErr)
0829 value = canUseErr == 1 && FLAGS.useSegs == 0;
0830 
0831 function makeActive(button)
0832 button.ForegroundColor = [0, 0, 0];
0833 button.Enable = 'on';
0834 
0835 function makeActiveInput(input)
0836 input.ForegroundColor = [0, 0, 0];
0837 input.Enable = 'on';
0838 
0839 function makeInactive(button)
0840 button.ForegroundColor = [0, 0, 0];
0841 button.Enable = 'off';
0842 
0843 function makeInactiveInput(input)
0844 input.ForegroundColor = [.5, .5, .5];
0845 input.Enable = 'off';
0846 
0847 function value = areCellsLoaded(handles)
0848 %value =  isfield(handles.data_c.regs, 'ID');
0849 value = numel(dir([handles.dirname_cell,'*ell*']))>0;
0850 
0851 function time_clist_Callback(hObject, eventdata, handles)
0852 if ~isempty(handles.FLAGS) && isfield(handles.clist,'data3D')
0853     figure(2);
0854     clf;
0855     plotClist3D(handles.clist, handles.time_clist.Value);
0856 end
0857 
0858 function time_clist_CreateFcn(hObject, eventdata, handles)
0859 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0860     set(hObject,'BackgroundColor','white');
0861 end
0862 
0863 function clear_gate_Callback(hObject, eventdata, handles)
0864 if ~isempty(handles.FLAGS)
0865     handles.clist = gateStrip(handles.clist, str2double(handles.clear_gate.String));
0866     handles.clear_gate.String = '';
0867     updateImage(hObject, handles);
0868 end
0869 
0870 function clear_gate_CreateFcn(hObject, eventdata, handles)
0871 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0872     set(hObject,'BackgroundColor','white');
0873 end
0874 
0875 function exclude_ids_Callback(hObject, eventdata, handles)
0876 if ~isempty(handles.FLAGS)
0877     handles.clist.idExclude = str2double(strsplit(handles.exclude_ids.String));
0878     if isnan(handles.clist.idExclude)
0879         handles.exclude_ids.String = '';
0880     end
0881     if isempty(handles.exclude_ids.String)
0882         handles.clist = rmfield(handles.clist, 'idExclude');
0883     end
0884     updateImage(hObject, handles);
0885 end
0886 
0887 function exclude_ids_CreateFcn(hObject, eventdata, handles)
0888 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0889     set(hObject,'BackgroundColor','white');
0890 end
0891 
0892 function include_ids_Callback(hObject, eventdata, handles)
0893 if ~isempty(handles.FLAGS)
0894     handles.clist.idInclude = str2double(strsplit(handles.include_ids.String));
0895     if isnan(handles.clist.idInclude)
0896         handles.include_ids.String = '';
0897     end
0898     if isempty(handles.include_ids.String)
0899         handles.clist = rmfield(handles.clist, 'idInclude');
0900     end
0901     updateImage(hObject, handles);
0902 end
0903 
0904 function include_ids_CreateFcn(hObject, eventdata, handles)
0905 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0906     set(hObject,'BackgroundColor','white');
0907 end
0908 
0909 function edit_segments_Callback(hObject, eventdata, handles)
0910 choice = questdlg('Are you sure you want to edit the segments?', 'Edit segments?', 'Yes', 'No', 'No');
0911 if strcmp(choice, 'Yes')
0912     setappdata(0, 'CONST', handles.CONST);
0913     setappdata(0, 'dirname_xy', [handles.dirname0,handles.contents_xy(handles.dirnum).name,filesep]);
0914     setappdata(0, 'dirname_seg', handles.dirname_seg);
0915     setappdata(0, 'dirname_cell', handles.dirname_cell);
0916     setappdata(0, 'nn', str2double(handles.go_to_frame_no.String));
0917     editSegmentsGui();
0918 end
0919 
0920 function intDispError( data_c, FLAGS, canUseErr)
0921 % intDispError
0922 disp(  ' ' );
0923 disp(  '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' );
0924 disp(  '%     Errors for this frame     %' );
0925 disp(  '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' );
0926 for kk = 1:data_c.regs.num_regs
0927     if isfield(data_c,'regs') &&...
0928             isfield(data_c.regs, 'error') && ...
0929             isfield(data_c.regs.error,'label') && ...
0930             ~isempty( data_c.regs.error.label{kk} )
0931         if FLAGS.cell_flag && shouldUseErrorFiles(FLAGS, canUseErr) && isfield( data_c.regs, 'ID' )
0932             disp(  ['Cell: ', num2str(data_c.regs.ID(kk)), ', ', ...
0933                 data_c.regs.error.label{kk}] );
0934         else
0935             disp(  [ data_c.regs.error.label{kk}] );
0936         end
0937     end
0938 end
0939 
0940 function clickOnImage(hObject, eventdata, handles)
0941 global settings;
0942 point = round(eventdata.IntersectionPoint(1:2));
0943 if settings.handles.use_seg_files.Value == 1
0944     errordlg('Untick use regions');
0945 elseif ~isfield(settings.handles,'data_c')
0946     errordlg('Reload frame first');
0947 else
0948     data = settings.handles.data_c;
0949     if ~isfield(data,'regs')
0950         data = intMakeRegs( data, settings.handles.CONST, [], [] );
0951     end
0952     ss = size(data.phase);
0953     tmp = zeros([51,51]);
0954     tmp(26,26) = 1;
0955     tmp = 8000-double(bwdist(tmp));
0956     rmin = max([1,point(2)-25]);
0957     rmax = min([ss(1),point(2)+25]);
0958     cmin = max([1,point(1)-25]);
0959     cmax = min([ss(2),point(1)+25]);
0960     rrind = rmin:rmax;
0961     ccind = cmin:cmax;
0962     pointSize = [numel(rrind),numel(ccind)];
0963     tmp = tmp(26-point(2)+rrind,26-point(1)+ccind).*data.mask_cell(rrind,ccind);
0964     [~,ind] = max( tmp(:) );
0965     [sub1, sub2] = ind2sub( pointSize, ind );
0966     ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
0967     hold on;
0968     plot( sub2-1+cmin, sub1-1+rmin, 'o', 'MarkerFaceColor', 'g' );
0969     if ii ~=0
0970         if strcmp(settings.function, 'exclude')
0971             settings.id_list(end+1) = data.regs.ID(ii);
0972             settings.handles.exclude_ids.String = num2str(settings.id_list);
0973         elseif strcmp(settings.function, 'include')
0974             settings.id_list(end+1) = data.regs.ID(ii);
0975             settings.handles.include_ids.String = num2str(settings.id_list);
0976         else
0977             disp(['ID : ', num2str(data.regs.ID(ii))]);
0978             disp(['Area : ', num2str(data.regs.props(ii).Area)]);
0979             if isfield(data,'CellA')
0980                 disp(['Pole orientation : ', num2str(data.CellA{ii}.pole.op_ori)]);
0981                 disp(['BoundingBox : ', num2str(data.CellA{ii}.BB)]);
0982                 disp(['Axis Lengths : ', num2str(data.CellA{ii}.length)]);
0983                 disp(['Cell Length : ', num2str(data.CellA{ii}.cellLength(1))]);
0984                 disp(['Mean Width : ', num2str(data.CellA{ii}.cellLength(2))]);
0985                 disp(['Cell distance : ', num2str(data.CellA{ii}.cell_dist)]);
0986                 disp(['Cell Old Pole Age : ', num2str( data.CellA{ii}.pole.op_age)]);
0987                 disp(['Cell New Pole Age : ', num2str(data.CellA{ii}.pole.np_age)]);
0988                 
0989                 if isfield(data.CellA{ii},'fl1')
0990                     disp('fluorescence 1 statistics: ')
0991                     disp( (data.CellA{ii}.fl1));
0992                 end
0993                 if isfield(data.CellA{ii},'fl2')
0994                     disp('fluorescence 2 statistics : ')
0995                     disp( (data.CellA{ii}.fl1));
0996                 end
0997             end
0998             % disp(data.CellA{ii});
0999             
1000             updateImage(settings.hObject, settings.handles);
1001             plot( sub2-1+cmin, sub1-1+rmin, 'o', 'MarkerFaceColor', 'g' );
1002             cell_info_Callback(settings.hObject, settings.eventdata, settings.handles);
1003         end
1004     end
1005 end
1006 
1007 
1008 function from_img_exclude_Callback(hObject, eventdata, handles)
1009 global settings;
1010 state = get(hObject,'Value');
1011 if state == get(hObject,'Max')
1012     settings.handles = handles;
1013     settings.function = 'exclude';
1014     if isnan(str2double(strsplit(handles.exclude_ids.String)))
1015         settings.id_list = [];
1016     else
1017         settings.id_list = str2double(strsplit(handles.exclude_ids.String));
1018     end
1019     set(handles.axes1.Children, 'ButtonDownFcn', @clickOnImage);
1020 elseif state == get(hObject,'Min')
1021     handles.exclude_ids.String = settings.handles.exclude_ids.String;
1022     exclude_ids_Callback(hObject, eventdata, handles);
1023 end
1024 
1025 function from_img_include_Callback(hObject, eventdata, handles)
1026 global settings;
1027 state = get(hObject,'Value');
1028 if state == get(hObject,'Max')
1029     settings.handles = handles;
1030     settings.function = 'include';
1031     if isnan(str2double(strsplit(handles.include_ids.String)))
1032         settings.id_list = [];
1033     else
1034         settings.id_list = str2double(strsplit(handles.include_ids.String));
1035     end
1036     set(handles.axes1.Children, 'ButtonDownFcn', @clickOnImage);
1037 elseif state == get(hObject,'Min')
1038     handles.include_ids.String = settings.handles.include_ids.String;
1039     include_ids_Callback(hObject, eventdata, handles);
1040 end
1041 
1042 function save_output_Callback(hObject, eventdata, handles)
1043 
1044 
1045 
1046 % --- Executes on button press in legend_box.
1047 function legend_box_Callback(hObject, eventdata, handles)
1048 % hObject    handle to legend_box (see GCBO)
1049 % eventdata  reserved - to be defined in a future version of MATLAB
1050 % handles    structure with handles and user data (see GUIDATA)
1051 
1052 % Hint: get(hObject,'Value') returns toggle state of legend_box
1053 if ~isempty(handles.FLAGS)
1054     handles.FLAGS.legend = handles.legend_box.Value;
1055     updateImage(hObject, handles);
1056 end
1057 
1058 
1059 
1060 % --- Executes on button press in phase_flag.
1061 function phase_flag_Callback(hObject, eventdata, handles)
1062 % hObject    handle to phase_flag (see GCBO)
1063 % eventdata  reserved - to be defined in a future version of MATLAB
1064 % handles    structure with handles and user data (see GUIDATA)
1065 
1066 % Hint: get(hObject,'Value') returns toggle state of phase_flag
1067 if ~isempty(handles.FLAGS)
1068     handles.FLAGS.phase_flag = get(hObject,'Value');
1069     updateImage(hObject, handles);
1070 end
1071 
1072 function phase_level_txt_Callback(hObject, eventdata, handles)
1073 % hObject    handle to phase_level_txt (see GCBO)
1074 % eventdata  reserved - to be defined in a future version of MATLAB
1075 % handles    structure with handles and user data (see GUIDATA)
1076 
1077 % Hints: get(hObject,'String') returns contents of phase_level_txt as text
1078 %        str2double(get(hObject,'String')) returns contents of phase_level_txt as a double
1079 if ~isempty(handles.FLAGS)
1080     handles.FLAGS.phase_level = str2double(get(hObject,'String'));
1081     updateImage(hObject, handles);
1082 end
1083 
1084 
1085 % --- Executes during object creation, after setting all properties.
1086 function phase_level_txt_CreateFcn(hObject, eventdata, handles)
1087 % hObject    handle to phase_level_txt (see GCBO)
1088 % eventdata  reserved - to be defined in a future version of MATLAB
1089 % handles    empty - handles not created until after all CreateFcns called
1090 
1091 % Hint: edit controls usually have a white background on Windows.
1092 %       See ISPC and COMPUTER.
1093 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1094     set(hObject,'BackgroundColor','white');
1095 end
1096 
1097 
1098 % --- Executes on button press in composite.
1099 function composite_Callback(hObject, eventdata, handles)
1100 % hObject    handle to composite (see GCBO)
1101 % eventdata  reserved - to be defined in a future version of MATLAB
1102 % handles    structure with handles and user data (see GUIDATA)
1103 
1104 % Hint: get(hObject,'Value') returns toggle state of composite
1105 if ~isempty(handles.FLAGS)
1106     handles.FLAGS.composite = get(hObject,'Value') ;
1107     updateImage(hObject, handles);
1108 end
1109 
1110 
1111 % --- Executes on button press in region_ids.
1112 function region_ids_Callback(hObject, eventdata, handles)
1113 % hObject    handle to region_ids (see GCBO)
1114 % eventdata  reserved - to be defined in a future version of MATLAB
1115 % handles    structure with handles and user data (see GUIDATA)
1116 
1117 % Hint: get(hObject,'Value') returns toggle state of region_ids
1118 if ~isempty(handles.FLAGS)
1119     handles.FLAGS.cell_flag = ~get(hObject,'Value') ;
1120     updateImage(hObject, handles);
1121 end
1122 
1123 
1124 
1125 % Output options
1126 function names = list_output_strings ()
1127 % strings that will be included in the output
1128 % format is :  name, needsCellFiles, needsClist
1129 names = [{'Cell Kymo'},1,0;
1130     {'Cell Movie'},1,0;
1131     {'Cell Tower'},1,0;
1132     {'Kymograph Mosaic'},1,0;
1133     {'Cell Tower Mosaic'},1,0;
1134     {'Lineage'},0,1;
1135     {'Field Movie'},0,0;
1136     {'Field Mosaic'},0,0;
1137     {'Consensus'},1,0;
1138     {'Consensus Kymo'},1,0];
1139 
1140 
1141 
1142 % --- Executes on selection change in output_list.
1143 function output_list_Callback(hObject, eventdata, handles)
1144 % Executes on double click of output options :
1145 % make sure names here match with names above.
1146 
1147 contents = cellstr(get(hObject,'String'));
1148 value = contents{get(hObject,'Value')};
1149 handles.message.String = '';
1150 
1151 if ~isempty(get(hObject, 'UserData')) && get(hObject, 'UserData') == get(hObject, 'Value')
1152     if strcmp('Cell Kymo',value)
1153         makeCellKymo(handles);
1154     elseif strcmp('Cell Movie',value)
1155         intMakeCellMovie(handles);
1156     elseif strcmp('Kymograph Mosaic',value)
1157         if ~areCellsLoaded(handles)
1158             errordlg('No cell files found');
1159         else
1160             figure(2);
1161             im = makeKymoMosaic( handles.dirname_cell, handles.CONST );
1162             if handles.save_output.Value
1163                 savename = [handles.dirSave, 'mosaic_kymograph'];
1164                 save (savename, 'im');
1165                 handles.message.String = ['Saved mosaic kymograph at ', savename];
1166             end
1167         end
1168     elseif strcmp('Cell Tower',value)
1169         makeCellTower(handles);
1170     elseif strcmp('Cell Tower Mosaic',value)
1171         cell_tower_mosaic(handles);
1172     elseif strcmp('Lineage',value)
1173         if isempty(handles.clist)
1174             errordlg('No clist found');
1175         else
1176             min_width = 3;
1177             ids = str2num(handles.cell_no.String);
1178             if isnan(ids)
1179                 ids = [];
1180             end
1181             makeLineage( handles.clist, ids, min_width );
1182         end
1183     elseif strcmp('Field Movie',value)
1184         makeFieldMovie(handles);
1185     elseif strcmp('Field Mosaic',value)
1186         handles = field_mosaic( handles)
1187     elseif strcmp('Consensus',value);
1188         handles = consensus_image(handles)
1189     elseif strcmp('Consensus Kymo',value)
1190         handles = consensus_kymo(handles);
1191     end
1192 end
1193 
1194 set(hObject, 'UserData', get(hObject, 'Value')); % for double click selection
1195 
1196 function cell_info_Callback(hObject, eventdata, handles)
1197 global settings;
1198 state = get(hObject,'Value');
1199 if state == get(hObject,'Max')
1200     settings.hObject = hObject;
1201     settings.handles = handles;
1202     settings.function = 'cell_info';
1203     settings.eventdata = eventdata;
1204     set(handles.axes1.Children, 'ButtonDownFcn', @clickOnImage);
1205 elseif state == get(hObject,'Min')
1206     updateImage(hObject, handles);
1207 end
1208 
1209 function handles = consensus_kymo(handles)
1210 global dataImArray
1211 if ~areCellsLoaded(handles)
1212     errordlg('No cell files found');
1213 else
1214     if ~exist('dataImArray','var') || isempty(dataImArray)
1215         fnum = handles.FLAGS.f_flag;
1216         if fnum == 0
1217             fnum = 1;
1218         end
1219         [dataImArray] = makeConsensusArray( handles.dirname_cell, handles.CONST...
1220             , 5,[], fnum, handles.clist);
1221         save ([handles.dirSave,'dataImArray'],'dataImArray');
1222     else
1223         handles.message.String = 'dataImArray already calculated';
1224     end
1225     [kymo,kymoMask ] = makeConsensusKymo(dataImArray.imCellNorm, dataImArray.maskCell , 1 );
1226     if handles.save_output.Value
1227         save ([handles.dirSave, 'consensus_kymograph'], 'kymo', 'kymoMask');
1228     end
1229 end
1230 
1231 
1232 
1233 function handles = consensus_image(handles)
1234 global dataImArray
1235 if ~areCellsLoaded(handles)
1236     errordlg('No cell files found');
1237 else
1238     if ~exist('dataImArray','var') || isempty(dataImArray)
1239         fnum = handles.FLAGS.f_flag;
1240         if fnum == 0
1241             fnum = 1;
1242         end
1243         [dataImArray] = makeConsensusArray( handles.dirname_cell, handles.CONST...
1244             , 5,[], fnum, handles.clist);
1245         save ([handles.dirSave,'dataImArray'],'dataImArray');
1246     else
1247         handles.message.String = 'dataImArray already calculated';
1248     end
1249     [imMosaic, imColor, imBW, imInv, imMosaic10 ] = makeConsensusImage(dataImArray,handles.CONST,5,4,0);
1250     if handles.save_output.Value
1251         save ([handles.dirSave, 'show_consensus'], 'imMosaic', 'imColor', 'imBW', 'imInv', 'imMosaic10');
1252     end
1253     figure(2);
1254     clf;
1255     imshow(imColor);
1256     
1257 end
1258 
1259 
1260 function makeCellKymo(handles)
1261 if ~areCellsLoaded(handles)
1262     errordlg('No cell files found');
1263 else
1264     c = str2num(handles.cell_no.String);
1265     if numel(c) > 1
1266         c = c(1);
1267     end
1268     if isempty(c) || isnan(c) || c < 1 || c > max(handles.data_c.regs.ID)
1269         handles.message.String = ['Invalid cell number'];
1270     else
1271         handles.kymograph_cell_no.String = num2str(c);
1272         [data_cell,cell_name] = loadCellData(c, handles.dirname_cell, handles);
1273         handles.message.String = ['Kymograph for cell ', cell_name];
1274         if ~isempty( data_cell )
1275             figure(2);
1276             clf;
1277             makeKymographC(data_cell, 1, handles.CONST,[]);
1278             title(cell_name);
1279             ylabel('Long Axis (pixels)');
1280             xlabel('Time (frames)' );
1281         end
1282     end
1283 end
1284 
1285 function intMakeCellMovie(handles)
1286 if ~areCellsLoaded(handles)
1287     errordlg('No cell files found');
1288 else
1289     c = str2num(handles.cell_no.String);
1290     if numel(c) > 1
1291         c = c(1);
1292     end
1293     if isempty(c) || isnan(c) || c < 1 || c > max(handles.data_c.regs.ID)
1294         handles.message.String = ['Invalid cell number'];
1295     else
1296         
1297         handles.movie_cell_no.String = num2str(c);
1298         [data_cell,cell_name] = loadCellData(c, handles.dirname_cell, handles);
1299         
1300         if ~isempty(data_cell)
1301             handles.message.String = ['Movie for cell ', cell_name];
1302             mov = makeCellMovie(data_cell);
1303             choice = questdlg('Save movie?', 'Save movie?', 'Yes', 'No', 'No');
1304             if strcmp(choice, 'Yes')
1305                 saveFilename = [handles.dirSave,cell_name(1:end-4),'.avi'];
1306                 v = VideoWriter(saveFilename);
1307                 v.FrameRate = 10;
1308                 open(v)
1309                 writeVideo(v,mov)
1310                 close(v)
1311                 handles.message.String = ['Saved movie at ', saveFilename];
1312             end
1313         end
1314     end
1315 end
1316 
1317 
1318 function hanldes = makeCellTower( handles)
1319 if ~areCellsLoaded(handles)
1320     errordlg('No cell files found');
1321 else
1322     if ~isempty(handles.FLAGS)
1323         c = str2num(handles.cell_no.String);
1324         if numel(c) > 1
1325             c = c(1);
1326         end
1327         if isempty(c) || isnan(c) || c < 1 || c > max(handles.data_c.regs.ID)
1328             handles.message.String = ['Invalid cell number'];
1329         else
1330             
1331             handles.cell_no.String = num2str(c);
1332             xdim = 4; %str2double(handles.no_columns.String);
1333             [data_cell,cell_name] = loadCellData(c, handles.dirname_cell, handles);
1334             if ~isempty( data_cell )
1335                 handles.message.String = ['Cell Tower for cell ', cell_name];
1336                 figure(2);
1337                 clf;
1338                 makeFrameMosaic(data_cell, handles.CONST, xdim);
1339                 title(cell_name);
1340             end
1341         end
1342     end
1343 end
1344 
1345 
1346 function [startFr,endFr,skip] = dialogBoxStartEndSkip (handles)
1347 prompt = {'Start frame:', 'End frame:','Choose Total # frames :','or Skip Frames :'};
1348 dlg_title = 'Make Field Movie';
1349 num_lines = 1;
1350 a = inputdlg(prompt,dlg_title,num_lines);
1351 
1352 if ~isempty(a) % did not press cancel
1353     startFr = str2double(a(1));
1354     endFr =  str2double(a(2));
1355     numFrm =  str2double(a(3));
1356     skip =  str2double(a(4));
1357     if isnan(endFr) || endFr < startFr || endFr > handles.num_im
1358         endFr = handles.num_im;
1359     end
1360     
1361     if  isnan(startFr) ||startFr < 1 || startFr > handles.num_im
1362         startFr = 1;
1363     end
1364     
1365     if isnan(skip) && ~isnan(numFrm)
1366         skip = (endFr-startFr)/(numFrm-1);
1367     end
1368     
1369     if isnan(numFrm) && ~isnan(skip)
1370         skip = skip;
1371     end
1372     
1373     if isnan(skip) && isnan(numFrm)
1374         skip = 1; % default value
1375     end
1376     
1377 else
1378     startFr = [];
1379     endFr = [];
1380     skip =  [];
1381     
1382 end
1383 
1384 
1385 
1386 function handles = field_mosaic( handles)
1387 
1388 if ~isempty(handles.FLAGS)
1389     clear mov;
1390     mov.cdata = [];
1391     mov.colormap = [];
1392     [startFr,endFr,skip] = dialogBoxStartEndSkip (handles);
1393     if ~isempty(startFr)
1394         counter = 0;
1395         time = round(startFr:skip: endFr);
1396         for ii = time
1397             delete(get(handles.axes1, 'Children'));
1398             counter = counter  + 1;
1399             [data_r, data_c, data_f] = intLoadDataViewer( handles.dirname_seg, ...
1400                 handles.contents, ii, handles.num_im, handles.clist, handles.FLAGS);
1401             showSeggerImage( data_c, data_r, data_f, handles.FLAGS, handles.clist, handles.CONST, handles.axes1);
1402             drawnow;
1403             mov(counter) = getframe;
1404             handles.message.String = ['Frame number: ', num2str(ii)];
1405         end
1406         handles.message.String = ('Field mosaic loaded');
1407         
1408         figure(2);
1409         clf;
1410         
1411         num_time = numel(time);
1412         x = min(6,num_time);
1413         y = ceil(num_time/x);
1414         if y == 0
1415             y = 1;
1416         end
1417         ha = tight_subplot(y,x,[0.01 0],[0 0],[0 0]);
1418         counter = 0;
1419         for ii = time
1420             counter = counter  + 1;
1421             axes(ha(counter));
1422             imshow(mov(counter).cdata);
1423             hold on;
1424             text( 30,30,[num2str(ii)],'color','b');
1425         end
1426     end
1427 end
1428 
1429 
1430 
1431 function makeFieldMovie(handles)
1432 % makes field movie
1433 if ~isempty(handles.FLAGS)
1434     clear mov;
1435     [startFr,endFr,skip] = dialogBoxStartEndSkip (handles);
1436     if ~isempty(startFr)
1437         mov.cdata = [];
1438         mov.colormap = [];
1439         counter = 1;
1440         for ii = round(startFr:skip: endFr)
1441             delete(get(handles.axes1, 'Children'))
1442             [data_r, data_c, data_f] = intLoadDataViewer( handles.dirname_seg, ...
1443                 handles.contents, ii, handles.num_im, handles.clist, handles.FLAGS);
1444             showSeggerImage( data_c, data_r, data_f, handles.FLAGS, handles.clist, handles.CONST, handles.axes1);
1445             drawnow;           
1446             mov(counter) = getframe;
1447             counter = counter + 1;
1448             handles.message.String = ['Frame number: ', num2str(ii)];
1449         end
1450         choice = questdlg('Save movie?', 'Save movie?', 'Yes', 'No', 'No');
1451         if strcmp(choice, 'Yes')
1452             filename = inputdlg('Filename', 'Filename:', 1);
1453             if ~isempty(filename)
1454                 saveFilename = [handles.dirSave,filename{1},'.avi'];
1455                 v = VideoWriter(saveFilename);
1456                 v.FrameRate = 10;
1457                 open(v);
1458                 writeVideo(v,mov);
1459                 close(v);
1460                 handles.message.String = ['Saved movie at ', saveFilename];
1461             end
1462         end
1463     end
1464 end
1465 
1466 
1467 function cell_tower_mosaic(handles)
1468 if ~isempty(handles.FLAGS) && areCellsLoaded(handles)
1469     figure(2);
1470     clf;
1471     imTot = makeFrameStripeMosaic([handles.dirname_cell], handles.CONST, [], true);
1472     if handles.save_output.Value
1473         save ([handles.dirSave,'tower_cells'],'imTot');
1474     end
1475 end
1476 
1477 % --- Executes during object creation, after setting all properties.
1478 function output_list_CreateFcn(hObject, eventdata, handles)
1479 % hObject    handle to output_list (see GCBO)
1480 % eventdata  reserved - to be defined in a future version of MATLAB
1481 % handles    empty - handles not created until after all CreateFcns called
1482 
1483 % Hint: listbox controls usually have a white background on Windows.
1484 %       See ISPC and COMPUTER.
1485 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1486     set(hObject,'BackgroundColor','white');
1487 end
1488 
1489 
1490 function cell_no_Callback(hObject, eventdata, handles)
1491 % hObject    handle to cell_no (see GCBO)
1492 % eventdata  reserved - to be defined in a future version of MATLAB
1493 % handles    structure with handles and user data (see GUIDATA)
1494 
1495 % Hints: get(hObject,'String') returns contents of cell_no as text
1496 %        str2double(get(hObject,'String')) returns contents of cell_no as a double
1497 
1498 
1499 % --- Executes during object creation, after setting all properties.
1500 function cell_no_CreateFcn(hObject, eventdata, handles)
1501 % hObject    handle to cell_no (see GCBO)
1502 % eventdata  reserved - to be defined in a future version of MATLAB
1503 % handles    empty - handles not created until after all CreateFcns called
1504 
1505 % Hint: edit controls usually have a white background on Windows.
1506 %       See ISPC and COMPUTER.
1507 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1508     set(hObject,'BackgroundColor','white');
1509 end
1510 
1511 
1512 % --- Executes on button press in save_clist.
1513 function save_clist_Callback(hObject, eventdata, handles)
1514 % hObject    handle to save_clist (see GCBO)
1515 % eventdata  reserved - to be defined in a future version of MATLAB
1516 % handles    structure with handles and user data (see GUIDATA)
1517 try
1518     clist = handles.clist;
1519     if ~isempty(clist)
1520         save( [handles.dirname0,handles.contents_xy(handles.dirnum).name,filesep,'clist.mat'],'-STRUCT','clist');
1521     end
1522 catch
1523     disp('Error saving.' );
1524 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005