Home > SuperSegger > viz > superSeggerViewer.m

superSeggerViewer

PURPOSE ^

superSeggerViewer : interactive visulization of the segmented data.

SYNOPSIS ^

function superSeggerViewer(dirname)

DESCRIPTION ^

 superSeggerViewer : interactive visulization of the segmented data.
 It displays a menu from which the user can make choices and vizualize or
 analyze the segmented data.

 important notes :
 - it saves a file in the directory named .trackOptiView.mat where it
 saves the flags from the previous launch
 - it uses the clist which can be gated to only show cells that pass specific
 criteria. it outlines and analyzes only cells that pass the gate, to display
 the full dataset the gate needs to be deleted.



 INPUT :
       dirname : main directory that contains files segemented by supeSegger
       it must be the directory that has raw_im and xy1 etc folders.
       It can be run from the seg file directly but some functions that require
       cell files will not work.


 Copyright (C) 2016 Wiggins Lab
 Written by Stella Stylianidou, Paul Wiggins, Connor Brennan.
 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 superSeggerViewer(dirname)
0002 % superSeggerViewer : interactive visulization of the segmented data.
0003 % It displays a menu from which the user can make choices and vizualize or
0004 % analyze the segmented data.
0005 %
0006 % important notes :
0007 % - it saves a file in the directory named .trackOptiView.mat where it
0008 % saves the flags from the previous launch
0009 % - it uses the clist which can be gated to only show cells that pass specific
0010 % criteria. it outlines and analyzes only cells that pass the gate, to display
0011 % the full dataset the gate needs to be deleted.
0012 %
0013 %
0014 %
0015 % INPUT :
0016 %       dirname : main directory that contains files segemented by supeSegger
0017 %       it must be the directory that has raw_im and xy1 etc folders.
0018 %       It can be run from the seg file directly but some functions that require
0019 %       cell files will not work.
0020 %
0021 %
0022 % Copyright (C) 2016 Wiggins Lab
0023 % Written by Stella Stylianidou, Paul Wiggins, Connor Brennan.
0024 % University of Washington, 2016
0025 % This file is part of SuperSegger.
0026 %
0027 % SuperSegger is free software: you can redistribute it and/or modify
0028 % it under the terms of the GNU General Public License as published by
0029 % the Free Software Foundation, either version 3 of the License, or
0030 % (at your option) any later version.
0031 %
0032 % SuperSegger is distributed in the hope that it will be useful,
0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0035 % GNU General Public License for more details.
0036 %
0037 % You should have received a copy of the GNU General Public License
0038 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0039 
0040 %% Load Constants and Initialize Flags
0041 
0042 global canUseErr;
0043 hf = figure(1);
0044 clf;
0045 mov = struct;
0046 CONST = [];
0047 touch_list = [];
0048 setHeader =[];
0049 
0050 % Add slash to the file name if it doesn't exist
0051 if(nargin<1 || isempty(dirname))
0052     dirname=uigetdir();
0053 end
0054 
0055 dirname = fixDir(dirname);
0056 dirname0 = dirname;
0057 
0058 % load flags if they already exist to maintain state between launches
0059 filename_flags = [dirname0,'.superSeggerViewer.mat'];
0060 FLAGS = [];
0061 if exist( filename_flags, 'file' )
0062     load(filename_flags);
0063     FLAGS = fixFlags(FLAGS);
0064 else
0065     FLAGS = fixFlags(FLAGS);
0066     error_list = [];
0067     nn = 1;
0068     dirnum = 1;
0069 end
0070 
0071 % Load info from one of the xy directories. dirnum tells you which one. If
0072 % you quit the program in an xy dir, it goes to that xy dir.
0073 clist = [];
0074 contents_xy =dir([dirname, 'xy*']);
0075 num_xy = numel(contents_xy);
0076 direct_contents = dir([dirname, '*seg.mat']);
0077 
0078 
0079 if num_xy~=0
0080     if isdir([dirname0,contents_xy(dirnum).name,filesep,'seg_full'])
0081         dirname_seg = [dirname0,contents_xy(dirnum).name,filesep,'seg_full',filesep];
0082     else
0083         dirname_seg = [dirname0,contents_xy(dirnum).name,filesep,'seg',filesep];
0084     end
0085     
0086     dirname_cell = [dirname0,contents_xy(dirnum).name,filesep,'cell',filesep];
0087     dirname_xy = [dirname0,contents_xy(dirnum).name,filesep];
0088     
0089     % Open clist if it exists
0090     clist_name = [dirname0,contents_xy(dirnum).name,filesep,'clist.mat'];
0091     if exist( clist_name, 'file' )
0092         clist = load([dirname0,contents_xy(dirnum).name,filesep,'clist.mat']);
0093     else
0094         clist = [];
0095     end
0096     
0097     ixy = intGetNum( contents_xy(dirnum).name );
0098     header = ['xy',num2str(ixy),': '];
0099 else
0100     if numel(direct_contents) == 0
0101         disp('There are no xy dirs. Choose a different directory.');
0102         return;
0103     else % loading from the seg directory directly
0104         dirname_cell = dirname;
0105         dirname_xy = dirname;
0106         dirname_seg = dirname;
0107         ixy = 1;
0108         header = ['seg',num2str(ixy),': '];
0109     end
0110 end
0111 
0112 if exist([dirname0,'CONST.mat'],'file')
0113     CONST = load([dirname0,'CONST.mat']);
0114     if isfield( CONST, 'CONST' )
0115         CONST = CONST.CONST;
0116     end
0117 else
0118     disp(['Exiting. There is a CONST.mat file at the root', ...
0119         'level of the data directory. Loading default 60XEcLB']);
0120     CONST = loadConstants(60,0);
0121 end
0122 
0123 contents=dir([dirname_seg, '*seg.mat']);
0124 num_im = length(contents);
0125 
0126 if (num_im == 0)
0127     error('No files found in the seg directory');
0128 end
0129 
0130 % for calculations that take time like the consensus array
0131 % you can save the array in a folder so that it is loaded from there
0132 % instead of calculated repeatedly.
0133 dirSave = [dirname,'superSeggerViewer',filesep];
0134 if ~exist(dirSave,'dir')
0135     mkdir(dirSave);
0136 else
0137     if exist([dirSave,'dataImArray.mat'],'file')
0138         load ([dirSave,'dataImArray'],'dataImArray');
0139     end
0140 end
0141 
0142 runFlag = (nn<=num_im);
0143 
0144 % This flag controls whether you reload from file
0145 first_flag = true;
0146 resetFlag = true;
0147 FLAGS.e_flag = 0 ;
0148 
0149 %% Run the main loop... and run it while the runFlag is true.
0150 while runFlag
0151     figure(1);
0152     
0153     contents=dir([dirname_seg, '*seg.mat']);
0154     num_segs = length(contents);
0155     
0156     contents=dir([dirname_seg, '*err.mat']);
0157     num_errs = length(contents);
0158     
0159     num_im = max(num_segs, num_errs);
0160     
0161     %Use region IDs if cells IDs unavailable
0162     if nn > num_errs || FLAGS.useSegs
0163         canUseErr = 0;
0164         contents=dir([dirname_seg, '*seg.mat']);
0165     else
0166         canUseErr = 1;
0167         contents=dir([dirname_seg, '*err.mat']);
0168     end
0169     
0170     % load current frame
0171     if resetFlag
0172         resetFlag = false;
0173         [data_r, data_c, data_f] = intLoadDataViewer( dirname_seg, ...
0174             contents, nn, num_im, clist, FLAGS);
0175     end
0176     
0177     clean_axis = [0 , 1 , 0  ,1];
0178     
0179     if ~first_flag && all(axis~=clean_axis)
0180         tmp_axis = axis;
0181     else % if first time - load image to get the axis
0182         clf;
0183         imshow(data_c.phase);
0184         tmp_axis = axis;
0185         first_flag = false;
0186     end
0187     
0188     %Force flags to required values when data is unavailable
0189     forcedFlags = FLAGS;
0190     forcedFlags.cell_flag = forcedFlags.cell_flag & shouldUseErrorFiles(FLAGS);
0191     %Force cell flag to 0 when err files not present
0192     
0193     showSeggerImage( data_c, data_r, data_f, forcedFlags, clist, CONST, []);
0194     flagsStates = intSetStateStrings(FLAGS,CONST);
0195     
0196     axis(tmp_axis);
0197     
0198     
0199     % Main Menu
0200     disp('------------------------------SuperSegger Data Viewer-------------------------------------');
0201     disp('-------------------------------------Main Menu--------------------------------------------');
0202     disp(['q  : To quit                                  reset : Reset axis to default   ']);
0203     disp(['x# : Switch xy directory from ', num2str(ixy), '               #  : Go to Frame Number #']);
0204     disp('----------------------------------Display Options-----------------------------------------');
0205     disp(['    Region info: ', num2str(num_segs), ' frames.   Cell info: ', num2str(num_errs), ' frames.   Current frame: ', num2str(nn)]);
0206     if ~FLAGS.cell_flag
0207         fprintf(2, 'Displaying region data.\n');
0208     end
0209     if FLAGS.useSegs
0210         fprintf(2, 'Using seg files. Displaying region IDs instead of cell IDs.\n');
0211     elseif ~canUseErr
0212         fprintf(2, 'No cell info for this frame. Displaying region IDs instead.\n');
0213     end
0214     disp(' ');
0215     disp(['id  : Show/Hide Cell Numbers ', [flagsStates.idState],'            seg : Use seg files ', flagsStates.useSegs]);
0216     disp(['r  : Show/Hide Region Outlines ', [flagsStates.rState],'          rs  : Show/Hide Region scores ', [flagsStates.regionScores]]);
0217     disp(['p  : Show/Hide Cell Poles ', flagsStates.pState,'               outline  : Outline cells ', flagsStates.vState]);
0218     disp(['f#  : Change channel ', [flagsStates.fState],'                  s  : Show Fluor Foci Scores ', [flagsStates.sState]]);
0219     disp(['filter : Filtered fluorescence ',flagsStates.filtState,'          CC : Use Complete Cell Cycles ', flagsStates.CCState] );
0220     disp(['falseCol : False Color ', flagsStates.falseColState,'                  log : Log View ', flagsStates.logState ]);
0221     disp(['find# : Find Cell Number #']);
0222     disp('-------------------------------------Link Options-----------------------------------------');
0223     if ~canUseErr || FLAGS.useSegs
0224         fprintf(2, 'Cell information must be availble to use this feature.\n');
0225     end
0226     if ~canUseErr
0227         fprintf(2, 'Please complete the linking phase of superSegger\n');
0228     end
0229     if FLAGS.useSegs
0230         fprintf(2, 'Please enable use of err files (seg command)\n');
0231     end
0232     disp(['link  : Show Linking Information               mother : Show mothers ', flagsStates.showMothers]);
0233     disp(['daughter  : Show daughters ', flagsStates.showDaughters]);
0234     disp('-----------------------------------Output Options-----------------------------------------');
0235     disp(['con  : Show Consensus                         cKym : Show consensus kymograph']);
0236     disp(['kymAll : Mosaic Kymograph of all cells        kym# : Show Kymograph for Cell #']);
0237     disp(['twrAll : Towers of all cells                  twr# : Tower for Cell #']);
0238     disp(['movie : Movie of this xy position             movie#  : Movie of # cell']);
0239     disp(['save : Save Figure #']);
0240     disp('-------------------------------------Gate Options-----------------------------------------');
0241     if ~isempty(clist)
0242         disp(['    Clist: ', [dirname0,contents_xy(dirnum).name,filesep,'clist.mat']]);
0243     else
0244         fprintf(2, 'No clist loaded, these commands will not work.\n');
0245     end
0246     disp(' ');
0247     disp(['g  : Make Gate                                G  : Create xy-combined clist, gated.']);
0248     disp(['moveG  : Move gated cells                     clear : Clear all Gates ']);
0249     disp(['hist : Histogram of clist quantity            hist2 : Plotting two clist quantities ']);
0250     disp('-------------------------------------Debug Options----------------------------------------');
0251     disp('k : Enter debugging mode');
0252     disp('------------------------------------------------------------------------------------------');
0253     disp(' ');
0254     if FLAGS.e_flag
0255         intDispError( data_c, FLAGS );
0256     end
0257     if ~isempty( touch_list );
0258         disp('Warning! Frames touched. Run re-link.');
0259         touch_list;
0260     end
0261     
0262     disp([header, 'Frame num [1...',num2str(num_im),']: ',num2str(nn)]);
0263     
0264     %pause;
0265     c = input(':','s');
0266     
0267     % LIST OF COMMANDS
0268     if isempty(c)
0269         % do nothing
0270         
0271     elseif strcmpi (c,'falseCol') % false color view
0272         if ~isfield( CONST,'view') || ...
0273                 ~isfield( CONST.view,'falseColorFlag')|| isempty( CONST.view.falseColorFlag )
0274             CONST.view.falseColorFlag = true;
0275         else
0276             CONST.view.falseColorFlag = ~CONST.view.falseColorFlag;
0277         end
0278         
0279     elseif  strcmpi(c,'log') % log view
0280         if ~isfield( CONST, 'view' ) || ~isfield( CONST.view, 'LogView' ) || ...
0281                 isempty( CONST.view.LogView )
0282             CONST.view.LogView = true;
0283         else
0284             CONST.view.LogView = ~CONST.view.LogView;
0285         end
0286         
0287     elseif strcmpi(c,'q') % Quit Command
0288         if exist('clist','var') && ~isempty(clist)
0289             save( [dirname0,contents_xy(dirnum).name,filesep,'clist.mat'],'-STRUCT','clist');
0290         else
0291             disp('Error saving clist file.');
0292         end
0293         runFlag = 0  ;
0294         
0295     elseif strcmpi(c,'CC') % Toggle Between Full Cell Cycles
0296         CONST.view.showFullCellCycleOnly = ~CONST.view.showFullCellCycleOnly ;
0297         
0298         if CONST.view.showFullCellCycleOnly
0299             figure(2);
0300             clist = gateMake( clist, 9, [1.1 inf] ); % stat0 above 1
0301             close(2);
0302             disp('Only showing complete Cell Cycles')
0303             resetFlag = 1;
0304         else
0305             figure(2);
0306             clist = gateStrip ( clist, 9 ); % clear stat0 gate
0307             close(2);
0308             disp('Showing incomplete Cell Cycles')
0309             resetFlag = 1;
0310         end
0311     elseif strcmpi(c,'hist') % choose characteristics and values to gate cells
0312         disp('Choose histogram characteristic')
0313         disp(clist.def')
0314         cc = str2double(input('Characteristic [ ] :','s')) ;
0315         figure(2);
0316         clf;
0317         gateHist(clist,cc);
0318         
0319     elseif strcmpi(c,'hist2') % choose characteristics and values to gate cells
0320         disp('Choose histogram characteristic')
0321         cc1 = str2double(input('Characteristic 1 [ ] :','s')) ;
0322         cc2 = str2double(input('Characteristic 2 [ ] :','s')) ;
0323         figure(2);
0324         clf;
0325         gateHistDot(clist, [cc1 cc2]);
0326         
0327     elseif strcmpi(c,'save') % choose characteristics and values to gate cells
0328         figNum = str2double(input('Figure number :','s')) ;
0329         filename = input('Filename :','s') ;
0330         savename = sprintf('%s/%s',dirSave,filename);
0331         saveas(figNum,(savename),'fig');
0332         print(figNum,'-depsc',[(savename),'.eps'])
0333         saveas(figNum,(savename),'png');
0334         disp (['Figure ', num2str(figNum) ,' is saved in eps, fig and png format at ',savename]);
0335         
0336     elseif numel(c) >= 4 && strcmpi(c(1:4), 'find') % Find Single Cells as F(number), an X appears on the iamge wehre the cell is
0337         if numel(c) > 4
0338             find_num = floor(str2double(c(5:end)));
0339             if FLAGS.cell_flag && shouldUseErrorFiles(FLAGS)
0340                 regnum = find( data_c.regs.ID == find_num);
0341                 
0342                 if ~isempty( regnum )
0343                     plot(data_c.regs.props(regnum).Centroid(1),...
0344                         data_c.regs.props(regnum).Centroid(2), ...
0345                         'yx','MarkerSize',50);
0346                 else
0347                     disp('couldn''t find that cell');
0348                 end
0349             else
0350                 if (find_num <= data_c.regs.num_regs) && (find_num >0)
0351                     plot(data_c.regs.props(find_num).Centroid(1),...
0352                         data_c.regs.props(find_num).Centroid(2), ...
0353                         'yx','MarkerSize',50);
0354                 else
0355                     disp( 'Out of range' );
0356                 end
0357             end
0358             input('Press any key','s');
0359         else
0360             disp ('Please provide cell number');
0361         end
0362         
0363     elseif strcmpi(c(1),'x')   % Change xy positions
0364         
0365         if numel(c)>1
0366             c = c(2:end);
0367             ll_ = floor(str2num(c));
0368             
0369             if ~isempty(ll_) && (ll_>=1) && (ll_<=num_xy)
0370                 try
0371                     save( [dirname0,contents_xy(dirnum).name,filesep,'clist.mat'],'-STRUCT','clist');
0372                 catch ME
0373                     printError(ME);
0374                     disp( 'Error writing clist file.');
0375                 end
0376                 
0377                 dirnum = ll_;
0378                 dirname_seg = [dirname0,contents_xy(ll_).name,filesep,'seg',filesep];
0379                 dirname_cell = [dirname0,contents_xy(ll_).name,filesep,'cell',filesep];
0380                 dirname_xy = [dirname0,contents_xy(ll_).name,filesep];
0381                 ixy = intGetNum( contents_xy(dirnum).name );
0382                 header = ['xy',num2str(ixy),': '];
0383                 contents=dir([dirname_seg, '*seg.mat']);
0384                 error_list = [];
0385                 clist = load([dirname0,contents_xy(ll_).name,filesep,'clist.mat']);
0386                 resetFlag = true;
0387             else
0388                 disp ('Incorrect number for xy position');
0389             end
0390             
0391         else
0392             disp ('Number of xy position missing');
0393             
0394         end
0395         
0396     elseif strcmpi(c,'r')  % Show/Hide Region Outlines
0397         FLAGS.P_flag = ~FLAGS.P_flag;
0398         FLAGS.Outline_flag = 0;
0399         
0400     elseif strcmpi(c,'outline') % Show/Hide Region Outlines
0401         FLAGS.Outline_flag = ~FLAGS.Outline_flag;
0402         
0403     elseif strcmpi(c,'reset') % Reset axis to default
0404         first_flag = true;
0405         resetFlag = 1;
0406         
0407     elseif numel(c) == 2 && c(1) == 'f' && isnum(c(2)) % Toggle Between Fluorescence and Phase Images
0408         disp('toggling between phase and fluorescence');
0409         f = 0;
0410         while true
0411             if isfield(data_c, ['fluor' num2str(f+1)] )
0412                 f = f+1;
0413             else
0414                 break
0415             end
0416         end
0417         c = round(str2double(c(2)));
0418         if isnan(c) || c < 0 || c > f
0419             FLAGS.f_flag = 0;
0420         else
0421             FLAGS.f_flag = c;
0422         end
0423         
0424     elseif strcmpi(c, 'filter') % Toggle Between filtered and unfiltered
0425         disp('filtering');
0426         FLAGS.filt = ~ FLAGS.filt;
0427         
0428     elseif strcmpi(c,'g') % choose characteristics and values to gate cells
0429         disp('Choose gating characteristic')
0430         disp(clist.def')
0431         cc = input('Gate Number(s) [ ] :','s') ;
0432         figure(2)
0433         clist = gateMake(clist,str2num(cc)) ;
0434         resetFlag = 1;
0435         
0436     elseif strcmpi(c,'Clear')  % Clear All Gates
0437         tmp_axis = axis;
0438         clist.gate = [] ;
0439         clf;
0440         resetFlag = 1;
0441         axis( tmp_axis );
0442         
0443     elseif strcmpi(c,'MoveG')   % moves gated cell files to a different directory
0444         header = 'trackOptiView: ';
0445         trackOptiGateCellFiles( dirname_cell, clist);
0446         
0447     elseif strcmpi(c, 'Gtot')
0448         % creates a clist for all xy positions, gated from loaded clist.
0449         if ~isfield( clist, 'gate' )
0450             clist.gate = [];
0451         end
0452         
0453         for ll_ = 1:num_xy
0454             filename = [dirname0,contents_xy(ll_).name,filesep,'clist.mat'];
0455             clist_tmp = gate(load(filename ));
0456             if  ll_ == 1
0457                 clist_comp =clist_tmp;
0458             else
0459                 clist_comp.data = [clist_comp.data; clist_tmp.data];
0460             end
0461         end
0462         
0463         save( [dirname0,'clist_comp.mat'], '-STRUCT', 'clist_comp' );
0464         
0465         
0466     elseif strcmpi(c,'id') % Show Cell Numbers
0467         FLAGS.ID_flag = ~FLAGS.ID_flag;
0468         if FLAGS.ID_flag
0469             FLAGS.regionScores = 0;
0470         end
0471         
0472     elseif strcmpi(c,'s') % Show Fluorescent Foci score values
0473         FLAGS.s_flag = ~FLAGS.s_flag;
0474         
0475     elseif numel(c) > 1 && c(1) == 's' && all(isnum(c(2:end))) % Toggle Between Fluorescence and Phase Images
0476         disp(['showing foci with scores higher than  ', c(2:end)]);
0477         FLAGS.s_flag = 1;
0478         CONST.getLocusTracks.FLUOR1_MIN_SCORE = str2double(c(2:end));
0479         
0480     elseif strcmpi(c,'p')  % Show Cell Poles
0481         FLAGS.p_flag = ~FLAGS.p_flag;
0482         
0483     elseif strcmpi(c,'k') % Enter Debugging Mode
0484         tmp_axis = axis;
0485         disp('Press "continue" on the editor tab to exit debugging mode')
0486         keyboard
0487         clf;
0488         axis( tmp_axis );
0489         
0490     elseif strcmpi(c,'KymAll') % Make Kymograph Mosaic for All Cells
0491         tmp_axis = axis;
0492         clf;
0493         makeKymoMosaic( dirname_cell, CONST );
0494         disp('press enter to continue.');
0495         pause;
0496         axis(tmp_axis);
0497         
0498     elseif strcmpi(c,'twrAll') %  Show Cell Towers for All Cells
0499         tmp_axis = axis;
0500         clf;
0501         
0502         if numel(c) > 1
0503             ll_ = floor(str2num(c(2:end)));
0504         else
0505             ll_ = [];
0506         end
0507         
0508         makeFrameStripeMosaic([dirname_cell], CONST, ll_,true );
0509         axis equal
0510         
0511         disp('press enter to continue.');
0512         pause;
0513         axis(tmp_axis);
0514         
0515     elseif strcmpi(c,'con') % Show existant consensus for this XY or calculate new one
0516         % it uses the current clist if datImArray has not been recalculated
0517         % before
0518         skip = 5;
0519         mag = 4;
0520         fnum = 1;
0521         alreadyExistsImArray = exist('dataImArray','var') && ~isempty(dataImArray);
0522         if alreadyExistsImArray
0523             answer = input(' dataImArray already calculated - recalculate? [y/n]:','s');
0524         end
0525         
0526         if ~alreadyExistsImArray || strcmpi(answer,'y')
0527             [dataImArray] = makeConsensusArray( dirname_cell, CONST, skip,mag,fnum);
0528             save ([dirSave,'dataImArray'],'dataImArray');
0529         end
0530         
0531         [imMosaic, imColor, imBW, imInv, imMosaic10 ] = makeConsensusImage( dataImArray,CONST,skip,mag,0);
0532         figure(2)
0533         clf
0534         imshow(imColor)
0535         disp('press enter to continue.');
0536         pause;
0537         
0538     elseif strcmpi(c,'cKym') % Show existant consensus for this XY or calculate new one
0539         skip = 5;
0540         mag = 4;
0541         fnum = 1;
0542         alreadyExistsImArray = exist('dataImArray','var') && ~isempty(dataImArray);
0543         if alreadyExistsImArray
0544             answer = input(' dataImArray already calculated - recalculate? [y/n]:','s');
0545         end
0546         
0547         if ~alreadyExistsImArray || strcmpi(answer,'y')
0548             [dataImArray] = makeConsensusArray( dirname_cell, CONST, skip,mag,fnum);
0549             save ([dirSave,'dataImArray'],'dataImArray');
0550         end
0551         
0552         
0553         [kymo,kymoMask] = makeConsensusKymo(dataImArray.imCellNorm, dataImArray.maskCell , 1);
0554         disp('press enter to continue.');
0555         pause;
0556     elseif numel(c)>2 && strcmpi(c(1:3),'twr') % Cell Tower for Single Cell
0557         
0558         if numel(c) > 3
0559             comma_pos = findstr(c,',');
0560             
0561             if isempty(comma_pos)
0562                 ll_ = floor(str2num(c(4:end)));
0563                 xdim__ = [];
0564             else
0565                 ll_ = floor(str2num(c(4:comma_pos(1))));
0566                 xdim__ = floor(str2num(c(comma_pos(1):end)));
0567             end
0568             
0569             padStr = getPadSize( dirname_cell, [] );
0570             
0571             if ~isempty( padStr )
0572                 data_cell = [];
0573                 filename_cell_C = [dirname_cell,'Cell',num2str(ll_,padStr),'.mat'];
0574                 filename_cell_c = [dirname_cell,'cell',num2str(ll_,padStr),'.mat'];
0575                 
0576                 if exist(filename_cell_C, 'file' )
0577                     filename_cell = filename_cell_C;
0578                 elseif exist(filename_cell_c, 'file' )
0579                     filename_cell = filename_cell_c;
0580                 else
0581                     filename_cell = [];
0582                 end
0583                 
0584                 if isempty( filename_cell )
0585                     disp( ['Files: ',filename_cell_C,' and ',filename_cell_c,' do not exist.']);
0586                 else
0587                     try
0588                         data_cell = load( filename_cell );
0589                     catch ME
0590                         printError(ME);
0591                         disp(['Error loading: ', filename_cell] );
0592                     end
0593                     
0594                     if ~isempty( data_cell )
0595                         figure(2);
0596                         clf;
0597                         im_tmp = makeFrameMosaic(data_cell, CONST, xdim__);
0598                     end
0599                     
0600                 end
0601             end
0602         else
0603             disp ('Please enter a number next to twr');
0604         end
0605         
0606     elseif numel(c)>2 && strcmpi(c(1:3),'kym') % Show Kymograph for Single Cell
0607         
0608         if numel(c) > 3
0609             num = floor(str2num(c(4:end)));
0610             data_cell = loadCellData(num,dirname_cell, []);
0611             
0612             if ~isempty( data_cell )
0613                 figure(2);
0614                 clf;
0615                 makeKymographC(data_cell, 1, CONST,[],FLAGS.filt);
0616                 ylabel('Long Axis (pixels)');
0617                 xlabel('Time (frames)' );
0618                 disp('Press enter to continue');
0619             end
0620         else
0621             disp ('Please enter a number next to kym');
0622         end
0623         
0624     elseif numel(c)>5 && strcmpi(c(1:5),'movie') % movie for single Cell
0625         if numel(c) > 5
0626             num = floor(str2double(c(6:end)));
0627             [data_cell,cell_name] = loadCellData(num,dirname_cell, []);
0628             if ~isempty(data_cell)
0629                 mov = makeCellMovie(data_cell);
0630                 disp('Save movie?')
0631                 d = input('[y/n]:','s');
0632                 if strcmpi(d,'y')
0633                     saveFilename = [dirSave,cell_name(1:end-4),'.avi'];
0634                     disp (['Saving movie at ',saveFilename]);
0635                     v = VideoWriter(saveFilename);
0636                     open(v)
0637                     writeVideo(v,mov)
0638                     close(v)
0639                 end
0640             end
0641         end
0642         
0643     elseif strcmpi(c,'movie')  % Make Time-Lapse Images for Movies
0644         
0645         tmp_axis = axis;
0646         
0647         clear mov;
0648         mov.cdata = [];
0649         mov.colormap = [];
0650         
0651         for ii = 1:num_im
0652             [data_r, data_c, data_f] = intLoadDataViewer( dirname_seg, ...
0653                 contents, ii, num_im, clist, FLAGS);
0654             tmp_im =  showSeggerImage( data_c, data_r, data_f, FLAGS, clist, CONST, []);
0655             axis(tmp_axis);
0656             drawnow;
0657             mov(ii) = getframe;
0658             disp( ['Frame number: ', num2str(ii)] );
0659         end
0660         
0661         
0662         disp('Save movie?')
0663         d = input('[y/n]:','s');
0664         if strcmpi(d,'y')
0665             name = input('filename:','s');
0666             saveFilename = [dirSave,name,'.avi'];
0667             disp (['Saving movie at ',saveFilename]);
0668             v = VideoWriter(saveFilename);
0669             v.FrameRate = 2; % frames per second
0670             open(v)
0671             writeVideo(v,mov)
0672             close(v)
0673         end
0674         
0675         resetFlag = true;
0676         
0677     elseif strcmpi(c,'e')
0678         % Show Error List
0679         FLAGS.e_flag = ~FLAGS.e_flag;
0680         
0681     elseif strcmpi(c,'rs') % Toggle display of region scores
0682         FLAGS.regionScores = ~FLAGS.regionScores;
0683         if FLAGS.regionScores
0684             FLAGS.ID_flag = 0;
0685         end
0686         
0687     elseif strcmpi(c,'seg') % Toggle display of region scores
0688         FLAGS.useSegs = ~FLAGS.useSegs;
0689         resetFlag = true;
0690         
0691         %% DEVELOPER FUNCTIONS : Use at your own risk
0692     elseif strcmpi(c,'link')  % Show links
0693         FLAGS.showLinks = ~FLAGS.showLinks;
0694         resetFlag = true;
0695         
0696     elseif strcmpi(c,'mother')  % Show links
0697         FLAGS.showMothers = ~FLAGS.showMothers;
0698         
0699     elseif strcmpi(c,'daughter')  % Show links
0700         FLAGS.showDaughters = ~FLAGS.showDaughters;
0701         
0702     elseif strcmpi(c,'editSegs')  % Edit Segments, allows to turn on and off segments
0703         disp('Are you sure you want to edit the segments?')
0704         d = input('[y/n]:','s');
0705         if strcmpi(d,'y')
0706             segsTLEdit(dirname_seg, nn, CONST);
0707         end
0708         
0709     elseif strcmpi(c, 'relink') % Re-Link - relinks the cells after modifications in segments
0710         disp('Are you sure you want to relink and remake the cell files?')
0711         d = input('[y/n]:','s');
0712         if strcmpi(d,'y')
0713             delete([dirname_cell,'*.mat']);
0714             delete([dirname,'*trk.mat*']);
0715             delete([dirname,'*err.mat*']);
0716             delete([dirname,'.trackOpti*']);
0717             delete([dirname_xy,'clist.mat']);
0718             % Re-Run trackOpti
0719             skip = 1;
0720             CLEAN_FLAG = false;
0721             header = 'trackOptiView: ';
0722             trackOpti(dirname_xy,skip,CONST, CLEAN_FLAG, header);
0723         end
0724     else % we assume that it is a number for a frame change.
0725         tmp_nn = str2num(c);
0726         if ~isempty(tmp_nn)
0727             nn = tmp_nn;
0728             if nn > num_im;
0729                 nn = num_im;
0730             elseif nn< 1
0731                 nn = 1;
0732             end
0733             resetFlag = true;
0734         else % not a number - command not found
0735             disp ('Command not found');
0736         end
0737     end
0738 end
0739 
0740 try
0741     save(filename_flags, 'FLAGS', 'nn', 'dirnum', 'error_list' );
0742 catch
0743     disp('Error saving flag preferences.');
0744 end
0745 
0746 end
0747 
0748 
0749 % END OF MAIN FUNCTION (superSeggerViewer)
0750 
0751 % INTERNAL FUNCTIONS
0752 function [nameInfo] = getDirStruct( dirname )
0753 
0754 contents = dir( [dirname,filesep,'*.tif'] );
0755 
0756 nt  = [];
0757 nc  = [];
0758 nxy = [];
0759 nz  = [];
0760 
0761 num_im = numel(contents);
0762 
0763 for i = 1:num_im;
0764     nameInfo = ReadFileName( contents(i).name );
0765     
0766     nt  = [nt,  nameInfo.npos(1,1)];
0767     nc  = [nc,  nameInfo.npos(2,1)];
0768     nxy = [nxy, nameInfo.npos(3,1)];
0769     nz  = [nz,  nameInfo.npos(4,1)];
0770 end
0771 
0772 nt  = sort(unique(nt));
0773 nc  = sort(unique(nc));
0774 nxy = sort(unique(nxy));
0775 nz  = sort(unique(nz));
0776 
0777 xyPadSize = floor(log(max(nxy))/log(10))+1;
0778 padString = ['%0',num2str(xyPadSize),'d'];
0779 
0780 num_xy = numel(nxy);
0781 num_c  = numel(nc);
0782 num_z  = numel(nz);
0783 num_t  = numel(nt);
0784 
0785 nameInfo.nt  = nt;
0786 nameInfo.nc  = nc;
0787 nameInfo.nxy = nxy;
0788 nameInfo.nz  = nz;
0789 end
0790 
0791 function ixy = intGetNum( str_xy )
0792 ixy = str2num(str_xy(ismember(str_xy, '0123456789' )));
0793 end
0794 
0795 function intDispError( data_c, FLAGS )
0796 % intDispError
0797 for kk = 1:data_c.regs.num_regs
0798     if isfield(data_c,'regs') &&...
0799             isfield(data_c.regs, 'error') && ...
0800             isfield(data_c.regs.error,'label') && ...
0801             ~isempty( data_c.regs.error.label{kk} )
0802         if FLAGS.cell_flag && shouldUseErrorFiles(FLAGS) && isfield( data_c.regs, 'ID' )
0803             disp(  ['Cell: ', num2str(data_c.regs.ID(kk)), ', ', ...
0804                 data_c.regs.error.label{kk}] );
0805         else
0806             disp(  [ data_c.regs.error.label{kk}] );
0807         end
0808     end
0809 end
0810 end
0811 
0812 
0813 function flagsStates = intSetStateStrings(FLAGS,CONST)
0814 % intSetStateStrings : sets default flags for when the program begins
0815 flagsStates.vState = '(on) ';
0816 flagsStates.mState = '(on) ';
0817 flagsStates.idState = '(on) ';
0818 flagsStates.TState = '(on) ';
0819 flagsStates.PState ='(on) ';
0820 flagsStates.pState ='(off) ';
0821 flagsStates.rState = '(on) ';
0822 flagsStates.eState = '(on) ';
0823 flagsStates.fState = '(Fluor)';
0824 flagsStates.CCState ='(on) ';
0825 flagsStates.PValState = '';
0826 flagsStates.lyseState = '';
0827 flagsStates.sState = '(on) ';
0828 
0829 if ~FLAGS.cell_flag
0830     flagsStates.vState = '(off)';
0831 end
0832 
0833 if ~FLAGS.Outline_flag
0834     flagsStates.vState = '(off)';
0835 end
0836 
0837 if ~FLAGS.m_flag
0838     flagsStates.mState = '(off)';
0839 end
0840 
0841 if ~FLAGS.ID_flag
0842     flagsStates.idState = '(off)';
0843 end
0844 
0845 if ~FLAGS.T_flag
0846     flagsStates.TState = '(off)';
0847 end
0848 
0849 if ~FLAGS.P_flag % regions
0850     flagsStates.rState = '(off)';
0851 end
0852 if ~FLAGS.e_flag
0853     flagsStates.eState = '(off)';
0854 end
0855 
0856 if ~FLAGS.f_flag
0857     flagsStates.fState = '(Phase)';
0858 end
0859 
0860 if ~FLAGS.s_flag
0861     flagsStates.sState = '(off)';
0862 end
0863 if ~FLAGS.p_flag
0864     flagsStates.pState = '(off)';
0865 end
0866 if ~CONST.view.showFullCellCycleOnly
0867     flagsStates.CCState= '(off)';
0868 end
0869 if ~FLAGS.lyse_flag
0870     flagsStates.lyseState = '(off)';
0871 end
0872 flagsStates.falseColState = '(on) ';
0873 if ~CONST.view.falseColorFlag
0874     flagsStates.falseColState= '(off)';
0875 end
0876 
0877 flagsStates.logState = '(on) ';
0878 if ~CONST.view.LogView
0879     flagsStates.logState = '(off)';
0880 end
0881 
0882 flagsStates.filtState = '(on) ';
0883 if ~FLAGS.filt
0884     flagsStates.filtState = '(off)';
0885 end
0886 
0887 flagsStates.regionScores = '(on) ';
0888 if ~FLAGS.regionScores
0889     flagsStates.regionScores = '(off)';
0890 end
0891 
0892 flagsStates.useSegs = '(on) ';
0893 if ~FLAGS.useSegs
0894     flagsStates.useSegs = '(off)';
0895 end
0896 
0897 
0898 flagsStates.showLinks = '(on) ';
0899 if ~FLAGS.showLinks
0900     flagsStates.showLinks = '(off)';
0901 end
0902 
0903 flagsStates.showDaughters = '(on) ';
0904 if ~FLAGS.showDaughters
0905     flagsStates.showDaughters = '(off)';
0906 end
0907 
0908 flagsStates.showMothers = '(on) ';
0909 if ~FLAGS.showMothers
0910     flagsStates.showMothers = '(off)';
0911 end
0912 
0913 end
0914 
0915 
0916 function intCons(dirname0, contents_xy, setHeader, CONST)
0917 xyDir = [dirname0,contents_xy.name,filesep];
0918 dircons = [xyDir,'/consensus/']
0919 
0920 if ~exist(dircons,'dir')
0921     mkdir(dircons);
0922 end
0923 
0924 ixy = intGetNum( contents_xy.name );
0925 header = ['xy',num2str(ixy),': '];
0926 
0927 if exist([dircons, 'consColor_', setHeader, '_', num2str(ixy,'%02d'), '.tif'],'file')
0928     disp('Consensus Already Calculated')
0929     imColor = imread([dircons, 'consColor_', setHeader, '_', num2str(ixy,'%02d'), '.tif']);
0930     figure(1)
0931     clf
0932     imshow(imColor);
0933     disp('Press any key to continue')
0934     pause;
0935 else
0936     
0937     disp('No Images Found.')
0938     disp('Calculate New Consensus?')
0939     d = input('[y/n]:','s');
0940     
0941     if strcmpi(d,'y')
0942         if isdir([dirname0,contents_xy.name,filesep,'seg_full'])
0943             dirname = [dirname0,contents_xy.name,filesep,'seg_full',filesep];
0944         end
0945         
0946         dirname_cell = [dirname0,contents_xy.name,filesep,'cell',filesep];
0947         disp( ['Doing ',num2str(ixy)] );
0948         skip = 1;
0949         mag = 4;
0950         [dataImArray] = makeConsensusArray( [dirname_cell], CONST, skip, mag, [] );
0951         [imMosaic, imColor, imBW, imInv, imMosaic10 ] = makeConsensusImage( dataImArray,CONST,skip,mag,0);
0952         
0953         figure(1)
0954         clf
0955         imshow(imColor)
0956         
0957         if ~isempty( imMosaic10 )
0958             disp('Save consensus images?')
0959             d = input('[y/n]:','s');
0960             % this just saves the consensus images.
0961             if strcmpi(d,'y')
0962                 save([dircons,'consensus'],'imMosaic', 'imColor', 'imBW', 'imInv', 'imMosaic10');
0963                 imwrite( imBW,    [dircons, 'consBW_',    setHeader, '_', num2str(ixy,'%02d'), '.tif'], 'tif' );
0964                 imwrite( imColor, [dircons, 'consColor_', setHeader, '_', num2str(ixy,'%02d'), '.tif'], 'tif' );
0965                 imwrite( imInv,   [dircons, 'consInv_',   setHeader, '_', num2str(ixy,'%02d'), '.tif'], 'tif' );
0966                 imwrite( imMosaic10,   [dircons, 'typical_',   setHeader, '_', num2str(ixy,'%02d'), '.tif'], 'tif' );
0967             end
0968         else
0969             disp( ['Found no cells in ', dirname_cell, '.'] );
0970         end
0971         
0972     else
0973         
0974         return
0975         
0976     end
0977 end
0978 end

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