0001 function varargout = gateToolGui(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 gui_Singleton = 1;
0029 gui_State = struct('gui_Name', mfilename, ...
0030 'gui_Singleton', gui_Singleton, ...
0031 'gui_OpeningFcn', @gateToolGui_OpeningFcn, ...
0032 'gui_OutputFcn', @gateToolGui_OutputFcn, ...
0033 'gui_LayoutFcn', [] , ...
0034 'gui_Callback', []);
0035 if nargin && ischar(varargin{1})
0036 gui_State.gui_Callback = str2func(varargin{1});
0037 end
0038
0039 if nargout
0040 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0041 else
0042 gui_mainfcn(gui_State, varargin{:});
0043 end
0044
0045
0046
0047
0048 function gateToolGui_OpeningFcn(hObject, eventdata, handles, varargin)
0049
0050
0051
0052
0053
0054
0055
0056 handles.output = hObject;
0057 handles.dirname.String = pwd;
0058 handles.time_flag = 0;
0059 handles.clist_found = 0;
0060 handles.multi_clist = [];
0061 handles.replace_flag = 0;
0062 updateGui(hObject,handles)
0063
0064 set(handles.figure1, 'units', 'normalized', 'position', [0.2 0.1 0.35 0.75]);
0065
0066 guidata(hObject, handles);
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 function varargout = gateToolGui_OutputFcn(hObject, eventdata, handles)
0077
0078
0079
0080
0081
0082
0083 varargout{1} = handles.multi_clist;
0084
0085
0086 function updateGui(hObject,handles)
0087
0088 if isfield(handles,'multi_clist') && ~isempty(handles.multi_clist)
0089 handles.clist_found = 1;
0090 else
0091 handles.clist_found = 0;
0092 handles.msgbox.String = ['Clists : 0'];
0093 end
0094
0095
0096
0097 if handles.clist_found
0098
0099
0100 which_clist = getClist(handles);
0101
0102 if iscell(which_clist)
0103 which_clist = which_clist{1};
0104 end
0105
0106
0107 if handles.time_flag
0108 if isfield( which_clist(1), 'def3D' )
0109 handles.def1.String = ['None';which_clist(1).def3D'];
0110 handles.def2.String = ['None';which_clist(1).def3D'];
0111
0112 elseif isfield( which_clist(1), 'def3d' )
0113 handles.def1.String = ['None';which_clist(1).def3d'];
0114 handles.def2.String = ['None';which_clist(1).def3d'];
0115
0116 end
0117 else
0118 handles.def1.String = ['None';which_clist(1).def'];
0119 handles.def2.String = ['None';which_clist(1).def'];
0120 end
0121
0122 num_clist = numel(handles.multi_clist);
0123 names = {};
0124 for i = 1 : num_clist
0125 if iscell (handles.multi_clist)
0126 if ~isfield(handles.multi_clist{i},'name')
0127 handles.multi_clist{i}.name = ['data',num2str(i)];
0128 end
0129 names {end+1} = handles.multi_clist{i}.name;
0130
0131 elseif isstruct (handles.multi_clist)
0132 if ~isfield(handles.multi_clist(i),'name')
0133 handles.multi_clist(i).name = ['data',num2str(i)];
0134 end
0135 names {end+1} = handles.multi_clist(i).name;
0136 end
0137 end
0138 handles.clist_choice.String = ['All';names'];
0139 size1 = num2str(size(handles.multi_clist,1));
0140 size2 = num2str(size(handles.multi_clist,2));
0141 handles.msgbox.String = ['Clists : ', size1, ' x ', size2 ];
0142 set(findall(handles.action_panel, '-property', 'enable'), 'enable', 'on');
0143 set(findall(handles.show_panel, '-property', 'enable'), 'enable', 'on');
0144 set(findall(handles.save_panel, '-property', 'enable'), 'enable', 'on');
0145 set(findall(handles.def_panel, '-property', 'enable'), 'enable', 'on');
0146 else
0147 set(findall(handles.action_panel, '-property', 'enable'), 'enable', 'off');
0148 set(findall(handles.show_panel, '-property', 'enable'), 'enable', 'off');
0149 set(findall(handles.save_panel, '-property', 'enable'), 'enable', 'off');
0150 set(findall(handles.def_panel, '-property', 'enable'), 'enable', 'off');
0151
0152 end
0153
0154
0155 guidata(hObject,handles);
0156
0157 function which_clist = getClist(handles)
0158 if handles.clist_choice.Value == 1
0159 which_clist = handles.multi_clist;
0160 elseif isstruct(handles.multi_clist)
0161 which_clist = handles.multi_clist(handles.clist_choice.Value-1);
0162 else
0163 which_clist = handles.multi_clist{handles.clist_choice.Value-1};
0164 end
0165
0166
0167
0168 function xls_Callback(hObject, eventdata, handles)
0169
0170
0171
0172 [filename, pathName] = uiputfile('data.csv', 'Save xls file', handles.dirname.String);
0173 which_clist = getClist(handles);
0174 gateTool(which_clist,'xls',[pathName,filesep,filename]);
0175
0176
0177
0178 function csv_Callback(hObject, eventdata, handles)
0179
0180
0181
0182 [filename, pathName] = uiputfile('data.csv', 'Save csv file', handles.dirname.String);
0183 which_clist = getClist(handles);
0184 gateTool(which_clist,'csv',[pathName,filesep,filename]);
0185
0186
0187 function save_mat_file_Callback(hObject, eventdata, handles)
0188
0189
0190
0191 [filename, pathName] = uiputfile('clist.mat', 'Save clist file', handles.dirname.String);
0192 which_clist = getClist(handles);
0193 gateTool(which_clist,'save',[pathName,filesep,filename]);
0194
0195 function [tmp_clist] = loadClistFromDir()
0196 folderOrClist = uigetdir;
0197 if folderOrClist~=0
0198 tmp_clist = gateTool(folderOrClist);
0199 else
0200 tmp_clist = [];
0201 end
0202
0203
0204 function load_clist_Callback(hObject, eventdata, handles)
0205
0206
0207
0208 [tmp_clist] = loadClistFromDir();
0209 updateGui(hObject,handles)
0210
0211
0212
0213 function pushbutton2_Callback(hObject, eventdata, handles)
0214
0215
0216
0217
0218
0219
0220
0221
0222 function drill_Callback(hObject, eventdata, handles)
0223
0224
0225
0226 handles.multi_clist = gateTool(handles.dirname,'drill' );
0227 guidata(hObject,handles);
0228
0229
0230 function merge_Callback(hObject, eventdata, handles)
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 function dash_Callback(hObject, eventdata, handles)
0241
0242
0243
0244
0245
0246 handles.multi_clist = handles.multi_clist';
0247 guidata(hObject,handles);
0248
0249
0250 function strip_Callback(hObject, eventdata, handles)
0251
0252
0253
0254
0255
0256 if handles.clist_choice.Value == 1
0257 if handles.replace_flag
0258 handles.multi_clist = gateTool(handles.multi_clist,'strip');
0259 else
0260 tmp_clist = gateTool(handles.multi_clist,'strip','merge');
0261 tmp_clist.name = 'all_strip';
0262 handles.multi_clist{end+1} = tmp_clist;
0263 end
0264 elseif isstruct(handles.multi_clist)
0265 if handles.replace_flag
0266 handles.multi_clist(handles.clist_choice.Value-1) = gateTool(handles.multi_clist(handles.clist_choice.Value-1),'strip');
0267 else
0268 clist_bef = handles.multi_clist(handles.clist_choice.Value-1);
0269 name_bef = clist_bef.name;
0270 tmp_striped = gateTool(clist_bef,'strip');
0271 tmp_striped.name = [name_bef,'stripped'];
0272 handles.multi_clist = {};
0273 handles.multi_clist{1} = clist_bef;
0274 handles.multi_clist{2} = tmp_striped;
0275 end
0276 else
0277 if handles.replace_flag
0278 handles.multi_clist{handles.clist_choice.Value-1} = gateTool(handles.multi_clist{handles.clist_choice.Value-1},'strip');
0279 else
0280 clist_bef = handles.multi_clist{handles.clist_choice.Value-1};
0281 name_bef = clist_bef.name;
0282 tmp_striped = gateTool(clist_bef,'strip');
0283 tmp_striped.name = [name_bef,'stripped'];
0284 handles.multi_clist{end+1} = tmp_striped;
0285 end
0286 end
0287
0288 updateGui(hObject,handles);
0289 guidata(hObject,handles);
0290
0291
0292
0293 function squeeze_Callback(hObject, eventdata, handles)
0294
0295
0296
0297
0298 handles.multi_clist = gateTool(handles.multi_clist,'squeeze');
0299 guidata(hObject,handles);
0300 updateGui(hObject,handles)
0301
0302
0303 function expand_Callback(hObject, eventdata, handles)
0304
0305
0306
0307 handles.multi_clist = gateTool(handles.multi_clist,'expand');
0308 guidata(hObject,handles);
0309 updateGui(hObject,handles)
0310
0311
0312 function kde_Callback(hObject, eventdata, handles)
0313
0314
0315
0316
0317
0318
0319 if get(hObject,'Value')
0320 if get(handles.dot,'Value')
0321 handles.dot.Value = 0;
0322 end
0323 if get(handles.hist,'Value')
0324 handles.hist.Value = 0;
0325 end
0326 end
0327
0328
0329
0330 function stats_Callback(hObject, eventdata, handles)
0331
0332
0333
0334
0335
0336
0337
0338
0339 function time_Callback(hObject, eventdata, handles)
0340
0341
0342
0343
0344
0345 if get(hObject,'Value')
0346 handles.time_flag = 1;
0347 else
0348 handles.time_flag = 0;
0349 end
0350
0351 updateGui(hObject,handles)
0352
0353 function def1_Callback(hObject, eventdata, handles)
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363 function def1_CreateFcn(hObject, eventdata, handles)
0364
0365
0366
0367
0368
0369
0370 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0371 set(hObject,'BackgroundColor','white');
0372 end
0373
0374
0375
0376 function def2_Callback(hObject, eventdata, handles)
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386 function def2_CreateFcn(hObject, eventdata, handles)
0387
0388
0389
0390
0391
0392
0393 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0394 set(hObject,'BackgroundColor','white');
0395 end
0396
0397
0398
0399 function hist_Callback(hObject, eventdata, handles)
0400
0401
0402
0403
0404
0405
0406 if get(hObject,'Value')
0407 if get(handles.dot,'Value')
0408 handles.dot.Value = 0;
0409 end
0410 if get(handles.kde,'Value')
0411 handles.kde.Value = 0;
0412 end
0413 end
0414
0415
0416 function dot_Callback(hObject, eventdata, handles)
0417
0418
0419
0420
0421
0422 if get(hObject,'Value')
0423 if get(handles.hist,'Value')
0424 handles.hist.Value = 0;
0425 end
0426 if get(handles.kde,'Value')
0427 handles.kde.Value = 0;
0428 end
0429
0430 end
0431
0432
0433 function log_Callback(hObject, eventdata, handles)
0434
0435
0436
0437
0438
0439
0440
0441
0442 function cond_Callback(hObject, eventdata, handles)
0443
0444
0445
0446
0447
0448 if get(hObject,'Value')
0449 handles.density.Value = 0;
0450 end
0451
0452
0453 function show_gates_Callback(hObject, eventdata, handles)
0454
0455
0456
0457
0458 index1 = handles.def1.Value - 1;
0459 index2 = handles.def2.Value - 1;
0460
0461 varg = {'show'};
0462
0463
0464 if ~index1 && ~index2
0465
0466 elseif index1~=0 && index2 == 0
0467 varg{end+1} = index1;
0468 elseif index1==0 && index2 ~= 0
0469 varg{end+1} = index2;
0470 elseif index1~=0 && index2 ~= 0
0471 varg{end+1} = [index1, index2];
0472 end
0473
0474 if handles.time.Value
0475 varg{end+1} = 'time';
0476 end
0477
0478
0479 if handles.stats.Value
0480 varg{end+1} = 'stat';
0481 end
0482
0483 if handles.kde.Value
0484 varg{end+1} = 'kde';
0485 end
0486
0487 if handles.hist.Value
0488 varg{end+1} = 'hist';
0489 end
0490 if handles.dot.Value
0491 varg{end+1} = 'dot';
0492 if handles.line.Value
0493 varg{end+1} = 'line';
0494 end
0495 end
0496
0497 if handles.log.Value
0498 varg{end+1} = 'log';
0499 log_axis = [];
0500 if handles.x_box.Value
0501 log_axis = [log_axis;1];
0502 end
0503 if handles.y_box.Value
0504 log_axis = [log_axis;2];
0505 end
0506 if handles.z_box.Value
0507 log_axis = [log_axis;3];
0508 end
0509 if ~isempty(log_axis)
0510 varg{end+1} = log_axis';
0511 end
0512
0513 end
0514 if handles.cond.Value
0515 varg{end+1} = 'cond';
0516 end
0517
0518 if handles.density.Value
0519 varg{end+1} = 'den';
0520 end
0521
0522 if handles.err.Value
0523 varg{end+1} = 'err';
0524 end
0525
0526 if handles.merge.Value
0527 varg{end+1} = 'merge';
0528 end
0529
0530
0531 which_clist = getClist(handles)
0532 figure;
0533 gateTool(which_clist,varg{:},'no clear');
0534
0535
0536 function err_Callback(hObject, eventdata, handles)
0537
0538
0539
0540
0541
0542
0543
0544
0545 function load_Callback(hObject, eventdata, handles)
0546
0547
0548
0549
0550 if ~isempty(handles.dirname.String)
0551 handles.multi_clist = gateTool(handles.dirname.String);
0552 updateGui(hObject,handles)
0553 end
0554
0555
0556 function add_Callback(hObject, eventdata, handles)
0557
0558
0559
0560 [loaded_clist] = loadClistFromDir();
0561 if iscell(loaded_clist) && size(loaded_clist,2) ==1
0562 loaded_clist = loaded_clist{1};
0563 end
0564
0565 if isstruct(handles.multi_clist)
0566 tmp_before = handles.multi_clist;
0567 handles.multi_clist = {};
0568 handles.multi_clist{1} = tmp_before;
0569 end
0570
0571 handles.multi_clist{end+1} = loaded_clist;
0572 updateGui(hObject,handles)
0573
0574
0575 function delete_Callback(hObject, eventdata, handles)
0576
0577
0578
0579
0580 if handles.clist_choice.Value == 1
0581 handles.multi_clist = [];
0582 elseif isstruct(handles.multi_clist)
0583 handles.multi_clist(handles.clist_choice.Value-1) =[];
0584 else
0585 handles.multi_clist{handles.clist_choice.Value-1} =[];
0586 handles.multi_clist = handles.multi_clist(~cellfun('isempty', handles.multi_clist))
0587 end
0588
0589 handles.clist_choice.Value = 1;
0590 updateGui(hObject,handles);
0591
0592
0593 function def3d_Callback(hObject, eventdata, handles)
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603 function def3d_CreateFcn(hObject, eventdata, handles)
0604
0605
0606
0607
0608
0609
0610 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0611 set(hObject,'BackgroundColor','white');
0612 end
0613
0614
0615
0616 function make_gate_Callback(hObject, eventdata, handles)
0617
0618
0619
0620
0621 index1 = handles.def1.Value - 1;
0622 index2 = handles.def2.Value - 1;
0623
0624
0625 varg = {'make'};
0626
0627 if ~index1 && ~index2
0628 msgbox ('choose an index')
0629 elseif index1~=0 && index2 == 0
0630 varg{end+1} = index1;
0631 elseif index1==0 && index2 ~= 0
0632 varg{end+1} = index2;
0633 elseif index1~=0 && index2 ~= 0
0634 varg{end+1} = [index1, index2];
0635 end
0636
0637
0638 if handles.merge.Value
0639 varg{end+1} = 'merge';
0640 end
0641
0642 if index1 || index2
0643 if handles.clist_choice.Value == 1
0644 if handles.replace_flag
0645 handles.multi_clist = gateTool(handles.multi_clist,varg{:},'no clear','newfig');
0646 else
0647 tmp_clist = gateTool(handles.multi_clist,varg{:},'merge','no clear','newfig');
0648 tmp_clist.name = 'all_gated';
0649 handles.multi_clist{end+1} = tmp_clist;
0650 end
0651 elseif isstruct(handles.multi_clist)
0652 if handles.replace_flag
0653 handles.multi_clist(handles.clist_choice.Value-1) = gateTool(handles.multi_clist(handles.clist_choice.Value-1),varg{:},'no clear','newfig');
0654 else
0655 tmp = handles.multi_clist;
0656 handles.multi_clist = {};
0657 handles.multi_clist{1} = tmp;
0658 name_bef = tmp.name;
0659 handles.multi_clist{2} = gateTool(tmp,varg{:},'no clear','newfig');
0660 handles.clist_choice.Value = numel(handles.multi_clist)+1;
0661 handles = naming_func (handles,[name_bef,'gated']);
0662 end
0663 else
0664 if handles.replace_flag
0665 handles.multi_clist{handles.clist_choice.Value-1} = gateTool(handles.multi_clist{handles.clist_choice.Value-1},varg{:},'no clear','newfig');
0666 else
0667 name_bef = handles.multi_clist{handles.clist_choice.Value-1}.name;
0668 handles.multi_clist{end+1} = gateTool(handles.multi_clist{handles.clist_choice.Value-1},varg{:},'no clear','newfig');
0669 handles.clist_choice.Value = numel(handles.multi_clist)+1;
0670 handles = naming_func (handles,[name_bef,'gated']);
0671 end
0672 end
0673 end
0674 updateGui(hObject,handles);
0675 guidata(hObject,handles);
0676
0677
0678
0679 function dirname_Callback(hObject, eventdata, handles)
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689 function dirname_CreateFcn(hObject, eventdata, handles)
0690
0691
0692
0693
0694
0695
0696 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0697 set(hObject,'BackgroundColor','white');
0698 end
0699
0700
0701
0702 function uipushtool1_ClickedCallback(hObject, eventdata, handles)
0703
0704
0705
0706 handles.dirname.String = uigetdir;
0707 guidata(hObject,handles);
0708
0709
0710 function hist_tool_ClickedCallback(hObject, eventdata, handles)
0711
0712
0713
0714 handles.hist.Value = 1;
0715 show_gates_Callback(hObject, eventdata, handles);
0716 handles.hist.Value = 0;
0717
0718
0719 function contour_tool_ClickedCallback(hObject, eventdata, handles)
0720
0721
0722
0723 handles.kde.Value = 1;
0724 show_gates_Callback(hObject, eventdata, handles);
0725 handles.kde.Value = 0;
0726
0727
0728
0729 function scatter_tool_ClickedCallback(hObject, eventdata, handles)
0730
0731
0732
0733 handles.dot.Value = 1;
0734 show_gates_Callback(hObject, eventdata, handles);
0735 handles.dot.Value = 0;
0736
0737
0738 function debug_ClickedCallback(hObject, eventdata, handles)
0739
0740
0741
0742 keyboard;
0743
0744
0745
0746 function close_figs_Callback(hObject, eventdata, handles)
0747
0748
0749
0750
0751 fh=findall(0,'Type','Figure');
0752 for i = 1 : numel(fh)
0753 if ~strcmp(fh(i).Name,'gateToolGui')
0754 close(fh(i));
0755 end
0756 end
0757
0758
0759 function clear_gate_Callback(hObject, eventdata, handles)
0760
0761
0762
0763
0764 if handles.clist_choice.Value == 1
0765 handles.multi_clist = gateTool(handles.multi_clist,'clear');
0766 elseif isstruct(handles.multi_clist)
0767 handles.multi_clist(handles.clist_choice.Value-1) = gateTool(handles.multi_clist(handles.clist_choice.Value-1),'clear');
0768 else
0769 handles.multi_clist{handles.clist_choice.Value-1} = gateTool(handles.multi_clist{handles.clist_choice.Value-1},'clear');
0770 end
0771
0772 updateGui(hObject,handles);
0773 guidata(hObject,handles);
0774
0775 function handles = naming_func (handles,name)
0776 if handles.clist_choice.Value == 1
0777 handles.multi_clist = gateTool(handles.multi_clist,'name',name);
0778 elseif isstruct(handles.multi_clist)
0779 handles.multi_clist(handles.clist_choice.Value-1) = gateTool(handles.multi_clist(handles.clist_choice.Value-1),'name',name);
0780 else
0781 handles.multi_clist{handles.clist_choice.Value-1} = gateTool(handles.multi_clist{handles.clist_choice.Value-1},'name',name);
0782 end
0783
0784
0785
0786 function name_Callback(hObject, eventdata, handles)
0787
0788
0789
0790
0791
0792 name = getString ('Clist name', 'Type clist name');
0793 handles = naming_func (handles,name);
0794 updateGui(hObject,handles)
0795
0796 function num_return = getNumber (dlg_title, prompt)
0797
0798 num_lines = 1;
0799 a = inputdlg(prompt,dlg_title,num_lines);
0800
0801 if ~isempty(a)
0802 num_return = str2double(a(1));
0803 else
0804 num_return = [];
0805 end
0806
0807
0808 function str_return = getString (dlg_title, prompt)
0809
0810 num_lines = 1;
0811 a = inputdlg(prompt,dlg_title,num_lines);
0812 if ~isempty(a)
0813 str_return = a{1};
0814 else
0815 str_return = [];
0816 end
0817
0818
0819
0820 function clist_choice_Callback(hObject, eventdata, handles)
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830 function clist_choice_CreateFcn(hObject, eventdata, handles)
0831
0832
0833
0834
0835
0836
0837 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0838 set(hObject,'BackgroundColor','white');
0839 end
0840
0841
0842
0843 function replace_Callback(hObject, eventdata, handles)
0844
0845
0846
0847
0848
0849 if get(hObject,'Value')
0850 handles.replace_flag = 1;
0851 else
0852 handles.replace_flag = 0;
0853 end
0854 guidata(hObject,handles);
0855
0856
0857 function x_box_Callback(hObject, eventdata, handles)
0858
0859
0860
0861
0862
0863
0864
0865
0866 function y_box_Callback(hObject, eventdata, handles)
0867
0868
0869
0870
0871
0872
0873
0874
0875 function z_box_Callback(hObject, eventdata, handles)
0876
0877
0878
0879
0880
0881
0882
0883
0884 function density_Callback(hObject, eventdata, handles)
0885
0886
0887
0888
0889
0890 if get(hObject,'Value')
0891 handles.cond.Value = 0
0892 end
0893
0894
0895
0896 function line_Callback(hObject, eventdata, handles)
0897
0898
0899
0900
0901