-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRexDataGUI.m
1701 lines (1445 loc) · 77.5 KB
/
RexDataGUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = RexDataGUI(varargin)
% REXDATAGUI MATLAB code for RexDataGUI.fig
% Designed to make Rex data analysis easier, more efficient, and nicer to
% the eye. VP 02/2012
%
% REXDATAGUI, by itself, creates a new REXDATAGUI or raises the existing
% singleton*.
%
% H = REXDATAGUI returns the handle to a new REXDATAGUI or the handle to
% the existing singleton*.
%
% REXDATAGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in REXDATAGUI.M with the given input arguments.
%
% REXDATAGUI('Property','Value',...) creates a new REXDATAGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before RexDataGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to RexDataGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Last Modified by GUIDE v2.5 22-Sep-2013 13:12:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RexDataGUI_OpeningFcn, ...
'gui_OutputFcn', @RexDataGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before RexDataGUI is made visible.
function RexDataGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to RexDataGUI (see VARARGIN)
% Choose default command line output for RexDataGUI
handles.output = hObject;
global replacespikes user;
replacespikes = 0;
% tiny design changes
set(hObject,'DefaultTextFontName','Calibri'); %'Color',[0.9 .9 .8]
% unprocfilebtxt=sprintf('Unprocessed\rfiles');
% uibutton(findobj('tag','unprocfilebutton'),'string',unprocfilebtxt);
%only display selection box for appropriate subjects
selboxh=get(findobj('tag','monkeyselect'),'Children');
if strcmp(user,'Vincent')
set(selboxh(strcmp(get(selboxh,'tag'),'shufflesselect')),'visible','off');
set(selboxh(strcmp(get(selboxh,'tag'),'pierreselect')),'visible','off');
set(selboxh(strcmp(get(selboxh,'tag'),'hildaselect')),'position',[0.1667 0.02 0.7083 0.3857]);
set(selboxh(strcmp(get(selboxh,'tag'),'sixxselect')),'position',[0.1667 0.32 0.7083 0.3857]);
set(selboxh(strcmp(get(selboxh,'tag'),'rigelselect')),'position',[0.1667 0.62 0.7083 0.3857]);
elseif (strcmp(user,'Adam') || strcmp(user,'Anna'))
set(selboxh(strcmp(get(selboxh,'tag'),'shufflesselect')),'visible','off');
set(selboxh(strcmp(get(selboxh,'tag'),'hildaselect')),'visible','off');
set(selboxh(strcmp(get(selboxh,'tag'),'sixxselect')),'visible','off');
set(selboxh(strcmp(get(selboxh,'tag'),'rigelselect')),'visible','off');
else
set(selboxh(strcmp(get(selboxh,'tag'),'pierreselect')),'visible','off');
end
% use varargin to allow for direct input of the name of the file to be analyzed.
% see http://www.mathworks.com/help/techdoc/creating_guis/f10-998580.html
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RexDataGUI wait for user response (see UIRESUME)
% uiwait(handles.rdd);
% --- Outputs from this function are returned to the command line.
function varargout = RexDataGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function filenamedisplay_Callback(hObject, eventdata, handles)
% hObject handle to filenamedisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of filenamedisplay as text
% str2double(get(hObject,'String')) returns contents of filenamedisplay as a double
% --- Executes during object creation, after setting all properties.
function filenamedisplay_CreateFcn(hObject, eventdata, handles)
% hObject handle to filenamedisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function taskdisplay_Callback(hObject, eventdata, handles)
% hObject handle to taskdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of taskdisplay as text
% str2double(get(hObject,'String')) returns contents of taskdisplay as a double
% --- Executes during object creation, after setting all properties.
function taskdisplay_CreateFcn(hObject, eventdata, handles)
% hObject handle to taskdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function nboftrialsdisplay_Callback(hObject, eventdata, handles)
% hObject handle to nboftrialsdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of nboftrialsdisplay as text
% str2double(get(hObject,'String')) returns contents of nboftrialsdisplay as a double
% --- Executes during object creation, after setting all properties.
function nboftrialsdisplay_CreateFcn(hObject, eventdata, handles)
% hObject handle to nboftrialsdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function trialnumbdisplay_Callback(hObject, eventdata, handles)
% hObject handle to trialnumbdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of trialnumbdisplay as text
% str2double(get(hObject,'String')) returns contents of trialnumbdisplay as a double
% --- Executes during object creation, after setting all properties.
function trialnumbdisplay_CreateFcn(hObject, eventdata, handles)
% hObject handle to trialnumbdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in arrowbackw.
function arrowbackw_Callback(hObject, eventdata, handles)
% hObject handle to arrowbackw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global replacespikes;
showwtrial= get(get(findobj('Tag','showtrials'),'SelectedObject'),'Tag');%selected button's tag
if strcmp(showwtrial,'showalltrials')
trialnumber=str2num(get(findobj('Tag','trialnumbdisplay'),'String'))-1;
if trialnumber<1
trialnumber=str2num(get(findobj('Tag','nboftrialsdisplay'),'String'));
end
elseif strcmp(showwtrial,'showoutlierstrials')
outliers=str2num(get(findobj('Tag','outliertrialnb'),'String'));
currtrial=str2num(get(findobj('Tag','trialnumbdisplay'),'String'));
if find(outliers==currtrial)==1
trialnumber=max(outliers);
else
trialnumber=outliers(find(outliers==currtrial)-1);
end
elseif strcmp(showwtrial,'showbadtrials') %another day
elseif strcmp(showwtrial,'showgoodtrials') %another day
end
if ~cellfun('isempty',regexp(get(findobj('Tag','filenamedisplay'),'String'),'\d\d$', 'match')) %'native' filename, without _Sp2 or _REX appendice
if strcmp(showwtrial,'showoutlierstrials') %was just processed
if replacespikes
filename=[get(findobj('Tag','filenamedisplay'),'String') '_Sp2'];
else
filename=[get(findobj('Tag','filenamedisplay'),'String') '_REX'];
end
else
filename=get(findobj('Tag','filenamedisplay'),'String')
end
end
set(findobj('Tag','trialnumbdisplay'),'String',num2str(trialnumber));
rdd_trialdata(filename, trialnumber);
% --- Executes on button press in arrowforw.
function arrowforw_Callback(hObject, eventdata, handles)
% hObject handle to arrowforw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global replacespikes;
showwtrial= get(get(findobj('Tag','showtrials'),'SelectedObject'),'Tag');%selected button's tag
if strcmp(showwtrial,'showalltrials')
trialnumber=str2num(get(findobj('Tag','trialnumbdisplay'),'String'))+1;
if trialnumber>str2num(get(findobj('Tag','nboftrialsdisplay'),'String'))
trialnumber=1;
end
elseif strcmp(showwtrial,'showoutlierstrials')
outliers=str2num(get(findobj('Tag','outliertrialnb'),'String'));
currtrial=str2num(get(findobj('Tag','trialnumbdisplay'),'String'));
if find(outliers==currtrial)==length(outliers)
trialnumber=min(outliers);
else
trialnumber=outliers(find(outliers==currtrial)+1);
end
elseif strcmp(showwtrial,'showbadtrials') %another day
elseif strcmp(showwtrial,'showgoodtrials') %another day
end
if ~cellfun('isempty',regexp(get(findobj('Tag','filenamedisplay'),'String'),'\d\d$', 'match')) %'native' filename, without _Sp2 or _REX appendice
if strcmp(showwtrial,'showoutlierstrials') %was just processed
if replacespikes
filename=[get(findobj('Tag','filenamedisplay'),'String') '_Sp2'];
else
filename=[get(findobj('Tag','filenamedisplay'),'String') '_REX'];
end
else
filename=get(findobj('Tag','filenamedisplay'),'String')
end
end
set(findobj('Tag','trialnumbdisplay'),'String',num2str(trialnumber));
rdd_trialdata(filename, trialnumber);
% --- Executes on selection change in SacDirToDisplay.
function SacDirToDisplay_Callback(hObject, eventdata, handles)
% hObject handle to SacDirToDisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns SacDirToDisplay contents as cell array
% contents{get(hObject,'Value')} returns selected item from SacDirToDisplay
% --- Executes during object creation, after setting all properties.
function SacDirToDisplay_CreateFcn(hObject, eventdata, handles)
% hObject handle to SacDirToDisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in OpenRawFile.
function OpenRawFile_Callback(hObject, eventdata, handles)
% hObject handle to OpenRawFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global directory slash unprocfiles replacespikes subject;
subjectlist=GetSubjects;
subjseleclist=get(get(findobj('Tag','monkeyselect'),'children') ,'Tag');
% get the one selected
subjselec=get(get(findobj('Tag','monkeyselect'),'children') ,'Value');
monknum=find(strcmp(subjectlist,...
subjectlist{~cellfun(@isempty,(regexpi(subjseleclist{logical([subjselec{:}])},subjectlist)))}));
monkeydir = [directory,subject,slash]; %'B:\data\Recordings\Rigel';
procdir = [directory,'processed',slash,subject,slash];
% determines computer type
archst = computer('arch');
try
if strcmp(archst, 'maci64')
[rfname]=uigetfile({'*.*','All Files';'*A','A Files'},'raw files directory',...
monkeydir); %rfpathname
else
[rfname]=uigetfile({'*A','A Files';'*.*','All Files'},'raw files directory',...
monkeydir); %rfpathname
end
%check if file exists already
rfname=rfname(1:length(rfname)-1);
overwrite = 1;
if ~strcmp(rfname(1),subject(1))
procname=cat(2,subject(1), rfname);
set(findobj('Tag','filenamedisplay'),'String',procname);
else
procname=rfname;
set(findobj('Tag','filenamedisplay'),'String',rfname);
end
catch
disp('Aborted raw import.');
return;
end
if exist(cat(2,procdir, procname,'.mat'), 'file')==2 %'B:\data\Recordings\processed\',
% Construct question dialog
choice = questdlg('File already processed. Overwrite?','File found','Yes','Cancel','Yes');
switch choice
case 'Yes'
overwrite = 1;
case 'Cancel'
overwrite = 0;
end
end
if overwrite
[success,outliers]=rex_process_inGUI(rfname,monkeydir); %shouldn't need the rfpathname
if success
if replacespikes
rfname=[rfname '_Sp2'];
else
rfname=[rfname '_REX'];
end
%then update the directory listing
dirlisting = dir([directory,'processed',slash,subject,slash]);
% Order by date
filedates=cell2mat({dirlisting(:).datenum});
[~,fdateidx] = sort(filedates,'descend');
dirlisting = {dirlisting(:).name};
dirlisting=dirlisting(fdateidx);
dirlisting = dirlisting(cellfun('isempty',strfind(dirlisting,'myBreakpoints')));
dirlisting = dirlisting(~cellfun('isempty',strfind(dirlisting,'mat')));
for i=1:length(dirlisting)
thisfilename=cell2mat(dirlisting(i));
dirlisting(i)={thisfilename(1:end-4)};
end
set(findobj('Tag','displaymfiles'),'String',dirlisting);
%remove newly processed file(s) from unprocessed variable
if ismember(unprocfiles{monknum},rfname)
if length(ismember(unprocfiles{monknum},rfname))>1
unprocfiles{monknum}=unprocfiles{monknum}(~ismember(unprocfiles{monknum},rfname));
else
unprocfiles{monknum}={};
end
end
if outliers
if ~get(findobj('Tag','displayfbt_session'),'Value') %show dialog only if processing individual trial
% make dialogue to inspect ouliers
dlgtxt=cat(2,'Found outlier saccades in trials ', num2str(outliers), '. Display them?');
outlierbt = questdlg(dlgtxt,'Found outliers','Yes','No','Yes');
switch outlierbt
case 'Yes'
dispoutliers = 1;
case 'No'
dispoutliers = 0;
end
if dispoutliers
set(findobj('Tag','outliertrialnb'),'String',num2str(outliers));
set(findobj('Tag','trialnumbdisplay'),'String',num2str(outliers(1)));
set(findobj('Tag','showoutlierstrials'),'Value',1.0);
rdd_trialdata(rfname, outliers(1));
end
end
end
end
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over OpenRawFile.
function OpenRawFile_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to OpenRawFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in savechg.
function savechg_Callback(hObject, eventdata, handles)
% hObject handle to savechg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function rigthclickcallback
processedrexfiles = cellstr(get(findobj('tag','displaymfiles'),'String')); % returns displaymfiles contents as cell array
rclk_filename = processedrexfiles{get(findobj('tag','displaymfiles'),'Value')};
% --- Executes on selection (double click) of file in listbox.
% this the function that loads data, puts name in UserData, and display
% first trial
function displaymfiles_Callback(hObject, eventdata, handles)
% hObject handle to displaymfiles (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global directory slash subject; %unprocfiles rexloadedname
subjectlist=GetSubjects;
subjseleclist=get(get(findobj('Tag','monkeyselect'),'children') ,'Tag');
% get the one selected
subjselec=get(get(findobj('Tag','monkeyselect'),'children') ,'Value');
monknum=find(strcmp(subjectlist,...
subjectlist{~cellfun(@isempty,(regexpi(subjseleclist{logical([subjselec{:}])},subjectlist)))}));
% monkeydir = [directory,subject,slash]; %'B:\data\Recordings\Rigel';
procdir = [directory,'processed',slash,subject,slash];
if strcmp(get(gcf,'SelectionType'),'normal') && ~strcmp(eventdata,'rightclkevt') % if simple click, just higlight it, don't open
if get(findobj('Tag','displayfbt_files'),'Value') % works only with individual file display
%set uimenu content for following rightclick
%SelectionType 'Alternate' (Right click) doesn't work with listbox
%dispmenu=(get(hObject,'UIContextMenu'));
set(findobj('tag','displaymfiles'),'Max',1)
clear rightclkevt;
clear global tasktype;
listboxcontextmenu=uicontextmenu;
processedrexfiles = cellstr(get(hObject,'String')); % returns displaymfiles contents as cell array
rclk_filename = processedrexfiles{get(hObject,'Value')}; %returns selected item from displaymfiles
filecontent=matfile([procdir,rclk_filename,'.mat']);
filecodes=filecontent.allcodes;
curtasktype=taskdetect(filecodes);
if iscell(curtasktype)
curtasktype=cell2mat(curtasktype);
end
disptask=uimenu('Parent',listboxcontextmenu,'Label',curtasktype);
set(hObject,'UIContextMenu',listboxcontextmenu);
else
set(hObject,'Max',2);
rightclkevt='rightclkevt';
multianalyzepopup=uicontextmenu();
set(hObject,'uicontextmenu',multianalyzepopup);
item1 = uimenu(multianalyzepopup,'Label','Analyze','Callback',{@(src,evt,handles) displaymfiles_Callback(hObject,rightclkevt,handles),hObject}); %disp(get(hObject,'Value'))
%displaymfiles_Callback(hObject, eventdata, handles)
end
elseif strcmp(get(gcf,'SelectionType'),'open') || strcmp(eventdata,'rightclkevt')
cd(directory);
s=dbstatus; %little trick to prevent removal of breakpoints with clear
save('myBreakpoints.mat', 's');
clear functions;
clear rightclkevt;
load('myBreakpoints.mat');
dbstop(s);
processedrexfiles = cellstr(get(hObject,'String')); % returns displaymfiles contents as cell array
selectionnm = {processedrexfiles{get(hObject,'Value')}}; %returns selected item from displaymfiles
%% very different actions (for the moment) between display buttons files and session/grid:
% the 'normal' one will display the file (which was already processed)
% the others will process the requested combination of files, but not
% display them, since for the moment GUI is designed to display only one
% file at a time
if ~get(findobj('Tag','displayfbt_files'),'Value') % if session or grid is selected
selectedrawdir=dir(procdir);
fileNames = {selectedrawdir.name}; % Put the file names in a cell array
if get(findobj('Tag','displayfbt_session'),'Value')
sessionNumber=regexpi(selectionnm,'\d+$', 'match');
allftoanlz=cell(length(sessionNumber),1);
for sessnumnum=1:length(sessionNumber)
ftoanlz = regexp(fileNames, strcat('^\w',sessionNumber{sessnumnum}{:}),'match');
ftoanlz = fileNames(~cellfun(@isempty,ftoanlz)); % Get the names of the matching files in a cell array
ftoanlz = regexprep(ftoanlz, '(A$)|(E$)',''); %remove A and E from end of names (if raw files)
ftoanlz = regexprep(ftoanlz, '.mat$',''); %remove .mat from end of names (if processed files)
ftoanlz = unique(ftoanlz);
allftoanlz{sessnumnum}=ftoanlz;
end
allftoanlz=horzcat(allftoanlz{:});
elseif get(findobj('Tag','displayfbt_grid'),'Value')
allftoanlz=cell(length(selectionnm),1);
for sessnumnum=1:length(selectionnm)
ftoanlz = regexp(fileNames, selectionnm{sessnumnum}); %regexp(fileNames, strcat('^\w',gridNumber{sessnumnum}{:}),'match');
ftoanlz = fileNames(~cellfun(@isempty,ftoanlz)); % Get the names of the matching files in a cell array
ftoanlz = regexprep(ftoanlz, '(A$)|(E$)',''); %remove A and E from end of names
ftoanlz = unique(ftoanlz);
allftoanlz{sessnumnum}=ftoanlz;
end
allftoanlz=horzcat(allftoanlz{:});
end
%overwrite option: legacy from the time when one could want to
%process and analyze at the same time. Not enabled at the moment.
%Only processed files will be analyzed.
overwriteAll = 0; % This switch should stay hardcoded, no need for user option
if overwriteAll %(exist(strcat({procdir},rfname,{'.mat'}), 'file')==2)
% Construct question dialog
choice = questdlg('Do you want to overwrite processed files?','Reprocess files?','Overwrite all','Skip','Skip'); %'Overwrite this file'
switch choice
case 'Overwrite all'
overwrite = 1;
% overwriteAll = 1;
% case 'Overwrite this file'
% overwrite = 1;
% overwriteAll = 0;
case 'Skip'
overwrite = 0;
% overwriteAll = 0;
end
else
overwrite=0;
end
try % see if database is running
dbname='vp_sldata';
CCNdb = connect2DB(dbname);
%ftp_CCNdb = connect2ftp(dbname); We don't have a ftp server,
%and that would mean writing main password in a file. Nope
% see connect2ftp.m to use cygwin instead
user = getUser(CCNdb);
isdbrunning=1;
catch
isdbrunning=0;
end
for i = 1:length(allftoanlz)
procname=allftoanlz{i};
trimmed_procname = regexprep(procname, '(_REX$)|(_Sp2$)','');
origin = procname(end-2:end);
origin = regexprep(origin,'Sp2','Spike2');
origin = regexprep(origin,'REX','Rex');
if strcmp(origin,'Spike2');
fcomments = getComments(trimmed_procname, CCNdb);
else
fcomments = ' ';
end
% crude segmentation: set depth limits for top cortex / dentate / bottom cortex
compart=reccompart(subject,procname);
if overwrite
[success,outliers]=rex_process_inGUI(trimmed_procname,monkeydir); %shouldn't need the rfpathname
% outliers are stored in file now
if success
successtr=['file ',procname,' processed succesfully'];
disp(successtr);
if ismember(unprocfiles{monknum},procname) %some files from this session / grid may not have been processed
if length(ismember(unprocfiles{monknum},procname))>1
unprocfiles{monknum}=unprocfiles{monknum}(~ismember(unprocfiles{monknum},procname));
else
unprocfiles{monknum}={};
end
end
else
successtr=['processing aborted for file ',procname'];
disp(successtr);
end
end
% load file
clear global tasktype;
try
[~, trialdirs] = data_info(procname, 1, 1); %1, 1 = reload file: yes (shouldn't happen, though), skip unprocessed files: yes
catch
continue
end
% process file, aligning to sac, cue, reward
alignmtname={'mainsacalign','tgtshownalign','rewardalign'};
alignbh=get( findobj('Tag','aligntimepanel'),'children');
clusnames = GetClusnames(procname);
clusnums = zeros(length(clusnames)-1,1);
for a = 1:length(clusnames)-1
clusnums(a) = str2num(clusnames{a}(1));
end
if isdbrunning
% add record to database if not already there
chamber = getChamber(trimmed_procname, CCNdb);
part=regexp(trimmed_procname,'^\w\d+','match'); part = part{:}(2:end);
date_today = datestr(date,'yyyy-mm-dd');
compart=reccompart(subject,procname,part,CCNdb);
newrecord = struct('name',trimmed_procname,...
'date',date_today,...
'chamber', chamber,...
'session', part,...
'task', get(findobj('Tag','taskdisplay'),'String'),...
'recloc', compart,...
'user', user);
[~, ~, rec_id] = addRecord(newrecord, CCNdb);
% overwrite a sort, or make a new one?
newsort = struct('name', trimmed_procname,...
'comments', fcomments,...
'user', user, 'origin', origin,...
'parent', rec_id);
q = ['SELECT sort_id FROM sorts s INNER JOIN recordings r ON s.recording_id_fk = r.recording_id WHERE user = ''' user ''' AND '...
'origin = ''' origin ''' AND r.a_file = ''' trimmed_procname 'A'''];
checksort = fetch(CCNdb,q);
if ~isempty(checksort)
% overwrite the user's oldest sort for this file
sort_id = checksort(end); sort_id = sort_id{1};
[success] = deleteChildren(sort_id, CCNdb); %removed ftp_CCNdb
updateSort(sort_id, newsort, CCNdb);
else
[~, sort_id] = addSort(newsort, CCNdb);
end
end
for curclus = 1:length(clusnums) % For each of this file's clusters
try
for alignmt=1:3
set(findobj('Tag','aligntimepanel'),'SelectedObject',alignbh(strcmp(get(alignbh,'tag'),alignmtname{alignmt})))
try
getaligndata{alignmt} = rdd_rasters_sdf(procname, trialdirs, clusnums(curclus), 0); % align data, don't plot rasters
%% statistics on rasters: do stats on collapsed data and individual direction, if > 7 trials
if length([getaligndata{alignmt}.trials])>=7
getaligndata{alignmt}=getaligndata{alignmt}(~cellfun('isempty',{getaligndata{alignmt}.alignidx})); % remove empty conditions
%additional measures: cc and auc
% cross-correlation values: pretty reliable indicator to sort out pre-event, peri-event and post-event activities
% possible limits are: pressac <-10ms before sac , >-10ms perisac <+10ms, <10ms postsac
% [peakcct, peaksdf]=crosscorel(procname,getaligndata{alignmt},'all',0); %Get peakcc for all directions. Don't plot
% area under curve: separate cells with low baseline FR and sharp burst from higher baseline neurons, especially ramping ones
% possible limit at 2000
try
[dirauc, dirslopes, peaksdft,nadirsdft]=findauc(procname,getaligndata{alignmt},'all'); %Get auc, slopes, peaksdft for all directions
catch
[dirauc, dirslopes, peaksdft,nadirsdft]=deal(nan(1,length(getaligndata{alignmt})));
end
% record values in respective array
for psda=1:length(getaligndata{alignmt})
% getaligndata{alignmt}(psda).peakramp.peakcct=peakcct(psda); % peak cross-correlation time
% getaligndata{alignmt}(psda).peakramp.peaksdf=peaksdf(psda); % main sdf peak, within -200/+199 of aligntime
getaligndata{alignmt}(psda).peakramp.peaksdft=peaksdft(psda); % time of peak sdf
getaligndata{alignmt}(psda).peakramp.nadirsdft=nadirsdft(psda); % time of sdf low point
getaligndata{alignmt}(psda).peakramp.auc=dirauc(psda); % normalized area under curve
getaligndata{alignmt}(psda).peakramp.slopes=dirslopes(:,psda); % slope of activity to peak (or drought, if negative)
end
% main stats (adding an extra array for collapsed values)
try
[p_sac,h_sac]=eventraststats(getaligndata{alignmt},alignmtname{alignmt});
catch
[p_sac,h_sac]=deal(nan(1,length(getaligndata{alignmt})));
end
for psda=1:length(getaligndata{alignmt})+1
getaligndata{alignmt}(psda).stats.p=p_sac(psda,:);
getaligndata{alignmt}(psda).stats.h=h_sac(psda,:);
% getaligndata{alignmt}(psda).stats.p_rmanov=p_rmanov(psda,:);
% getaligndata{alignmt}(psda).stats.mcstats=mcstats(psda,:);
end
else
getaligndata{alignmt}(1).peakramp=[];
for psda=1:length(getaligndata{alignmt})+1
getaligndata{alignmt}(psda).stats.h=[];
end
end
catch
continue
end
end
% export data
if isempty(cellfun(@(x) x.savealignname, arrayfun(@(x) x, getaligndata),'UniformOutput', false))
getaligndata{1}(1).savealignname = cat( 2, directory, 'processed',slash, 'aligned',slash, procname, '_cl', num2str(clusnums(curclus)), '_', getaligndata{1}(1).alignlabel);
end
guidata(findobj('Tag','exportdata'),getaligndata);
exportdata_Callback(findobj('tag','exportdata'), eventdata, handles);
% if statistically significant event related activity in
% any alignment, categorize activity
if sum(~cellfun('isempty',arrayfun(@(x) x.stats, cell2mat(arrayfun(@(x) x, getaligndata)),'UniformOutput',false))) &&...
nansum(cell2mat(arrayfun(@(x) x.stats.h, cell2mat(arrayfun(@(x) x, getaligndata)),...
'UniformOutput',false))) %checking if any useful stats to categorize
[activlevel,activtype,maxmean,profile,dirselective,bestlt]=catstatres(getaligndata);
if ~sum([activlevel{:}])
[activtype,profile,dirselective,maxmean,activlevel,bestlt]=deal({0});
end
else
[activtype,profile,dirselective,maxmean,activlevel,bestlt]=deal({0});
end
% print vignette figure of every alignement (not just
% statistically significant result)
effectcat={'sac','vis','rew'};
for effnum=1:3
try
% Radu TODO insert cluster number into summaryplot
% somehow
summary_procname = regexprep(procname, '(_Sp2$)',['_Sp2_cl_' num2str(clusnums(curclus))]);
summary_procname = regexprep(summary_procname, '(_REX$)',['_REX_cl_' num2str(clusnums(curclus))]);
% SummaryPlot(effectcat{effnum},summary_procname,get(findobj('Tag','taskdisplay'),'String'),getaligndata{effnum});
% close(gcf);
catch
% close(gcf);
end
end
if sum([activlevel{:}]>1)
foundeff=find(~cellfun('isempty',activtype));
else
foundeff=max(1,find([activlevel{:}]==max([activlevel{:}])));
end
if isdbrunning
[~, c_id] = addCluster(sort_id, clusnums(curclus),CCNdb); %removed ftp_CCNdb
[~, ~] = addPsth(c_id, clusnums(curclus), CCNdb); % removed ftp_CCNdb
[ ~, ~ ] = addStats(c_id, getaligndata, effectcat, CCNdb);
else
% if not database, write result to excel file
% get number of row in "database"
exl = actxserver('excel.application');
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open([directory 'procdata.xlsx']);
exlSheet = exlFile.Sheets.Item(monknum);% e.g.: 2 = Sixx
robj = exlSheet.Columns.End(4);
numrows = robj.row;
if numrows==1048576 %empty document
numrows=1;
end
Quit(exl);
cd(directory);
% remove appendix
procname=procname(1:end-4);
% get current processed file list from excel file
[~,pfilelist] = xlsread('procdata.xlsx',monknum,['A2:A' num2str(numrows)]);
if logical(sum(ismember(pfilelist,procname))) %file has to have been processed already, but if for some reason not, then do not go further
wline=find(ismember(pfilelist,procname))+1;
else
continue
end
xlswrite('procdata.xlsx', compart, monknum, sprintf('H%d',wline));
xlswrite('procdata.xlsx', {max([activlevel{foundeff}])}, monknum, sprintf('K%d',wline));
xlswrite('procdata.xlsx', {[activtype{foundeff}]}, monknum, sprintf('L%d',wline));
xlswrite('procdata.xlsx', {max([maxmean{foundeff}])}, monknum, sprintf('M%d',wline));
xlswrite('procdata.xlsx', {[profile{foundeff}]}, monknum, sprintf('N%d',wline));
xlswrite('procdata.xlsx', {[dirselective{foundeff}]}, monknum, sprintf('O%d',wline));
xlswrite('procdata.xlsx', {[bestlt{foundeff}]}, monknum, sprintf('P%d',wline));
end
catch
continue
end
end % End of things to do for this cluster
end % End of things to do for this file
else
%% normal method
% selecteprocdir=dir(procdir);
% {selecteprocdir.name}; % Put the file names in a cell array
rdd_filename =selectionnm{:};
[rdd_nt, trialdirs] = data_info( rdd_filename, 1);% load file
clusnames = GetClusnames(rdd_filename);
set(findobj('Tag','whichclus'),'Enable','on');
set(findobj('Tag','whichclus'),'String',clusnames);
set(findobj('Tag','whichclus'),'Value',1);
% Radu 2/11/2014 now that we know the filename, retrieve its
% clusters
trialnumber = rex_first_trial( rdd_filename, rdd_nt, 1);
if trialnumber == 0
msgbox( 'There are no good trials (no trials, or all are marked BAD) for this set of Rex data.', 'Loading data', 'modal' );
return;
end;
set(findobj('Tag','trialnumbdisplay'),'String',num2str(trialnumber));
%set(findobj('Tag','outliertrialnb'),'String',[]);
set(findobj('Tag','showalltrials'),'Value',1.0);
%set(gcbf,'UserData',whatever might be needed);
%disp ('File name set to Figure UserData');
%now send data to Trial Data panel, to display first trial
%trialdatapanelH = findobj('Tag','fulltrialdata');
%set(trialdatapanelH,'UserData',whatever might be needed);
rdd_trialdata(rdd_filename, trialnumber); % add 1 to make sure it reloads file
try
if strcmp(rdd_filename(end-2:end),'Sp2'); % using data from Spike2 processing
selclus_order = get(findobj('Tag','whichclus'),'Value'); %Which element of the list
spikechannel = get(findobj('Tag','whichclus'),'String');
if iscell(spikechannel)
spikechannel = str2double(spikechannel{selclus_order}(1));
else
spikechannel = str2double(spikechannel);
end
else
spikechannel = 1;
end
dataaligned=rdd_rasters_sdf(rdd_filename, trialdirs, spikechannel, 1); %align data, plot rasters
catch err
fprintf([err.message '\n']); % Print error message as well
disp('rdd_rasters_sdf call from RexDataGui failed');
return;
end
dataaligned=dataaligned(~cellfun('isempty',{dataaligned.alignidx}));
%% do stats
[p_sac,h_sac,p_rmanov,mcstats]=raststats(dataaligned);
for psda=1:length(dataaligned)
dataaligned(psda).stats.p=p_sac(psda,:);
dataaligned(psda).stats.h=h_sac(psda,:);
end
%additional measures: cc and auc
% cross-correlation values: pretty reliable indicator to sort out presac, perisac and postsac activities
% possible limits are:
% pressac <-10ms before sac , >-10ms perisac <+10ms, <10ms postsac
% [peakcct, peaksdf]=crosscorel(rdd_filename,dataaligned,'all',0); %Get peakcc for all directions. Don't plot
% area under curve: separate cells with low baseline FR and sharp burst from higher baseline neurons, especially ramping ones
% possible limit at 2000
% [dirauc, dirslopes, peaksdft]=findauc(rdd_filename,dataaligned,'all'); %Get auc, slopes, peaksdft for all directions
%% Present statistics
pdata = {};
stat_dir = {};
set(findobj('Tag','wilcoxontable'),'Data',pdata,'RowName',[]); %Clears previous table
% Create table data
if any(sum(h_sac,1))
pdata=num2cell(p_sac);
stat_dir ={dataaligned.dir};
set(findobj('Tag','wilcoxontable'),'Data',pdata,'RowName',stat_dir);
end
guidata(findobj('Tag','exportdata'),dataaligned);
end
end
% --- Executes on button press in replotbutton.
function replotbutton_Callback(hObject, eventdata, handles)
s=dbstatus; %little trick to prevent removal of breakpoints with clear
save('myBreakpoints.mat', 's');
clear functions;
load('myBreakpoints.mat');
dbstop(s);
rdd_filename=get(findobj('Tag','filenamedisplay'),'String');
[rdd_nt, trialdirs] = data_info( rdd_filename );
try
if strcmp(rdd_filename(end-2:end),'Sp2'); % using data from Spike2 processing
spikechannel = get(findobj('Tag','whichclus'),'Value');
else
spikechannel = 1;
end
dataaligned=rdd_rasters_sdf(rdd_filename, trialdirs, spikechannel, 1);
catch err
fprintf(['Error: ' err.message '\n']); % Print error message as well
disp('rdd_rasters_sdf call from RexDataGui replot failed');
return;
end
guidata(findobj('Tag','exportdata'),dataaligned);
% --- Executes on button press in exportdata.
function exportdata_Callback(hObject, eventdata, handles)
% hObject handle to exportdata (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dataaligned=guidata(hObject);
if iscell(dataaligned) %multiple alignements
snames=cellfun(@(x) x.savealignname, arrayfun(@(x) x, dataaligned),'UniformOutput', false);
savealignname=[dataaligned{1}(1).savealignname(1:end-3) cell2mat(cellfun(@(x) regexp(x,'\w\w\w$','match'),snames(~cellfun('isempty',snames))))];
else
savealignname = dataaligned.savealignname;
end
save(savealignname,'dataaligned','-v7.3');
%save some data to match with SH / Spike2 data analysis
% about dataaligned:
% datalign.timefromtrig and datalign.timetotrig represent time from start
% or to the end of the trial with respect to the alignment time
% respectively. Depending on whether there is a trigger ecode,
% they represent different things.
% No trigger ecode: time from the first trigger(in case there's a trigger
% channel, otherwise it's useless), and time to the end-of-trial reward delivery
% Trigger ecode: time from onset of first trigger (beggining of trial),
% and time to onset of second trigger (end of trial).
% for Rigel: no trigger ecode until R146 included
% for Sixx: no trigger ecode until S102 included
if iscell(dataaligned) %multiple alignements: keep only sac alignement
dataaligned=dataaligned(find(cell2mat(strfind(cellfun(@(x) x.alignlabel, arrayfun(@(x) x, dataaligned),'UniformOutput',false),'sac')),1));
if ~isempty(dataaligned)
dataaligned=dataaligned{:};
else
dataaligned(1);
end
end
rdd_filename=get(findobj('Tag','filenamedisplay'),'String');
recdata=matfile(rdd_filename);
%rex2sh=NaN(length(recdata.allbad),8);
rex2sh.goodtrials=~(recdata.allbad)';
rex2sh.starttrigs=recdata.alltrigin';
rex2sh.endtrigs=recdata.alltrigout';
rex2sh.rewtimes=recdata.allrew';
%prealloc
trigtosac=nan(size(rex2sh.goodtrials));
sactotrig=nan(size(rex2sh.goodtrials));
trigtovis=nan(size(rex2sh.goodtrials));
vistotrig=nan(size(rex2sh.goodtrials));
trialdir=cell(size(rex2sh.goodtrials));
alignlabel=cell(size(rex2sh.goodtrials));
if logical(sum(rex2sh.goodtrials))
for i=1:length(dataaligned)
if ~isempty(dataaligned(i).trials)
trigtosac((dataaligned(i).trials),1)=dataaligned(i).trigtosac;
sactotrig((dataaligned(i).trials),1)=dataaligned(i).sactotrig;
trigtovis((dataaligned(i).trials),1)=dataaligned(i).trigtovis;
vistotrig((dataaligned(i).trials),1)=dataaligned(i).vistotrig;
trialdir(dataaligned(i).trials)={dataaligned(i).dir};
alignlabel(dataaligned(i).trials)={dataaligned(i).alignlabel};
end
end
end
rex2sh.align=alignlabel;
rex2sh.dir=trialdir;
rex2sh.trigtosac=trigtosac;
rex2sh.sactotrig=sactotrig;
rex2sh.trigtovis=trigtovis;
rex2sh.vistotrig=vistotrig;
savealignsh=cat(2,savealignname,'_2SH');
save(savealignsh, '-struct','rex2sh','goodtrials','starttrigs',...
'endtrigs','rewtimes','align','dir','trigtosac','sactotrig','trigtovis','vistotrig','-v7.3');
% --- Executes during object creation, after setting all properties.
function displaymfiles_CreateFcn(hObject, eventdata, handles)
% hObject handle to displaymfiles (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
global directory slash unprocfiles user subject;
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%find user, directory and slash type
userinfo=SetUserDir;
directory=userinfo.directory;
slash=filesep;
user=userinfo.user;
%get subject list
subjectlist=GetSubjects;
% get list of subject select boxes
selboxh=get(findobj('tag','monkeyselect'),'Children');
if strcmp(user,'Vincent')
set(selboxh(strcmp(get(selboxh,'tag'),'sixxselect')),'value',1);
end
%setting process directory
monkeydir= get(get(findobj('Tag','monkeyselect'),'SelectedObject'),'Tag');
if strcmp(monkeydir,'rigelselect')
subject=subjectlist{1};
elseif strcmp(monkeydir,'sixxselect')
subject=subjectlist{2};
elseif strcmp(monkeydir,'hildaselect')
subject=subjectlist{3};
elseif strcmp(monkeydir, 'shufflesselect')
subject=subjectlist{4};
elseif strcmp(monkeydir, 'pierreselect')
subject=subjectlist{5};
end
%% add subject ID letter in front of file names for sessions >= 100
% change hyphens into underscores
% output unprocessed file list
rawdirs=cellfun(@(x) [directory x slash], subjectlist, 'UniformOutput', false);