-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_lever_tools.py
993 lines (712 loc) · 42.6 KB
/
mouse_lever_tools.py
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
import glob
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from analysis import *
from mouse_lever import *
class MouseLeverTools(QtGui.QWidget):
def __init__(self, parent):
super(MouseLeverTools, self).__init__(parent)
self.parent = parent
layout = QtGui.QGridLayout()
#Mouse IA1 as default experiment for Greg experiments
#self.parent.root_dir = '/media/cat/12TB/in_vivo/tim/yuki/'
self.parent.root_dir = '/media/cat/12TB/in_vivo/tim/yuki/'
self.parent.replacement_dir = "12TB"# 'All.Data.3TB'
self.parent.n_sec = 3
self.parent.exp_type = 'mouse_lever'
row_index = 0 #Keep track of button/box row
self.video_rate = 15. #Video rate in Hz.
#**************************************************************************************
#******************************** SELECT ANIMAL & SESSION *****************************
#**************************************************************************************
#Select animal
self.select_lbl = QLabel('Select Experiment----->', self)
self.select_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
layout.addWidget(self.select_lbl, row_index,1)
self.comboBox_select_animal = QtGui.QComboBox(self)
file_names = sorted(glob.glob(self.parent.root_dir+"*"))
for file_name in file_names:
self.comboBox_select_animal.addItem(file_name.replace(self.parent.root_dir,''))
layout.addWidget(self.comboBox_select_animal, row_index,2)
self.comboBox_select_animal.activated[str].connect(self.select_animal); self.selected_animal = file_names[0].replace(self.parent.root_dir,'')
#Select session
self.select_lbl = QLabel('Select Session----->', self)
self.select_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
layout.addWidget(self.select_lbl, row_index,3)
self.comboBox_select_session = QtGui.QComboBox(self)
file_names = sorted(glob.glob(self.parent.root_dir + self.selected_animal + "/tif_files/*"))
for file_name in file_names:
self.comboBox_select_session.addItem(file_name.replace(self.parent.root_dir+self.selected_animal+"/tif_files/",''))
layout.addWidget(self.comboBox_select_session, row_index,4)
self.comboBox_select_session.activated[str].connect(self.select_session); self.selected_session = file_names[0].replace(self.parent.root_dir + self.selected_animal + "/tif_files/",'')
#Load Mouse from default values
self.parent.animal_name_text=self.selected_animal.replace(self.parent.root_dir,'')
self.parent.animal = Mouse_lever(self.parent.animal_name_text, self.parent.root_dir, self.parent.n_sec)
self.parent.setWindowTitle(self.parent.animal.name)
#Find movie if available:
self.movie_available_lbl = QLabel('', self)
self.movie_available_lbl.setFont(QtGui.QFont("", 12) )
if os.path.exists(self.parent.animal.home_dir+self.parent.animal.name+"/video_files/"+self.selected_session+'.m4v')==True:
self.movie_available_lbl.setText("Movie exists")
else:
self.movie_available_lbl.setText("No movie")
layout.addWidget(self.movie_available_lbl, row_index,5)
row_index+=1
#**************************************************************************************
#************************* PRE-PROCESSING BATCH / ALL SESSIONS ************************
#**************************************************************************************
self.preprocess_lbl = QLabel('PREPROCESS ALL SESSIONS', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
self.button_preprocess_mlever = QPushButton('Preprocess All Sessions')
self.button_preprocess_mlever.setMaximumWidth(200)
self.button_preprocess_mlever.clicked.connect(self.preprocess_mlever)
layout.addWidget(self.button_preprocess_mlever, row_index, 0)
self.button_filter_mlever = QPushButton('Filter All Sessions')
self.button_filter_mlever.setMaximumWidth(200)
self.button_filter_mlever.clicked.connect(self.filter_mlever)
layout.addWidget(self.button_filter_mlever, row_index, 1); row_index+=1
#**************************************************************************************
#************************* PREPROCESSING SINGLE SESSION ******************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.preprocess_lbl = QLabel('PREPROCESS SINGLE SESSION', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
#Convert .tif to .npy
self.button1 = QPushButton('Convert .tif -> .npy')
self.button1.setMaximumWidth(200)
self.button1.clicked.connect(self.cvrt_tif_npy)
layout.addWidget(self.button1, row_index, 0)
#Align sessions
self.button1 = QPushButton('Align Sessions')
self.button1.setMaximumWidth(200)
self.button1.clicked.connect(self.algn_images)
layout.addWidget(self.button1, row_index, 1)
#Other Functions
self.button1 = QPushButton('Other Functions')
self.button1.setMaximumWidth(200)
self.button1.clicked.connect(self.algn_images)
layout.addWidget(self.button1, row_index, 2)
self.cmap = QLineEdit('viridis')
self.cmap.setMaximumWidth(50)
self.cmap_lbl = QLabel('Colour map:', self)
layout.addWidget(self.cmap_lbl, row_index,5)
layout.addWidget(self.cmap, row_index,6)
self.fps = QLineEdit('15')
self.fps.setMaximumWidth(50)
self.fps_lbl = QLabel('Video FPS:', self)
layout.addWidget(self.fps_lbl, row_index,7)
layout.addWidget(self.fps, row_index,8); row_index+=1
#************************************ FILTERING ***************************************
self.button2 = QPushButton('Pre-Filter Images')
self.button2.setMaximumWidth(200)
self.button2.clicked.connect(self.fltr_mouse_lever)
layout.addWidget(self.button2, row_index, 0)
self.filter_list = ['nofilter', 'butterworth', 'chebyshev']
self.comboBox_filter = QtGui.QComboBox(self)
for filter_ in self.filter_list[1:]: self.comboBox_filter.addItem(filter_)
layout.addWidget(self.comboBox_filter, row_index,1)
self.comboBox_filter.activated[str].connect(self.select_filter); self.selected_filter = "butterworth" #Set default
parent.filter_low = QLineEdit('0.1')
parent.filter_low.setMaximumWidth(50)
filter_low_lbl = QLabel('Low Cutoff (HZ):', self)
layout.addWidget(filter_low_lbl, row_index,2)
layout.addWidget(parent.filter_low, row_index,3)
parent.filter_high = QLineEdit('6.0')
parent.filter_high.setMaximumWidth(50)
filter_high_lbl = QLabel('High Cutoff (HZ):', self)
layout.addWidget(filter_high_lbl, row_index,4)
layout.addWidget(parent.filter_high, row_index,5)
self.n_sec_window = QLineEdit('3')
self.n_sec_window.setMaximumWidth(50)
self.n_sec_window_lbl = QLabel('Window (sec):', self)
layout.addWidget(self.n_sec_window_lbl, row_index,6)
layout.addWidget(self.n_sec_window, row_index,7)
#**************************************************************************************
#************************************ COMPUTE DFF *************************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.preprocess_lbl = QLabel('[Ca] EVENT TRIGGERED', self)
self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.preprocess_lbl.setStyleSheet('color: blue')
layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
self.button3 = QPushButton('Compute DFF Pipe ====>')
self.button3.setMaximumWidth(200)
self.button3.clicked.connect(self.dff_mouse_lever)
layout.addWidget(self.button3, row_index, 0)
#Filter dropdown box
self.comboBox_select_dff_filter = QtGui.QComboBox(self)
for filter_ in self.filter_list: self.comboBox_select_dff_filter.addItem(filter_)
layout.addWidget(self.comboBox_select_dff_filter, row_index,1)
self.comboBox_select_dff_filter.activated[str].connect(self.select_dff_filter); self.selected_dff_filter = "nofilter" #Set default
#DFF method dropdown box
dff_list = ['globalAverage', 'slidingWindow']
self.comboBox_select_dff_method = QtGui.QComboBox(self)
for dff_ in dff_list: self.comboBox_select_dff_method.addItem(dff_)
layout.addWidget(self.comboBox_select_dff_method, row_index,2)
self.comboBox_select_dff_method.activated[str].connect(self.select_dff_method); self.dff_method = "globalAverage"
#Reward code dropdown box
self.locs_44threshold = []; self.code_44threshold = []
temp_file = self.parent.root_dir+self.selected_animal + '/tif_files/'+self.selected_session+'/'+self.selected_session
print temp_file
if os.path.exists(temp_file + '_locs44threshold.npy')==True:
self.locs_44threshold = np.load(temp_file+'_locs44threshold.npy')
self.code_44threshold = np.load(temp_file+'_code44threshold.npy')
self.selected_code = '02'; self.n_codes = np.count_nonzero(self.code_44threshold == self.selected_code)
#Make reward code box; May need to redo below if adding other types of codes;
self.code_list = ['02', '04', '07']
#Search for behavioural annotation data:
self.code_list.extend(self.find_annotated_clusters())
self.comboBox_select_code = QtGui.QComboBox(self)
for code_ in self.code_list:
self.comboBox_select_code.addItem(code_)
layout.addWidget(self.comboBox_select_code, row_index, 3)
self.comboBox_select_code.activated[str].connect(self.select_reward_code);
# Number of trials for reward code
self.n_codes_lbl = QLabel(str(self.n_codes), self)
layout.addWidget(self.n_codes_lbl, row_index, 4)
#Display location of trials
self.loc_trials = QPushButton('Trial Locations')
self.loc_trials.setMaximumWidth(200)
self.loc_trials.clicked.connect(self.view_trial_locations)
layout.addWidget(self.loc_trials, row_index, 5)
#Display location of trials
self.annotated_movies = QPushButton('Annotated Movies')
self.annotated_movies.setMaximumWidth(200)
self.annotated_movies.clicked.connect(self.make_annotated_movies)
layout.addWidget(self.annotated_movies, row_index, 6)
#Display location of trials
self.isolated_behaviours = QPushButton('Isolated Behaviours')
self.isolated_behaviours.setMaximumWidth(200)
self.isolated_behaviours.clicked.connect(self.find_isolated_behaviours)
layout.addWidget(self.isolated_behaviours, row_index, 7); row_index+=1
#**************************************************************************************
#************************************ VIEW DFF *************************************
#**************************************************************************************
self.button31 = QPushButton('Static STM - Single')
self.button31.setMaximumWidth(200)
self.button31.clicked.connect(self.static_stm_mouse_lever)
layout.addWidget(self.button31, row_index, 0)
self.button32 = QPushButton('Video STM')
self.button32.setMaximumWidth(200)
self.button32.clicked.connect(self.video_stm_mouse_lever)
layout.addWidget(self.button32, row_index, 1)
trial_lbl = QLabel('Select Trial:', self)
layout.addWidget(trial_lbl, row_index,2)
self.comboBox_select_trial = QtGui.QComboBox(self)
n_trials_in = self.load_trials()
self.selected_trial = ''
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #Redundant method
layout.addWidget(self.comboBox_select_trial, row_index,3)
self.comboBox_select_trial.activated[str].connect(self.initialize_trial)
self.block_save = QLineEdit('1')
self.block_save.setMaximumWidth(50)
self.block_save_lbl = QLabel('Block Ave:', self)
layout.addWidget(self.block_save_lbl, row_index,4)
layout.addWidget(self.block_save, row_index,5)
self.midline_mask = QLineEdit('1')
self.midline_mask.setMaximumWidth(50)
self.midline_mask_lbl = QLabel('MidlineMask:', self)
layout.addWidget(self.midline_mask_lbl, row_index,6)
layout.addWidget(self.midline_mask, row_index,7)
self.stm_start_time = QLineEdit('-.3')
self.stm_start_time.setMaximumWidth(50)
self.stm_start_time_lbl = QLabel('Start time:', self)
layout.addWidget(self.stm_start_time_lbl, row_index,8)
layout.addWidget(self.stm_start_time, row_index,9)
self.stm_end_time = QLineEdit('+.3')
self.stm_end_time.setMaximumWidth(50)
self.stm_end_time_lbl = QLabel('End time:', self)
layout.addWidget(self.stm_end_time_lbl, row_index,10)
layout.addWidget(self.stm_end_time, row_index,11); row_index+=1
self.static_stm_all = QPushButton('Static STM - All')
self.static_stm_all.setMaximumWidth(200)
self.static_stm_all.clicked.connect(self.static_stm_all_lever)
layout.addWidget(self.static_stm_all, row_index, 0)
self.vid_stm_all = QPushButton('Video STM - All')
self.vid_stm_all.setMaximumWidth(200)
self.vid_stm_all.clicked.connect(self.video_stm_all)
layout.addWidget(self.vid_stm_all, row_index, 1)
#************************************ EVENT TRIGGERED OPTIONS ***************************************
#self.stm_activity = QPushButton('Activity Triggered STM')
#self.stm_activity.setMaximumWidth(200)
#self.stm_activity.clicked.connect(self.view_stm_activity)
#layout.addWidget(self.stm_activity, row_index, 0)
self.mask_width = QLineEdit('12')
self.mask_width.setMaximumWidth(50)
self.mask_width_lbl = QLabel('Mask width (pixels):', self)
layout.addWidget(self.mask_width_lbl, row_index,5)
layout.addWidget(self.mask_width, row_index,6)
self.mask_percentile = QLineEdit('99.99')
self.mask_percentile.setMaximumWidth(50)
self.mask_percentile_lbl = QLabel('Mask Percentile:', self)
layout.addWidget(self.mask_percentile_lbl, row_index,7)
layout.addWidget(self.mask_percentile, row_index,8)
self.mask_power = QLineEdit('1.2')
self.mask_power.setMaximumWidth(50)
self.mask_power_lbl = QLabel('Mask Power:', self)
layout.addWidget(self.mask_power_lbl, row_index,9)
layout.addWidget(self.mask_power, row_index,10); row_index+=1
self.mask_start_frame = QLineEdit('0')
self.mask_start_frame.setMaximumWidth(50)
self.mask_start_frame_lbl = QLabel('Mask start frame:', self)
layout.addWidget(self.mask_start_frame_lbl, row_index,5)
layout.addWidget(self.mask_start_frame, row_index,6)
self.mask_end_frame = QLineEdit('6')
self.mask_end_frame.setMaximumWidth(50)
self.mask_end_frame_lbl = QLabel('Mask end frame:', self)
layout.addWidget(self.mask_end_frame_lbl, row_index,7)
layout.addWidget(self.mask_end_frame, row_index,8)
self.sigma_smooth = QLineEdit('1')
self.sigma_smooth.setMaximumWidth(50)
self.sigma_smooth_lbl = QLabel('Smooth pixels:', self)
layout.addWidget(self.sigma_smooth_lbl, row_index,9)
layout.addWidget(self.sigma_smooth, row_index,10)
row_index+=1
#**************************************************************************************
#*********************************** VIDEO TOOLS **************************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.vid_analysis_lbl = QLabel('VIDEO ANALYSIS', self)
self.vid_analysis_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.vid_analysis_lbl.setStyleSheet('color: blue')
layout.addWidget(self.vid_analysis_lbl, row_index, 0); row_index+=1
#Convert videos;
self.button4 = QPushButton('Convert: .m4v => .npy')
self.button4.setMaximumWidth(200)
self.button4.clicked.connect(self.conv_video)
layout.addWidget(self.button4, row_index, 0)
#self.comboBox_select_video = QtGui.QComboBox(self)
#layout.addWidget(self.comboBox_select_video, row_index,1)
#self.comboBox_select_video.activated[str].connect(self.select); self.choice2 = ""
self.button41 = QPushButton('Find start/end of vid')
self.button41.setMaximumWidth(200)
self.button41.clicked.connect(self.fnd_start_end)
layout.addWidget(self.button41, row_index, 1)
self.button42 = QPushButton('Plot blue_light ROI')
self.button42.setMaximumWidth(200)
self.button42.clicked.connect(self.bl_light_roi)
layout.addWidget(self.button42, row_index, 2)
self.blue_light_std = QLineEdit('1.0')
self.blue_light_std.setMaximumWidth(50)
self.blue_light_std_lbl = QLabel('std of blue light):', self)
layout.addWidget(self.blue_light_std_lbl, row_index, 3)
layout.addWidget(self.blue_light_std, row_index, 4); row_index+=1
self.button431 = QPushButton('Movies: Single-Trial + [Ca]')
self.button431.setMaximumWidth(200)
self.button431.clicked.connect(self.evt_movies_ca)
layout.addWidget(self.button431, row_index, 0)
self.button43 = QPushButton('Movies: Multi-Trial')
self.button43.setMaximumWidth(200)
self.button43.clicked.connect(self.evt_movies)
layout.addWidget(self.button43, row_index, 1)
self.n_trials_movies = QLineEdit('12')
self.n_trials_movies.setMaximumWidth(50)
self.n_trials_movies_lbl = QLabel('# of trials:', self)
layout.addWidget(self.n_trials_movies_lbl, row_index, 2)
layout.addWidget(self.n_trials_movies, row_index, 3); row_index+=1
for k in range(2):
layout.addWidget(QLabel(' '*40, self), row_index,0)
row_index+=1
##**************************************************************************************
##***************************** COMBINED [Ca] & VIDEO **********************************
##**************************************************************************************
#self.preprocess_lbl = QLabel('COMBINED [Ca] & VIDEO', self)
#self.preprocess_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
#self.preprocess_lbl.setStyleSheet('color: blue')
#layout.addWidget(self.preprocess_lbl, row_index, 0); row_index+=1
#self.button_ca_stm = QPushButton('Static [Ca] + STM')
#self.button_ca_stm.setMaximumWidth(200)
#self.button_ca_stm.clicked.connect(self.static_stm_ca_mouse_lever)
#layout.addWidget(self.button_ca_stm, row_index, 0)
#self.button_ca_stm_video = QPushButton('Video [Ca] + STM')
#self.button_ca_stm_video.setMaximumWidth(200)
#self.button_ca_stm_video.clicked.connect(self.video_stm_ca_mouse_lever)
#layout.addWidget(self.button_ca_stm_video, row_index, 1)
#row_index+=1
#**************************************************************************************
#********************************** STROKE TOOLS **************************************
#**************************************************************************************
for k in range(6): layout.addWidget(QLabel(' '*40, self), row_index,k)
row_index+=1
self.post_processing_lbl = QLabel('STROKE TOOLS', self)
self.post_processing_lbl.setFont(QtGui.QFont("Times", 12, QtGui.QFont.Bold) )
self.post_processing_lbl.setStyleSheet('color: blue')
layout.addWidget(self.post_processing_lbl, row_index, 0); row_index+=1
#Load mouse from disk
self.button5 = QPushButton('Load Mouse')
self.button5.setMaximumWidth(200)
self.button5.clicked.connect(self.load_m_lever)
layout.addWidget(self.button5, row_index, 0); row_index+=1
#Separate sessions into epoch periods
epoch_days_lbl = QLabel('Epoch days: ', self)
layout.addWidget(epoch_days_lbl, row_index, 0)
#self.button6 = QPushButton('Set Epochs (days)')
#self.button6.setMaximumWidth(200)
#self.button6.clicked.connect(self.load_m_lever)
#layout.addWidget(self.button6, row_index, 0)
pre_stroke_days = 21; post_stroke_days = 14; post_post_stroke_days = 42
parent.pre_stroke_days = QLineEdit('21');
parent.pre_stroke_days.setMaximumWidth(50)
pre_stroke_days_lbl = QLabel('# days pre_stroke:', self)
layout.addWidget(pre_stroke_days_lbl, row_index,1)
layout.addWidget(parent.pre_stroke_days, row_index,2)
parent.post_stroke_days = QLineEdit('14');
parent.post_stroke_days.setMaximumWidth(50)
post_stroke_days_lbl = QLabel('# days post_stroke:', self)
layout.addWidget(post_stroke_days_lbl, row_index,3)
layout.addWidget(parent.post_stroke_days, row_index,4)
parent.post_post_stroke_days = QLineEdit('42');
parent.post_post_stroke_days.setMaximumWidth(50)
post_post_stroke_days_lbl = QLabel('# days pp_stroke:', self)
layout.addWidget(post_post_stroke_days_lbl, row_index,5)
layout.addWidget(parent.post_post_stroke_days, row_index,6) ; row_index+=1
#Dim reduction: options
self.button7 = QPushButton('Dimension Reduction:')
self.button7.setMaximumWidth(200)
self.button7.clicked.connect(self.dim_red_mouse_lever)
layout.addWidget(self.button7, row_index, 0)
self.comboBox3 = QtGui.QComboBox(self)
self.comboBox3.addItem("PCA")
self.comboBox3.addItem("MDS")
self.comboBox3.addItem("tSNE")
self.comboBox3.addItem("tSNE Barnes-Hutt")
layout.addWidget(self.comboBox3, row_index,1); row_index+=1
self.comboBox3.activated[str].connect(self.style_choice3); self.choice3="PCA"
#KMeans: options
self.button8 = QPushButton('Kmeans:')
self.button8.setMaximumWidth(200)
self.button8.clicked.connect(self.kmeans_mouse_lever)
layout.addWidget(self.button8, row_index, 0)
parent.kmeans_clusters = QLineEdit('16');
parent.kmeans_clusters.setMaximumWidth(50)
kmeans_clusters_lbl = QLabel('# of clusters:', self)
layout.addWidget(kmeans_clusters_lbl, row_index,1)
layout.addWidget(parent.kmeans_clusters, row_index,2)
#View clusters in dim reduction space
self.button9 = QPushButton('View Clusters - 3D')
self.button9.setMaximumWidth(200)
self.button9.clicked.connect(self.clusters_plot_mouse_lever)
layout.addWidget(self.button9, row_index, 3); row_index+=1
#Select a cluster from 2D trace groupings
self.button10 = QPushButton('Select Cluster - 2D')
self.button10.setMaximumWidth(200)
self.button10.clicked.connect(self.select_cluster_mouse_lever)
layout.addWidget(self.button10, row_index, 0)
#Plot Cluster Motiff
self.button11 = QPushButton('Plot Cluster Motiff')
self.button11.setMaximumWidth(200)
self.button11.clicked.connect(self.plot_motiff_mouse_lever)
layout.addWidget(self.button11, row_index, 1); row_index+=1
#Movies - single trial
self.button12 = QPushButton('Movies - Single Trial')
self.button12.setMaximumWidth(200)
self.button12.clicked.connect(self.movies_single_mouse_lever)
layout.addWidget(self.button12, row_index, 0); row_index+=1
#1D plots
self.button13 = QPushButton('1D - Plots')
self.button13.setMaximumWidth(200)
self.button13.clicked.connect(self.plot_1D_mouse_lever)
layout.addWidget(self.button13, row_index, 0)
#Pixel plots
self.button14 = QPushButton('Pixel - Plots')
self.button14.setMaximumWidth(200)
self.button14.clicked.connect(self.plot_pixel_mouse_lever)
layout.addWidget(self.button14, row_index, 1)
#Make Movies
self.button15 = QPushButton('Make Movies')
self.button15.setMaximumWidth(200)
self.button15.clicked.connect(self.make_movies_mouse_lever)
layout.addWidget(self.button15, row_index, 2) ; row_index+=1
self.setLayout(layout)
#*****************************************************************************************************
#************************************* SELECT SESSIONS FUNCTIONS *************************************
#*****************************************************************************************************
#SELECT ANIMAL
def select_animal(self, text):
print "...animal: ", text
self.selected_animal=text
self.parent.animal_name_text = text
#Reload animal object
self.parent.animal = Mouse_lever(self.parent.animal_name_text, self.parent.root_dir, self.parent.n_sec)
self.parent.setWindowTitle(self.parent.animal.name)
#Reload session list and reset session box
self.comboBox_select_session.clear()
file_names = sorted(glob.glob(self.parent.root_dir+self.parent.animal.name+"/tif_files/*"))
for file_name in sorted(file_names):
self.comboBox_select_session.addItem(file_name.replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",''))
self.selected_session = file_names[0].replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",'')
self.select_session(self.selected_session)
#Reset code functions
self.comboBox_select_code.setCurrentIndex(0)
self.locs_44threshold = []; self.code_44threshold = []
temp_file = self.selected_session+'/'+self.selected_session.replace(self.parent.animal.home_dir+self.parent.animal.name+'/tif_files/','')
if os.path.exists(temp_file + '_locs44threshold.npy')==True:
self.locs_44threshold = np.load(temp_file+'_locs44threshold.npy')
self.code_44threshold = np.load(temp_file+'_code44threshold.npy')
self.select_reward_code('02') #Reset reward code to '02' for new animal load
print self.selected_animal
print self.selected_session
print self.selected_code
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
#Find movie availabliltiy
if os.path.exists(self.parent.animal.home_dir+self.parent.animal.name+"/video_files/"+self.selected_session+'.m4v')==True:
self.movie_available_lbl.setText("Movie exists")
else:
self.movie_available_lbl.setText("No movie")
#SELECT SESSION
def select_session(self, text):
print "...session: ", text
self.selected_session=text
self.parent.animal.recName = text; self.parent.rec_name_text= text
print "... self.selected_animal: ", self.selected_animal
print "... self.selected_session: ", self.selected_session
#CALL CODE COUNTING FUNCTIONS
self.locs_44threshold = []; self.code_44threshold = []
self.tif_file = self.parent.root_dir+self.parent.animal.name+"/tif_files/" +self.selected_session+'/'+self.selected_session+'.tif'
if os.path.exists(self.tif_file[:-4] + '_locs44threshold.npy')==True:
self.locs_44threshold = np.load(self.tif_file[:-4]+'_locs44threshold.npy')
self.code_44threshold = np.load(self.tif_file[:-4]+'_code44threshold.npy')
print "... code_44threshold: ", self.code_44threshold
#Update code list values
self.code_list = ['02', '04', '07']
self.code_list.extend(self.find_annotated_clusters())
print "...updated code_list: ", self.code_list
self.comboBox_select_code.clear()
for code_ in self.code_list:
self.comboBox_select_code.addItem(code_)
self.comboBox_select_code.setCurrentIndex(0)
self.selected_code = '02'
self.n_codes = np.count_nonzero(self.code_44threshold == self.selected_code)
self.n_codes_lbl.setText(str(self.n_codes))
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
#Find movie availability
if os.path.exists(self.parent.animal.home_dir+self.parent.animal.name+"/video_files/"+self.selected_session+'.m4v')==True:
self.movie_available_lbl.setText("Movie exists")
else:
self.movie_available_lbl.setText("No movie")
#SELECT REWARD CODE
def select_reward_code(self, text):
print "...code selected: ", text
self.selected_code = text
#Load Standard Reward Codes
if (self.selected_code=='02') or (self.selected_code=='04') or (self.selected_code=='07'):
self.locs_44threshold = []; self.code_44threshold = []
temp_file = self.parent.root_dir + self.parent.animal.name + "/tif_files/"+ self.selected_session+'/'+self.selected_session
print "...temp_file: ", temp_file
if os.path.exists(temp_file + '_locs44threshold.npy')==True:
self.locs_44threshold = np.load(temp_file+'_locs44threshold.npy')
self.code_44threshold = np.load(temp_file+'_code44threshold.npy')
print self.code_44threshold
self.n_codes = np.count_nonzero(self.code_44threshold == self.selected_code)
self.n_codes_lbl.setText(str(self.n_codes))
#Load Times for specific behaviours using video annotation
else:
load_behavioural_annotation_data(self)
self.n_codes = len(self.code_44threshold_selected)
self.n_codes_lbl.setText(str(self.n_codes))
print "..reseting reward code, # codes: ", self.n_codes
print "\n\n"
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
#Initialize Trial - ONLY USED ONCE
def initialize_trial(self, text):
print "...selecting trial: ", text
self.selected_trial = text
def view_trial_locations(self):
print "... displaying trial locations..."
show_trial_locations(self)
def find_isolated_behaviours(self):
print "... finding isolated behaviours..."
find_isolated(self)
def make_annotated_movies(self):
print "... making annotated movies..."
annotate_movies(self)
#*****************************************************************************************************
#************************************* PREPROCESS ALL DATA ******************************************
#*****************************************************************************************************
def preprocess_mlever(self):
#PREPROCESS ALL DATA: Load filenames, sessions, etc.
self.parent.animal.preprocess_mouse_lever()
def filter_mlever(self):
#FILTER ALL DATA
file_names = sorted(glob.glob(self.parent.root_dir+self.parent.animal.name+"/tif_files/*"))
for file_name in sorted(file_names):
#print file_name.replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",'')
self.selected_session = file_name.replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",'')
self.select_session(self.selected_session)
filter_data(self)
def algn_images(self):
#ALIGN ALL IMAGES
file_names = sorted(glob.glob(self.parent.root_dir+self.parent.animal.name+"/tif_files/*"))
for file_name in sorted(file_names):
print file_name.replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",'')
self.selected_session = file_name.replace(self.parent.root_dir+self.parent.animal.name+"/tif_files/",'')
self.select_session(self.selected_session)
self.animal.sessfilter_data(self)
self.align_images() #Align raw_images to first session frame 1000
#load specific session .npy images and align to 1000 frame of 1st session
print "... alligning session ... NOT CURRENTLY IMPLEMENTED..."
def load_m_lever(self):
self.parent.animal.load()
#*****************************************************************************************************
#************************************* PROCESS INDIVIDUAL SESSION ************************************
#*****************************************************************************************************
def dff_mouse_lever(self):
compute_dff_mouse_lever(self)
#self.parent.animal.process_sessions(self)
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
def cvrt_tif_npy(self):
print "...convert .tif to .npy..."
#Check to see if .npy or _aligned.npy file exists
if (os.path.exists(self.tif_file[:-4] +'.npy')==False) and (os.path.exists(self.tif_file[:-4] +'_aligned.npy')==False):
print "...read: ", self.tif_file
images_raw = tiff.imread(self.tif_file)
print "... saving .npy"
np.save(self.tif_file[:-4], images_raw)
else:
print "... .npy file exists ..."
def fltr_mouse_lever(self):
filter_data(self)
def movie_available(self, text):
self.comboBox_movie_available = QtGui.QComboBox(self)
if os.path.exists(self.parent.animal.home_dir+self.parent.animal.name+"/video_files/"+self.selected_session+'.m4v')==True:
self.comboBox_movie_available.addItem("Movie exists")
else:
self.comboBox_movie_available.addItem("No movie")
layout.addWidget(self.comboBox_movie_available, row_index,5)
self.comboBox_select_session.activated[str].connect(self.movie_available)
def load_trials(self):
if self.selected_dff_filter == 'nofilter':
self.traces_filename = self.parent.animal.home_dir+self.parent.animal.name+'/tif_files/'+self.selected_session+'/'+self.selected_session+"_"+ \
str(self.parent.n_sec)+"sec_"+ self.selected_dff_filter+'_' +self.dff_method+'_'+str(self.selected_code)+"code_traces.npy"
else:
self.traces_filename = self.parent.animal.home_dir+self.parent.animal.name+'/tif_files/'+self.selected_session+'/'+self.selected_session+"_"+ \
str(self.parent.n_sec)+"sec_" + self.selected_dff_filter + "_"+self.dff_method+'_'+self.parent.filter_low.text()+"hz_"+self.parent.filter_high.text()+"hz_"+str(self.selected_code)+"code_traces.npy"
filename = self.traces_filename.replace('_traces.npy','')+'_stm.npy'
#Load trial file if data has been computed.
if os.path.exists(filename)==True:
data = np.load(filename, mmap_mode='r+')
print data.shape
return data.shape[0]
return 0
def select_dff_filter(self,text):
self.selected_dff_filter=text
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
def select_filter(self, text):
self.selected_filter = text
def select_dff_method(self, text):
self.dff_method = text
#Reset trial value
n_trials_in = self.load_trials()
self.comboBox_select_trial.clear()
for k in range(n_trials_in):
self.comboBox_select_trial.addItem(str(k))
self.selected_trial = '0' #crappy method; redundant
def find_annotated_clusters(self):
''' Find all annotation fiels called "*_clusters.npz" and add their annotations '''
filenames = glob.glob(self.parent.root_dir + self.parent.animal.name + '/tif_files/'+self.selected_session+'/'+self.selected_session+"*_clusters.npz")
self.annotated_clusters = []
for k in range(len(filenames)):
print filenames[k]
data = np.load(filenames[k])
for cluster in data['cluster_names']:
if "no_" in cluster: pass #Ignore the non-behaviour labels containing string "no_" in them.
else: self.annotated_clusters.append(cluster)
return self.annotated_clusters
#*************************************************************************************************************************************************************************
#*************************************************************************************************************************************************************************
#*************************************************************************************************************************************************************************
#*************************************************************************************************************************************************************************
#*************************************************************************************************************************************************************************
#*************************************************************************************************************************************************************************
def static_stm_mouse_lever(self):
view_static_stm(self)
def static_stm_all_lever(self):
make_static_stm_all(self)
def video_stm_mouse_lever(self):
view_video_stm(self)
def video_stm_all(self):
view_video_stm_all(self)
def style_choice2(self, text):
self.choice2 = text
def style_choice3(self, text):
self.choice3 = text
#*************************************************************************************************
#*********************************** VIDEO PROCESSING TOOLS **************************************
#*************************************************************************************************
def conv_video(self):
convert_video(self)
def fnd_start_end(self):
find_start_end(self)
def bl_light_roi(self):
plot_blue_light_roi(self)
def evt_movies(self):
event_triggered_movies_multitrial(self)
def evt_movies_ca(self):
event_triggered_movies_single_Ca(self)
#*************************************************************************************************
#****************************************** STROKE TOOLS *****************************************
#*************************************************************************************************
def kmeans_mouse_lever(self):
print "...kmeans..."
def clusters_plot_mouse_lever(self):
print "... visualizing clustered distributions in 3D post dim-reduction..."
plot_pyqt(app, dim_red_data, mouse.cluster_labels)
def select_cluster_mouse_lever(self):
print "... selecting cluster post dim-reduction..."
plot_traces_pyqt(app, mouse)
def plot_motiff_mouse_lever(self):
print "... plotting mouse lever motiff ..."
plot_selected_cluster_DFF(mouse)
def plot_1D_mouse_lever(self):
print "... plotting 1D ..."
plot_1D(mouse, generic_mask_indexes)
def plot_pixel_mouse_lever(self):
print "... plotting 1D ..."
pixel_plot(mouse, generic_mask_indexes)
def make_movies_mouse_lever(self):
print "... make movies ..."
make_movies(mouse, stacks, v_max, v_min)
def movies_single_mouse_lever(self):
print "... make movies signle trial ..."
make_movies_singletrials(mouse, data_chunks)
def dim_red_mouse_lever(self):
print "... dim reduction..."
dim_reduction (self.parent.animal, text)
def chunk_mouse_lever(self):
#Call chunking algorithm
self.parent.animal.chunk_data(pre_stroke_days, post_stroke_days, post_post_stroke_days)